tcp/udp: helper api cleanup
This commit is contained in:
parent
0c9176516b
commit
b8fb22fa71
11 changed files with 52 additions and 38 deletions
|
@ -3,8 +3,6 @@ TODO
|
|||
-------------------------------------------------------------------------------
|
||||
Version v0.2.0
|
||||
|
||||
tcp_register_helper: remove int *fd, add int layer
|
||||
udp_register_helper: remove int *fd
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Version v0.x.y
|
||||
|
|
|
@ -96,6 +96,7 @@ typedef bool (tcp_helper_recv_h)(int *err, struct mbuf *mb, bool *estab,
|
|||
struct tcp_helper;
|
||||
|
||||
|
||||
int tcp_register_helper(struct tcp_helper **thp, struct tcp_conn *tc, int *fd,
|
||||
int tcp_register_helper(struct tcp_helper **thp, struct tcp_conn *tc,
|
||||
int layer,
|
||||
tcp_helper_estab_h *eh, tcp_helper_send_h *sh,
|
||||
tcp_helper_recv_h *rh, void *arg);
|
||||
|
|
|
@ -46,7 +46,7 @@ struct udp_helper;
|
|||
|
||||
|
||||
int udp_register_helper(struct udp_helper **uhp, struct udp_sock *us,
|
||||
int *fd, int layer,
|
||||
int layer,
|
||||
udp_helper_send_h *sh, udp_helper_recv_h *rh,
|
||||
void *arg);
|
||||
|
||||
|
|
|
@ -156,7 +156,7 @@ int icem_comp_alloc(struct icem_comp **cp, struct icem *icem, int id,
|
|||
comp->sock = mem_ref(sock);
|
||||
comp->icem = icem;
|
||||
|
||||
err = udp_register_helper(&comp->uh, sock, NULL, icem->layer,
|
||||
err = udp_register_helper(&comp->uh, sock, icem->layer,
|
||||
NULL, /*helper_send_handler*/
|
||||
helper_recv_handler, comp);
|
||||
if (err)
|
||||
|
|
|
@ -201,7 +201,7 @@ int stun_keepalive_alloc(struct stun_keepalive **skap,
|
|||
switch (proto) {
|
||||
|
||||
case IPPROTO_UDP:
|
||||
err = udp_register_helper(&ska->uh, sock, NULL, layer,
|
||||
err = udp_register_helper(&ska->uh, sock, layer,
|
||||
NULL, udp_recv_handler, ska);
|
||||
break;
|
||||
|
||||
|
|
|
@ -117,6 +117,7 @@ public:
|
|||
|
||||
struct tcp_helper {
|
||||
struct le le;
|
||||
int layer;
|
||||
tcp_helper_estab_h *estabh;
|
||||
tcp_helper_send_h *sendh;
|
||||
tcp_helper_recv_h *recvh;
|
||||
|
@ -965,13 +966,24 @@ static bool helper_recv_handler(int *err, struct mbuf *mb, bool *estab,
|
|||
}
|
||||
|
||||
|
||||
int tcp_register_helper(struct tcp_helper **thp, struct tcp_conn *tc, int *fd,
|
||||
static bool sort_handler(struct le *le1, struct le *le2, void *arg)
|
||||
{
|
||||
struct tcp_helper *th1 = (struct tcp_helper *)le1->data;
|
||||
struct tcp_helper *th2 = (struct tcp_helper *)le2->data;
|
||||
(void)arg;
|
||||
|
||||
return th1->layer <= th2->layer;
|
||||
}
|
||||
|
||||
|
||||
int tcp_register_helper(struct tcp_helper **thp, struct tcp_conn *tc,
|
||||
int layer,
|
||||
tcp_helper_estab_h *eh, tcp_helper_send_h *sh,
|
||||
tcp_helper_recv_h *rh, void *arg)
|
||||
{
|
||||
struct tcp_helper *th;
|
||||
|
||||
if (!thp || !tc)
|
||||
if (!tc)
|
||||
return EINVAL;
|
||||
|
||||
th = (struct tcp_helper *)mem_zalloc(sizeof(*th), helper_destructor);
|
||||
|
@ -980,18 +992,16 @@ int tcp_register_helper(struct tcp_helper **thp, struct tcp_conn *tc, int *fd,
|
|||
|
||||
list_append(&tc->helpers, &th->le, th);
|
||||
|
||||
th->layer = layer;
|
||||
th->estabh = eh ? eh : helper_estab_handler;
|
||||
th->sendh = sh ? sh : helper_send_handler;
|
||||
th->recvh = rh ? rh : helper_recv_handler;
|
||||
th->arg = arg;
|
||||
|
||||
#if 0
|
||||
if (fd)
|
||||
*fd = tc->fdc;
|
||||
#endif
|
||||
(void)fd;
|
||||
list_sort(&tc->helpers, sort_handler, NULL);
|
||||
|
||||
*thp = th;
|
||||
if (thp)
|
||||
*thp = th;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -84,6 +84,7 @@ struct tcp_conn {
|
|||
|
||||
struct tcp_helper {
|
||||
struct le le;
|
||||
int layer;
|
||||
tcp_helper_estab_h *estabh;
|
||||
tcp_helper_send_h *sendh;
|
||||
tcp_helper_recv_h *recvh;
|
||||
|
@ -1191,13 +1192,23 @@ int tcp_conn_fd(const struct tcp_conn *tc)
|
|||
}
|
||||
|
||||
|
||||
int tcp_register_helper(struct tcp_helper **thp, struct tcp_conn *tc, int *fd,
|
||||
static bool sort_handler(struct le *le1, struct le *le2, void *arg)
|
||||
{
|
||||
struct tcp_helper *th1 = le1->data, *th2 = le2->data;
|
||||
(void)arg;
|
||||
|
||||
return th1->layer <= th2->layer;
|
||||
}
|
||||
|
||||
|
||||
int tcp_register_helper(struct tcp_helper **thp, struct tcp_conn *tc,
|
||||
int layer,
|
||||
tcp_helper_estab_h *eh, tcp_helper_send_h *sh,
|
||||
tcp_helper_recv_h *rh, void *arg)
|
||||
{
|
||||
struct tcp_helper *th;
|
||||
|
||||
if (!thp || !tc)
|
||||
if (!tc)
|
||||
return EINVAL;
|
||||
|
||||
th = mem_zalloc(sizeof(*th), helper_destructor);
|
||||
|
@ -1206,15 +1217,16 @@ int tcp_register_helper(struct tcp_helper **thp, struct tcp_conn *tc, int *fd,
|
|||
|
||||
list_append(&tc->helpers, &th->le, th);
|
||||
|
||||
th->layer = layer;
|
||||
th->estabh = eh ? eh : helper_estab_handler;
|
||||
th->sendh = sh ? sh : helper_send_handler;
|
||||
th->recvh = rh ? rh : helper_recv_handler;
|
||||
th->arg = arg;
|
||||
|
||||
if (fd)
|
||||
*fd = tc->fdc;
|
||||
list_sort(&tc->helpers, sort_handler, NULL);
|
||||
|
||||
*thp = th;
|
||||
if (thp)
|
||||
*thp = th;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -209,8 +209,9 @@ static bool send_handler(int *err, struct mbuf *mb, void *arg)
|
|||
|
||||
int tls_start_tcp(struct tls_conn **ptc, struct tls *tls, struct tcp_conn *tcp)
|
||||
{
|
||||
int err, fd;
|
||||
struct tls_conn *tc;
|
||||
const int layer = 0;
|
||||
int err;
|
||||
|
||||
if (!ptc || !tls || !tcp)
|
||||
return EINVAL;
|
||||
|
@ -219,7 +220,7 @@ int tls_start_tcp(struct tls_conn **ptc, struct tls *tls, struct tcp_conn *tcp)
|
|||
if (!tc)
|
||||
return ENOMEM;
|
||||
|
||||
err = tcp_register_helper(&tc->th, tcp, &fd, estab_handler,
|
||||
err = tcp_register_helper(&tc->th, tcp, layer, estab_handler,
|
||||
send_handler, recv_handler, tc);
|
||||
if (err)
|
||||
goto out;
|
||||
|
@ -241,7 +242,7 @@ int tls_start_tcp(struct tls_conn **ptc, struct tls *tls, struct tcp_conn *tcp)
|
|||
goto out;
|
||||
}
|
||||
|
||||
tc->sbio_out = BIO_new_socket(fd, BIO_NOCLOSE);
|
||||
tc->sbio_out = BIO_new_socket(tcp_conn_fd(tcp), BIO_NOCLOSE);
|
||||
if (!tc->sbio_out) {
|
||||
DEBUG_WARNING("alloc: BIO_new_socket() failed\n");
|
||||
goto out;
|
||||
|
|
|
@ -416,7 +416,7 @@ int turnc_alloc(struct turnc **turncp, const struct stun_conf *conf, int proto,
|
|||
switch (proto) {
|
||||
|
||||
case IPPROTO_UDP:
|
||||
err = udp_register_helper(&turnc->uh, sock, NULL, layer,
|
||||
err = udp_register_helper(&turnc->uh, sock, layer,
|
||||
udp_send_handler, udp_recv_handler,
|
||||
turnc);
|
||||
break;
|
||||
|
|
|
@ -536,18 +536,19 @@ static bool sort_handler(struct le *le1, struct le *le2, void *arg)
|
|||
struct udp_helper *uh1 = (struct udp_helper *)le1->data;
|
||||
struct udp_helper *uh2 = (struct udp_helper *)le2->data;
|
||||
(void)arg;
|
||||
|
||||
return uh1->layer <= uh2->layer;
|
||||
}
|
||||
|
||||
|
||||
int udp_register_helper(struct udp_helper **uhp, struct udp_sock *us,
|
||||
int *fd, int layer,
|
||||
int layer,
|
||||
udp_helper_send_h *sh, udp_helper_recv_h *rh,
|
||||
void *arg)
|
||||
{
|
||||
struct udp_helper *uh;
|
||||
|
||||
if (!uhp || !us)
|
||||
if (!us)
|
||||
return EINVAL;
|
||||
|
||||
uh = (struct udp_helper *)mem_zalloc(sizeof(*uh), helper_destructor);
|
||||
|
@ -563,14 +564,8 @@ int udp_register_helper(struct udp_helper **uhp, struct udp_sock *us,
|
|||
|
||||
list_sort(&us->helpers, sort_handler, NULL);
|
||||
|
||||
#if 0
|
||||
/* Symbian has no `fd' */
|
||||
if (fd)
|
||||
*fd = us->fd;
|
||||
#endif
|
||||
(void)fd;
|
||||
|
||||
*uhp = uh;
|
||||
if (uhp)
|
||||
*uhp = uh;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -720,6 +720,7 @@ static bool sort_handler(struct le *le1, struct le *le2, void *arg)
|
|||
{
|
||||
struct udp_helper *uh1 = le1->data, *uh2 = le2->data;
|
||||
(void)arg;
|
||||
|
||||
return uh1->layer <= uh2->layer;
|
||||
}
|
||||
|
||||
|
@ -729,7 +730,6 @@ static bool sort_handler(struct le *le1, struct le *le2, void *arg)
|
|||
*
|
||||
* @param uhp Pointer to allocated UDP helper object
|
||||
* @param us UDP socket
|
||||
* @param fd Returned file-descriptor (optional)
|
||||
* @param layer Layer number; higher number means higher up in stack
|
||||
* @param sh Send handler
|
||||
* @param rh Receive handler
|
||||
|
@ -738,7 +738,7 @@ static bool sort_handler(struct le *le1, struct le *le2, void *arg)
|
|||
* @return 0 if success, otherwise errorcode
|
||||
*/
|
||||
int udp_register_helper(struct udp_helper **uhp, struct udp_sock *us,
|
||||
int *fd, int layer,
|
||||
int layer,
|
||||
udp_helper_send_h *sh, udp_helper_recv_h *rh,
|
||||
void *arg)
|
||||
{
|
||||
|
@ -760,9 +760,6 @@ int udp_register_helper(struct udp_helper **uhp, struct udp_sock *us,
|
|||
|
||||
list_sort(&us->helpers, sort_handler, NULL);
|
||||
|
||||
if (fd)
|
||||
*fd = us->fd;
|
||||
|
||||
if (uhp)
|
||||
*uhp = uh;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue