Skip to content

Commit

Permalink
Merge pull request #283 from mojyack/master
Browse files Browse the repository at this point in the history
Add more specific error codes to juice_send
  • Loading branch information
paullouisageneau authored Jan 9, 2025
2 parents 1d915b7 + f709266 commit 60bcb33
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
2 changes: 2 additions & 0 deletions include/juice/juice.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ extern "C" {
#define JUICE_ERR_FAILED -2 // runtime error
#define JUICE_ERR_NOT_AVAIL -3 // element not available
#define JUICE_ERR_IGNORED -4 // ignored
#define JUICE_ERR_AGAIN -5 // buffer full
#define JUICE_ERR_TOO_LARGE -6 // datagram too large

// ICE Agent

Expand Down
2 changes: 1 addition & 1 deletion src/agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ int agent_send_stun_binding(juice_agent_t *agent, agent_stun_entry_t *entry, stu
// Direct send
int ret = agent_direct_send(agent, &entry->record, buffer, size, 0);
if (ret < 0) {
if (ret == SENETUNREACH)
if (ret == -SENETUNREACH)
JLOG_INFO("STUN binding failed: Network unreachable");
else
JLOG_WARN("STUN message send failed");
Expand Down
1 change: 1 addition & 0 deletions src/conn_mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ int conn_mux_send(juice_agent_t *agent, const addr_record_t *dst, const char *da

int ret = udp_sendto(registry_impl->sock, data, size, dst);
if (ret < 0) {
ret = -sockerrno;
if (sockerrno == SEAGAIN || sockerrno == SEWOULDBLOCK)
JLOG_INFO("Send failed, buffer is full");
else if (sockerrno == SEMSGSIZE)
Expand Down
1 change: 1 addition & 0 deletions src/conn_poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ int conn_poll_send(juice_agent_t *agent, const addr_record_t *dst, const char *d

int ret = udp_sendto(conn_impl->sock, data, size, dst);
if (ret < 0) {
ret = -sockerrno;
if (sockerrno == SEAGAIN || sockerrno == SEWOULDBLOCK)
JLOG_INFO("Send failed, buffer is full");
else if (sockerrno == SEMSGSIZE)
Expand Down
1 change: 1 addition & 0 deletions src/conn_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ int conn_thread_send(juice_agent_t *agent, const addr_record_t *dst, const char

int ret = udp_sendto(conn_impl->sock, data, size, dst);
if (ret < 0) {
ret = -sockerrno;
if (sockerrno == SEAGAIN || sockerrno == SEWOULDBLOCK)
JLOG_INFO("Send failed, buffer is full");
else if (sockerrno == SEMSGSIZE)
Expand Down
20 changes: 9 additions & 11 deletions src/juice.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,21 @@ JUICE_EXPORT int juice_set_remote_gathering_done(juice_agent_t *agent) {
}

JUICE_EXPORT int juice_send(juice_agent_t *agent, const char *data, size_t size) {
if (!agent || (!data && size))
return JUICE_ERR_INVALID;

if (agent_send(agent, data, size, 0) < 0)
return JUICE_ERR_FAILED;

return JUICE_ERR_SUCCESS;
return juice_send_diffserv(agent, data, size, 0);
}

JUICE_EXPORT int juice_send_diffserv(juice_agent_t *agent, const char *data, size_t size, int ds) {
if (!agent || (!data && size))
return JUICE_ERR_INVALID;

if (agent_send(agent, data, size, ds) < 0)
return JUICE_ERR_FAILED;

return JUICE_ERR_SUCCESS;
int ret = agent_send(agent, data, size, ds);
if(ret >= 0)
return JUICE_ERR_SUCCESS;
if(ret == -SEAGAIN || ret == -SEWOULDBLOCK)
return JUICE_ERR_AGAIN;
if(ret == -SEMSGSIZE)
return JUICE_ERR_TOO_LARGE;
return JUICE_ERR_FAILED;
}

JUICE_EXPORT juice_state_t juice_get_state(juice_agent_t *agent) { return agent_get_state(agent); }
Expand Down

0 comments on commit 60bcb33

Please sign in to comment.