Bottom: 3ea2748a5c41b11a2e7033c56bddd938d2770b6c
-Top: 216390f24bdb1fa45d9326571f8dd46b1fd804ef
+Top: 64baa18c546931a07eef988a8d6bdef26a73feab
Author: Sean Hefty <sean.hefty@intel.com>
Date: 2012-08-10 21:44:39 -0700
---
diff --git a/src/preload.c b/src/preload.c
-index b18d310..c61d092 100644
+index b18d310..e5d3fcb 100644
--- a/src/preload.c
+++ b/src/preload.c
@@ -99,12 +99,20 @@ static int fork_support;
set_rsocket_options(ret);
}
return index;
-@@ -427,22 +444,32 @@ int listen(int socket, int backlog)
+@@ -419,30 +436,46 @@ int bind(int socket, const struct sockaddr *addr, socklen_t addrlen)
+
+ int listen(int socket, int backlog)
+ {
+- int fd;
+- return (fd_get(socket, &fd) == fd_rsocket) ?
+- rlisten(fd, backlog) : real.listen(fd, backlog);
++ int fd, ret;
++ if (fd_get(socket, &fd) == fd_rsocket) {
++ ret = rlisten(fd, backlog);
++ } else {
++ ret = real.listen(fd, backlog);
++ if (!ret && fd_gets(socket) == fd_fork)
++ fd_store(socket, fd, fd_normal, fd_fork_listen);
++ }
++ return ret;
+ }
+
int accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
{
int fd, index, ret;
- type = fd_get(socket, &fd);
- if (type == fd_rsocket || type == fd_fork) {
+ if (fd_get(socket, &fd) == fd_rsocket) {
-+ index = fd_open();
-+ if (index < 0)
-+ return index;
-+
-+ ret = raccept(fd, addr, addrlen);
-+ if (ret < 0) {
-+ fd_close(index, &fd);
-+ return ret;
-+ }
-+
-+ fd_store(index, ret, fd_rsocket, fd_ready);
-+ return index;
-+ } else if (fd_gets(socket) == fd_fork_listen) {
index = fd_open();
if (index < 0)
return index;
- ret = (type == fd_rsocket) ? raccept(fd, addr, addrlen) :
- real.accept(fd, addr, addrlen);
-+ ret = real.accept(fd, addr, addrlen);
++ ret = raccept(fd, addr, addrlen);
if (ret < 0) {
fd_close(index, &fd);
return ret;
}
- fd_store(index, ret, type);
++ fd_store(index, ret, fd_rsocket, fd_ready);
++ return index;
++ } else if (fd_gets(socket) == fd_fork_listen) {
++ index = fd_open();
++ if (index < 0)
++ return index;
++
++ ret = real.accept(fd, addr, addrlen);
++ if (ret < 0) {
++ fd_close(index, &fd);
++ return ret;
++ }
++
+ fd_store(index, ret, fd_normal, fd_fork_passive);
return index;
} else {
return real.accept(fd, addr, addrlen);
-@@ -471,7 +498,7 @@ static int fork_active(int socket, const struct sockaddr *addr, socklen_t addrle
+@@ -471,7 +504,7 @@ static int fork_active(int socket, const struct sockaddr *addr, socklen_t addrle
ret = real.recv(fd, &msg, sizeof msg, MSG_PEEK);
if ((ret != sizeof msg) || msg) {
return 0;
}
-@@ -544,7 +571,7 @@ static void fork_passive(int socket)
+@@ -544,7 +577,7 @@ static void fork_passive(int socket)
copysockopts(dfd, sfd, &rs, &real);
real.shutdown(sfd, SHUT_RDWR);
real.close(sfd);
lclose:
rclose(lfd);
-@@ -553,7 +580,7 @@ sclose:
+@@ -553,7 +586,7 @@ sclose:
sem_close(sem);
out:
if (ret)
}
static inline enum fd_type fd_fork_get(int index, int *fd)
-@@ -577,10 +604,7 @@ int connect(int socket, const struct sockaddr *addr, socklen_t addrlen)
+@@ -562,8 +595,10 @@ static inline enum fd_type fd_fork_get(int index, int *fd)
+
+ fdi = idm_lookup(&idm, index);
+ if (fdi) {
+- if (fdi->type == fd_fork)
++ if (fdi->type == fd_fork_passive)
+ fork_passive(index);
++ else if (fdi->type == fd_fork_active)
++ fork_active(index);
+ *fd = fdi->fd;
+ return fdi->type;
+
+@@ -577,10 +612,7 @@ int connect(int socket, const struct sockaddr *addr, socklen_t addrlen)
{
int fd, ret;
ret = rconnect(fd, addr, addrlen);
if (!ret || errno == EINPROGRESS)
return ret;
-@@ -591,12 +615,9 @@ int connect(int socket, const struct sockaddr *addr, socklen_t addrlen)
+@@ -591,12 +623,10 @@ int connect(int socket, const struct sockaddr *addr, socklen_t addrlen)
rclose(fd);
fd = ret;
- default:
- break;
+ } else {
++ /* Set state to fork_active if nonblocking. if blocking fork_active */
+ return real.connect(fd, addr, addrlen);
}
-
+++ /dev/null
-Bottom: 216390f24bdb1fa45d9326571f8dd46b1fd804ef
-Top: 64baa18c546931a07eef988a8d6bdef26a73feab
-Author: Sean Hefty <sean.hefty@intel.com>
-Date: 2012-08-10 22:13:06 -0700
-
-Refresh of fork-connect
-
----
-
-diff --git a/src/preload.c b/src/preload.c
-index c61d092..e5d3fcb 100644
---- a/src/preload.c
-+++ b/src/preload.c
-@@ -436,9 +436,15 @@ int bind(int socket, const struct sockaddr *addr, socklen_t addrlen)
-
- int listen(int socket, int backlog)
- {
-- int fd;
-- return (fd_get(socket, &fd) == fd_rsocket) ?
-- rlisten(fd, backlog) : real.listen(fd, backlog);
-+ int fd, ret;
-+ if (fd_get(socket, &fd) == fd_rsocket) {
-+ ret = rlisten(fd, backlog);
-+ } else {
-+ ret = real.listen(fd, backlog);
-+ if (!ret && fd_gets(socket) == fd_fork)
-+ fd_store(socket, fd, fd_normal, fd_fork_listen);
-+ }
-+ return ret;
- }
-
- int accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
-@@ -589,8 +595,10 @@ static inline enum fd_type fd_fork_get(int index, int *fd)
-
- fdi = idm_lookup(&idm, index);
- if (fdi) {
-- if (fdi->type == fd_fork)
-+ if (fdi->type == fd_fork_passive)
- fork_passive(index);
-+ else if (fdi->type == fd_fork_active)
-+ fork_active(index);
- *fd = fdi->fd;
- return fdi->type;
-
-@@ -616,6 +624,7 @@ int connect(int socket, const struct sockaddr *addr, socklen_t addrlen)
- rclose(fd);
- fd = ret;
- } else {
-+ /* Set state to fork_active if nonblocking. if blocking fork_active */
- return real.connect(fd, addr, addrlen);
- }
- }