Skip to content

Commit f709266

Browse files
committed
Introduce JUICE_ERR_{AGAIN,TOO_LARGE}
Add new error codes JUICE_ERR_AGAIN and JUICE_ERR_TOO_LARGE, which can represent more detailed result of juice_send. Then update juice_send(_diffserv) to return them.
1 parent ce730a1 commit f709266

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

include/juice/juice.h

Lines changed: 2 additions & 0 deletions
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/juice.c

Lines changed: 9 additions & 11 deletions
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)