Skip to content

Commit 60bcb33

Browse files
Merge pull request #283 from mojyack/master
Add more specific error codes to juice_send
2 parents 1d915b7 + f709266 commit 60bcb33

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

include/juice/juice.h

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ extern "C" {
4141
#define JUICE_ERR_FAILED -2 // runtime error
4242
#define JUICE_ERR_NOT_AVAIL -3 // element not available
4343
#define JUICE_ERR_IGNORED -4 // ignored
44+
#define JUICE_ERR_AGAIN -5 // buffer full
45+
#define JUICE_ERR_TOO_LARGE -6 // datagram too large
4446

4547
// ICE Agent
4648

src/agent.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,7 @@ int agent_send_stun_binding(juice_agent_t *agent, agent_stun_entry_t *entry, stu
16841684
// Direct send
16851685
int ret = agent_direct_send(agent, &entry->record, buffer, size, 0);
16861686
if (ret < 0) {
1687-
if (ret == SENETUNREACH)
1687+
if (ret == -SENETUNREACH)
16881688
JLOG_INFO("STUN binding failed: Network unreachable");
16891689
else
16901690
JLOG_WARN("STUN message send failed");

src/conn_mux.c

+1
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ int conn_mux_send(juice_agent_t *agent, const addr_record_t *dst, const char *da
522522

523523
int ret = udp_sendto(registry_impl->sock, data, size, dst);
524524
if (ret < 0) {
525+
ret = -sockerrno;
525526
if (sockerrno == SEAGAIN || sockerrno == SEWOULDBLOCK)
526527
JLOG_INFO("Send failed, buffer is full");
527528
else if (sockerrno == SEMSGSIZE)

src/conn_poll.c

+1
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ int conn_poll_send(juice_agent_t *agent, const addr_record_t *dst, const char *d
412412

413413
int ret = udp_sendto(conn_impl->sock, data, size, dst);
414414
if (ret < 0) {
415+
ret = -sockerrno;
415416
if (sockerrno == SEAGAIN || sockerrno == SEWOULDBLOCK)
416417
JLOG_INFO("Send failed, buffer is full");
417418
else if (sockerrno == SEMSGSIZE)

src/conn_thread.c

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ int conn_thread_send(juice_agent_t *agent, const addr_record_t *dst, const char
260260

261261
int ret = udp_sendto(conn_impl->sock, data, size, dst);
262262
if (ret < 0) {
263+
ret = -sockerrno;
263264
if (sockerrno == SEAGAIN || sockerrno == SEWOULDBLOCK)
264265
JLOG_INFO("Send failed, buffer is full");
265266
else if (sockerrno == SEMSGSIZE)

src/juice.c

+9-11
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,21 @@ JUICE_EXPORT int juice_set_remote_gathering_done(juice_agent_t *agent) {
8585
}
8686

8787
JUICE_EXPORT int juice_send(juice_agent_t *agent, const char *data, size_t size) {
88-
if (!agent || (!data && size))
89-
return JUICE_ERR_INVALID;
90-
91-
if (agent_send(agent, data, size, 0) < 0)
92-
return JUICE_ERR_FAILED;
93-
94-
return JUICE_ERR_SUCCESS;
88+
return juice_send_diffserv(agent, data, size, 0);
9589
}
9690

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

101-
if (agent_send(agent, data, size, ds) < 0)
102-
return JUICE_ERR_FAILED;
103-
104-
return JUICE_ERR_SUCCESS;
95+
int ret = agent_send(agent, data, size, ds);
96+
if(ret >= 0)
97+
return JUICE_ERR_SUCCESS;
98+
if(ret == -SEAGAIN || ret == -SEWOULDBLOCK)
99+
return JUICE_ERR_AGAIN;
100+
if(ret == -SEMSGSIZE)
101+
return JUICE_ERR_TOO_LARGE;
102+
return JUICE_ERR_FAILED;
105103
}
106104

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

0 commit comments

Comments
 (0)