lib: Added variants of sendfd and sendreq that take sendmsg flags.
authorFredrik Tolf <fredrik@dolda2000.com>
Tue, 15 Jan 2013 07:05:22 +0000 (08:05 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Tue, 15 Jan 2013 07:05:22 +0000 (08:05 +0100)
lib/proc.c
lib/proc.h
lib/req.c
lib/req.h

index 2c05608..a1dc336 100644 (file)
@@ -56,7 +56,7 @@ int stdmkchild(char **argv, void (*chinit)(void *), void *idata)
     return(fd[1]);
 }
 
     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;
 {
     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;
     
     *((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)
 }
 
 int recvfd(int sock, char **data, size_t *datalen)
index 6d2ea92..7236595 100644 (file)
@@ -4,6 +4,7 @@
 #include "req.h"
 
 int stdmkchild(char **argv, void (*chinit)(void *), void *idata);
 #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);
 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);
index 662df0f..8ff26e0 100644 (file)
--- a/lib/req.c
+++ b/lib/req.c
@@ -290,7 +290,7 @@ int writeresp(FILE *out, struct hthead *resp)
     return(0);
 }
 
     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;
 {
     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, "");
        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);
     buffree(buf);
     if(ret < 0)
        return(-1);
@@ -313,6 +313,11 @@ int sendreq(int sock, struct hthead *req, int fd)
        return(0);
 }
 
        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;
 int recvreq(int sock, struct hthead **reqp)
 {
     int fd;
index 71a7a06..054d3c1 100644 (file)
--- 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);
 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);
 int sendreq(int sock, struct hthead *req, int fd);
 int recvreq(int sock, struct hthead **reqp);
 void replrest(struct hthead *head, char *rest);