Browse code

fix accept

aCaB authored on 2010/01/30 04:10:45
Showing 2 changed files
... ...
@@ -301,20 +301,11 @@ struct acceptdata {
301 301
     pthread_cond_t cond_nfds;
302 302
     int max_queue;
303 303
     int commandtimeout;
304
-#ifdef _WIN32
305
-    HANDLE event_wake_recv;
306
-    HANDLE event_wake_accept;
307
-#else
308 304
     int syncpipe_wake_recv[2];
309 305
     int syncpipe_wake_accept[2];
310
-#endif
311 306
 };
312 307
 
313
-#ifdef _WIN32
314
-#define ACCEPTDATA_INIT(mutex1, mutex2) { FDS_INIT(mutex1), FDS_INIT(mutex2), PTHREAD_COND_INITIALIZER, 0, 0, NULL, NULL}
315
-#else
316 308
 #define ACCEPTDATA_INIT(mutex1, mutex2) { FDS_INIT(mutex1), FDS_INIT(mutex2), PTHREAD_COND_INITIALIZER, 0, 0, {-1, -1}, {-1, -1}}
317
-#endif
318 309
 
319 310
 static void *acceptloop_th(void *arg)
320 311
 {
... ...
@@ -330,7 +321,9 @@ static void *acceptloop_th(void *arg)
330 330
     for (;;) {
331 331
 	/* Block waiting for data to become available for reading */
332 332
 	int new_sd = fds_poll_recv(fds, -1, 0, event_wake_accept);
333
-
333
+#ifdef _WIN32
334
+	ResetEvent(event_wake_accept);
335
+#endif
334 336
 	/* TODO: what about sockets that get rm-ed? */
335 337
 	if (!fds->nfds) {
336 338
 	    /* no more sockets to poll, all gave an error */
... ...
@@ -351,7 +344,7 @@ static void *acceptloop_th(void *arg)
351 351
 	    struct fd_buf *buf = &fds->buf[i];
352 352
 	    if (!buf->got_newdata)
353 353
 		continue;
354
-#ifndef _WIN32 // FIXME
354
+#ifndef _WIN32
355 355
 	    if (buf->fd == data->syncpipe_wake_accept[0]) {
356 356
 		/* dummy sync pipe, just to wake us */
357 357
 		if (read(buf->fd, buff, sizeof(buff)) < 0) {
... ...
@@ -1107,8 +1100,9 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
1107 1107
 	    pthread_cond_signal(&acceptdata.cond_nfds);
1108 1108
 	new_sd = fds_poll_recv(fds, selfchk ? (int)selfchk : -1, 1, event_wake_recv);
1109 1109
 
1110
-
1111
-#ifndef _WIN32
1110
+#ifdef _WIN32
1111
+	ResetEvent(event_wake_recv);
1112
+#else
1112 1113
 	if (!fds->nfds) {
1113 1114
 	    continue;
1114 1115
 	    /* at least the dummy/sync pipe should have remained */
... ...
@@ -1137,7 +1131,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
1137 1137
 	    if (!buf->got_newdata)
1138 1138
 		continue;
1139 1139
 
1140
-#ifndef _WIN32 //FIXME
1140
+#ifndef _WIN32
1141 1141
 	    if (buf->fd == acceptdata.syncpipe_wake_recv[0]) {
1142 1142
 		/* dummy sync pipe, just to wake us */
1143 1143
 		if (read(buf->fd, buff, sizeof(buff)) < 0) {
... ...
@@ -386,7 +386,10 @@ int poll_with_event(struct pollfd *fds, int nfds, int timeout, HANDLE event) {
386 386
     setme[1] = event;
387 387
     timeout = timeout>=0 ? timeout*1000 : INFINITE;
388 388
     if(!nfds) {
389
-	Sleep(timeout);
389
+	if(event)
390
+	    WaitForSingleObject(event, timeout);
391
+	else
392
+	    Sleep(timeout);
390 393
 	return 0;
391 394
     }
392 395
     items = malloc(nfds * sizeof(struct w32polldata));