Browse Source

Fix coupling problems on OSX

v0.7.4-release
Ryan 16 years ago
parent
commit
b0a362a727
  1. 30
      deps/coupling/coupling.c

30
deps/coupling/coupling.c

@ -143,9 +143,8 @@ ring_buffer_push (ring_buffer *ring, int fd)
return r;
}
static void
pump (int pullfd, int pushfd)
pump (int is_pull, int pullfd, int pushfd)
{
int r;
ring_buffer ring;
@ -160,34 +159,41 @@ pump (int pullfd, int pushfd)
FD_ZERO(&readfds);
FD_ZERO(&writefds);
maxfd = -1;
if (is_pull) {
if (!ring_buffer_empty_p(&ring)) {
maxfd = pushfd;
FD_SET(pushfd, &exceptfds);
FD_SET(pushfd, &writefds);
}
} else {
if (pullfd >= 0) {
if (!ring_buffer_filled_p(&ring)) {
maxfd = pullfd;
FD_SET(pullfd, &exceptfds);
maxfd = MAX(pushfd, pullfd);
if (!ring_buffer_filled_p(&ring)) FD_SET(pullfd, &readfds);
FD_SET(pullfd, &readfds);
}
}
if (!ring_buffer_empty_p(&ring)) {
FD_SET(pushfd, &writefds);
}
if (maxfd >= 0) {
r = select(maxfd+1, &readfds, &writefds, &exceptfds, NULL);
if (r < 0 || FD_ISSET(pushfd, &exceptfds)) {
if (r < 0 || (pullfd >= 0 && FD_ISSET(pushfd, &exceptfds))) {
close(pushfd);
close(pullfd);
pushfd = pullfd = -1;
return;
}
}
if (pullfd >= 0 && FD_ISSET(pullfd, &exceptfds)) {
close(pullfd);
pullfd = -1;
}
if (pullfd >= 0 && FD_ISSET(pullfd, &readfds)) {
if (pullfd >= 0 && (is_pull || FD_ISSET(pullfd, &readfds))) {
r = ring_buffer_pull(&ring, pullfd);
if (r == 0) {
/* eof */
@ -199,7 +205,7 @@ pump (int pullfd, int pushfd)
}
}
if (FD_ISSET(pushfd, &writefds)) {
if (!is_pull || FD_ISSET(pushfd, &writefds)) {
r = ring_buffer_push(&ring, pushfd);
if (r < 0) {
switch (errno) {
@ -256,7 +262,7 @@ pump_thread (void *data)
{
struct coupling *c = (struct coupling*)data;
pump(c->pullfd, c->pushfd);
pump(c->is_pull, c->pullfd, c->pushfd);
return NULL;
}

Loading…
Cancel
Save