diff --git a/daemon/control_ng.c b/daemon/control_ng.c index 70f6392c7..e148dcffb 100644 --- a/daemon/control_ng.c +++ b/daemon/control_ng.c @@ -81,8 +81,8 @@ static void control_ng_incoming(struct obj *obj, str *buf, const endpoint_t *sin bencode_item_t *dict, *resp; str cmd, cookie, data, reply, *to_send, callid; const char *errstr; - struct msghdr mh; struct iovec iov[3]; + unsigned int iovlen; GString *log_str; struct control_ng_stats* cur = get_control_ng_stats(c,&sin->address); @@ -196,9 +196,7 @@ send_resp: } send_only: - ZERO(mh); - mh.msg_iov = iov; - mh.msg_iovlen = 3; + iovlen = 3; iov[0].iov_base = cookie.s; iov[0].iov_len = cookie.len; @@ -207,7 +205,7 @@ send_only: iov[2].iov_base = to_send->s; iov[2].iov_len = to_send->len; - socket_sendmsg(&c->udp_listener.sock, &mh, sin); + socket_sendiov(&c->udp_listener.sock, iov, iovlen, sin); if (resp) cookie_cache_insert(&c->cookie_cache, &cookie, &reply); diff --git a/daemon/control_udp.c b/daemon/control_udp.c index ae9996e77..d614aee6a 100644 --- a/daemon/control_udp.c +++ b/daemon/control_udp.c @@ -25,8 +25,8 @@ static void control_udp_incoming(struct obj *obj, str *buf, const endpoint_t *si int ret; int ovec[100]; char **out; - struct msghdr mh; struct iovec iov[10]; + unsigned int iovlen; str cookie, *reply; ret = pcre_exec(u->parse_re, u->parse_ree, buf->s, buf->len, 0, 0, ovec, G_N_ELEMENTS(ovec)); @@ -41,10 +41,6 @@ static void control_udp_incoming(struct obj *obj, str *buf, const endpoint_t *si pcre_get_substring_list(buf->s, ovec, ret, (const char ***) &out); - /* XXX abstraction for iovec sending */ - ZERO(mh); - mh.msg_iov = iov; - iov[0].iov_base = (void *) out[RE_UDP_COOKIE]; iov[0].iov_len = strlen(out[RE_UDP_COOKIE]); if (out[RE_UDP_UL_CMD] && (chrtoupper(out[RE_UDP_UL_CMD][0]) == 'U' || chrtoupper(out[RE_UDP_UL_CMD][0]) == 'L')) { @@ -54,15 +50,15 @@ static void control_udp_incoming(struct obj *obj, str *buf, const endpoint_t *si iov[2].iov_len = strlen(out[3]); iov[3].iov_base = "\n"; iov[3].iov_len = 1; - mh.msg_iovlen = 4; + iovlen = 4; } else { iov[1].iov_base = " E8\n"; iov[1].iov_len = 4; - mh.msg_iovlen = 2; + iovlen = 2; } - socket_sendmsg(&u->udp_listener.sock, &mh, sin); + socket_sendiov(&u->udp_listener.sock, iov, iovlen, sin); pcre_free(out); @@ -96,9 +92,7 @@ static void control_udp_incoming(struct obj *obj, str *buf, const endpoint_t *si else if (chrtoupper(out[RE_UDP_DQ_CMD][0]) == 'Q') reply = call_query_udp(out, u->callmaster); else if (chrtoupper(out[RE_UDP_V_CMD][0]) == 'V') { - ZERO(mh); - mh.msg_iov = iov; - mh.msg_iovlen = 2; + iovlen = 2; iov[0].iov_base = (void *) out[RE_UDP_COOKIE]; iov[0].iov_len = strlen(out[RE_UDP_COOKIE]); @@ -115,14 +109,14 @@ static void control_udp_incoming(struct obj *obj, str *buf, const endpoint_t *si ret = 1; iov[2].iov_base = ret ? "1\n" : "0\n"; iov[2].iov_len = 2; - mh.msg_iovlen++; + iovlen++; } else { iov[2].iov_base = "20040107\n"; iov[2].iov_len = 9; - mh.msg_iovlen++; + iovlen++; } - socket_sendmsg(&u->udp_listener.sock, &mh, sin); + socket_sendiov(&u->udp_listener.sock, iov, iovlen, sin); } if (reply) { diff --git a/daemon/socket.h b/daemon/socket.h index 50dda3d00..a8b912454 100644 --- a/daemon/socket.h +++ b/daemon/socket.h @@ -141,6 +141,13 @@ INLINE int is_addr_unspecified(const sockaddr_t *a) { #define socket_recvfrom(s,a...) (s)->family->recvfrom((s), a) #define socket_sendmsg(s,a...) (s)->family->sendmsg((s), a) #define socket_sendto(s,a...) (s)->family->sendto((s), a) +INLINE ssize_t socket_sendiov(socket_t *s, const struct iovec *v, unsigned int len, const endpoint_t *dst) { + struct msghdr mh; + ZERO(mh); + mh.msg_iov = (void *) v; + mh.msg_iovlen = len; + return socket_sendmsg(s, &mh, dst); +}