From: Fredrik Tolf Date: Tue, 15 Jan 2013 07:05:22 +0000 (+0100) Subject: lib: Added variants of sendfd and sendreq that take sendmsg flags. X-Git-Tag: 0.12~10 X-Git-Url: http://www.dolda2000.com/gitweb/?p=ashd.git;a=commitdiff_plain;h=d9f67feaea01146d7ea10abfff2dc59ff8946ced lib: Added variants of sendfd and sendreq that take sendmsg flags. --- diff --git a/lib/proc.c b/lib/proc.c index 2c05608..a1dc336 100644 --- a/lib/proc.c +++ b/lib/proc.c @@ -56,7 +56,7 @@ int stdmkchild(char **argv, void (*chinit)(void *), void *idata) return(fd[1]); } -int sendfd(int sock, int fd, char *data, size_t datalen) +int sendfd2(int sock, int fd, char *data, size_t datalen, int flags) { struct msghdr msg; struct cmsghdr *cmsg; @@ -78,7 +78,12 @@ int sendfd(int sock, int fd, char *data, size_t datalen) *((int *)CMSG_DATA(cmsg)) = fd; msg.msg_controllen = cmsg->cmsg_len; - return(sendmsg(sock, &msg, MSG_NOSIGNAL | MSG_DONTWAIT)); + return(sendmsg(sock, &msg, flags)); +} + +int sendfd(int sock, int fd, char *data, size_t datalen) +{ + return(sendfd2(sock, fd, data, datalen, MSG_NOSIGNAL | MSG_DONTWAIT)); } int recvfd(int sock, char **data, size_t *datalen) diff --git a/lib/proc.h b/lib/proc.h index 6d2ea92..7236595 100644 --- a/lib/proc.h +++ b/lib/proc.h @@ -4,6 +4,7 @@ #include "req.h" int stdmkchild(char **argv, void (*chinit)(void *), void *idata); +int sendfd2(int sock, int fd, char *data, size_t datalen, int flags); int sendfd(int sock, int fd, char *data, size_t datalen); int recvfd(int sock, char **data, size_t *datalen); pid_t stdforkserve(char **argv, struct hthead *req, int fd, void (*chinit)(void *), void *idata); diff --git a/lib/req.c b/lib/req.c index 662df0f..8ff26e0 100644 --- a/lib/req.c +++ b/lib/req.c @@ -290,7 +290,7 @@ int writeresp(FILE *out, struct hthead *resp) return(0); } -int sendreq(int sock, struct hthead *req, int fd) +int sendreq2(int sock, struct hthead *req, int fd, int flags) { int ret, i; struct charbuf buf; @@ -305,7 +305,7 @@ int sendreq(int sock, struct hthead *req, int fd) bufcatstr2(buf, req->headers[i][1]); } bufcatstr2(buf, ""); - ret = sendfd(sock, fd, buf.b, buf.d); + ret = sendfd2(sock, fd, buf.b, buf.d, flags); buffree(buf); if(ret < 0) return(-1); @@ -313,6 +313,11 @@ int sendreq(int sock, struct hthead *req, int fd) return(0); } +int sendreq(int sock, struct hthead *req, int fd) +{ + return(sendreq2(sock, req, fd, MSG_NOSIGNAL | MSG_DONTWAIT)); +} + int recvreq(int sock, struct hthead **reqp) { int fd; diff --git a/lib/req.h b/lib/req.h index 71a7a06..054d3c1 100644 --- a/lib/req.h +++ b/lib/req.h @@ -18,6 +18,7 @@ char *getheader(struct hthead *head, char *name); void headpreheader(struct hthead *head, const char *name, const char *val); void headappheader(struct hthead *head, const char *name, const char *val); void headrmheader(struct hthead *head, const char *name); +int sendreq2(int sock, struct hthead *req, int fd, int flags); int sendreq(int sock, struct hthead *req, int fd); int recvreq(int sock, struct hthead **reqp); void replrest(struct hthead *head, char *rest);