From 5bc730ef88971c98e00ee6b0ea56e068b944c815 Mon Sep 17 00:00:00 2001 From: Richard Aas Date: Fri, 11 Nov 2011 09:26:16 +0000 Subject: [PATCH] udp: added udp_send_helper() --- include/re_udp.h | 2 ++ src/udp/udp.c | 60 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/include/re_udp.h b/include/re_udp.h index 2dbf52d..cc3d895 100644 --- a/include/re_udp.h +++ b/include/re_udp.h @@ -49,6 +49,8 @@ int udp_register_helper(struct udp_helper **uhp, struct udp_sock *us, int layer, udp_helper_send_h *sh, udp_helper_recv_h *rh, void *arg); +int udp_send_helper(struct udp_sock *us, const struct sa *dst, + struct mbuf *mb, struct udp_helper *uh); #ifdef __SYMBIAN32__ diff --git a/src/udp/udp.c b/src/udp/udp.c index a030960..13479ee 100644 --- a/src/udp/udp.c +++ b/src/udp/udp.c @@ -220,8 +220,6 @@ static void udp_read(struct udp_sock *us, int fd) goto out; } - DEBUG_INFO("udp recv %u bytes from %j:%u\n", mb->end, - &src, sa_port(&src)); us->rh(&src, mb, us->arg); out: @@ -416,24 +414,12 @@ void udp_connect(struct udp_sock *us, bool conn) } -/** - * Send a UDP Datagram to a peer - * - * @param us UDP Socket - * @param dst Destination network address - * @param mb Buffer to send - * - * @return 0 if success, otherwise errorcode - */ -int udp_send(struct udp_sock *us, const struct sa *dst, struct mbuf *mb) +static int udp_send_internal(struct udp_sock *us, const struct sa *dst, + struct mbuf *mb, struct le *le) { struct sa hdst; - struct le *le; int err = 0, fd; - if (!us || !dst || !mb) - return EINVAL; - /* check for error in e.g. connected state */ if (us->err) { err = us->err; @@ -448,7 +434,6 @@ int udp_send(struct udp_sock *us, const struct sa *dst, struct mbuf *mb) fd = us->fd; /* call helpers in reverse order */ - le = us->helpers.tail; while (le) { struct udp_helper *uh = le->data; @@ -484,6 +469,24 @@ int udp_send(struct udp_sock *us, const struct sa *dst, struct mbuf *mb) } +/** + * Send a UDP Datagram to a peer + * + * @param us UDP Socket + * @param dst Destination network address + * @param mb Buffer to send + * + * @return 0 if success, otherwise errorcode + */ +int udp_send(struct udp_sock *us, const struct sa *dst, struct mbuf *mb) +{ + if (!us || !dst || !mb) + return EINVAL; + + return udp_send_internal(us, dst, mb, us->helpers.tail); +} + + /** * Send an anonymous UDP Datagram to a peer * @@ -504,7 +507,7 @@ int udp_send_anon(const struct sa *dst, struct mbuf *mb) if (err) return err; - err = udp_send(us, dst, mb); + err = udp_send_internal(us, dst, mb, NULL); mem_deref(us); return err; @@ -773,3 +776,24 @@ int udp_register_helper(struct udp_helper **uhp, struct udp_sock *us, return 0; } + + +/** + * Send a UDP Datagram to a remote peer bypassing this helper and + * the helpers above it. + * + * @param us UDP Socket + * @param dst Destination network address + * @param mb Buffer to send + * @param uh UDP Helper + * + * @return 0 if success, otherwise errorcode + */ +int udp_send_helper(struct udp_sock *us, const struct sa *dst, + struct mbuf *mb, struct udp_helper *uh) +{ + if (!us || !dst || !mb || !uh) + return EINVAL; + + return udp_send_internal(us, dst, mb, uh->le.prev); +}