udp: added udp_send_helper()

This commit is contained in:
Richard Aas 2011-11-11 09:26:16 +00:00
parent d46a33cdf2
commit 5bc730ef88
2 changed files with 44 additions and 18 deletions

View file

@ -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__

View file

@ -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);
}