diff options
Diffstat (limited to 'src/daemon/daemon.c')
-rw-r--r-- | src/daemon/daemon.c | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 9aad7593..70d5075f 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c | |||
@@ -174,7 +174,7 @@ MHD_handle_connection(void * data) { | |||
174 | &ws, | 174 | &ws, |
175 | &es, | 175 | &es, |
176 | &max); | 176 | &max); |
177 | num_ready = select(max + 1, | 177 | num_ready = SELECT(max + 1, |
178 | &rs, | 178 | &rs, |
179 | &ws, | 179 | &ws, |
180 | &es, | 180 | &es, |
@@ -192,7 +192,7 @@ MHD_handle_connection(void * data) { | |||
192 | break; | 192 | break; |
193 | } | 193 | } |
194 | if (con->socket_fd != -1) { | 194 | if (con->socket_fd != -1) { |
195 | close(con->socket_fd); | 195 | CLOSE(con->socket_fd); |
196 | con->socket_fd = -1; | 196 | con->socket_fd = -1; |
197 | } | 197 | } |
198 | return NULL; | 198 | return NULL; |
@@ -215,20 +215,20 @@ MHD_accept_connection(struct MHD_Daemon * daemon) { | |||
215 | memset(&addr, | 215 | memset(&addr, |
216 | 0, | 216 | 0, |
217 | sizeof(struct sockaddr)); | 217 | sizeof(struct sockaddr)); |
218 | s = accept(daemon->socket_fd, | 218 | s = ACCEPT(daemon->socket_fd, |
219 | &addr, | 219 | &addr, |
220 | &addrlen); | 220 | &addrlen); |
221 | if ( (s < 0) || | 221 | if ( (s < 0) || |
222 | (addrlen <= 0) ) { | 222 | (addrlen <= 0) ) { |
223 | MHD_DLOG(daemon, | 223 | MHD_DLOG(daemon, |
224 | "Error accepting connection: %s\n", | 224 | "Error accepting connection: %s\n", |
225 | strerror(errno)); | 225 | STRERROR(errno)); |
226 | return MHD_NO; | 226 | return MHD_NO; |
227 | } | 227 | } |
228 | if (MHD_NO == daemon->apc(daemon->apc_cls, | 228 | if (MHD_NO == daemon->apc(daemon->apc_cls, |
229 | &addr, | 229 | &addr, |
230 | addrlen)) { | 230 | addrlen)) { |
231 | close(s); | 231 | CLOSE(s); |
232 | return MHD_YES; | 232 | return MHD_YES; |
233 | } | 233 | } |
234 | session = malloc(sizeof(struct MHD_Session)); | 234 | session = malloc(sizeof(struct MHD_Session)); |
@@ -249,9 +249,9 @@ MHD_accept_connection(struct MHD_Daemon * daemon) { | |||
249 | session)) ) { | 249 | session)) ) { |
250 | MHD_DLOG(daemon, | 250 | MHD_DLOG(daemon, |
251 | "Failed to create a thread: %s\n", | 251 | "Failed to create a thread: %s\n", |
252 | strerror(errno)); | 252 | STRERROR(errno)); |
253 | free(session->addr); | 253 | free(session->addr); |
254 | close(s); | 254 | CLOSE(s); |
255 | free(session); | 255 | free(session); |
256 | return MHD_NO; | 256 | return MHD_NO; |
257 | } | 257 | } |
@@ -367,7 +367,7 @@ MHD_select(struct MHD_Daemon * daemon, | |||
367 | max = daemon->socket_fd; | 367 | max = daemon->socket_fd; |
368 | FD_SET(daemon->socket_fd, &rs); | 368 | FD_SET(daemon->socket_fd, &rs); |
369 | } | 369 | } |
370 | num_ready = select(max + 1, | 370 | num_ready = SELECT(max + 1, |
371 | &rs, | 371 | &rs, |
372 | &ws, | 372 | &ws, |
373 | &es, | 373 | &es, |
@@ -377,7 +377,7 @@ MHD_select(struct MHD_Daemon * daemon, | |||
377 | return MHD_YES; | 377 | return MHD_YES; |
378 | MHD_DLOG(daemon, | 378 | MHD_DLOG(daemon, |
379 | "Select failed: %s\n", | 379 | "Select failed: %s\n", |
380 | strerror(errno)); | 380 | STRERROR(errno)); |
381 | return MHD_NO; | 381 | return MHD_NO; |
382 | } | 382 | } |
383 | ds = daemon->socket_fd; | 383 | ds = daemon->socket_fd; |
@@ -472,12 +472,12 @@ MHD_start_daemon(unsigned int options, | |||
472 | if ( (port == 0) || | 472 | if ( (port == 0) || |
473 | (dh == NULL) ) | 473 | (dh == NULL) ) |
474 | return NULL; | 474 | return NULL; |
475 | socket_fd = socket(AF_INET, SOCK_STREAM, 0); | 475 | socket_fd = SOCKET(AF_INET, SOCK_STREAM, 0); |
476 | if (socket_fd < 0) { | 476 | if (socket_fd < 0) { |
477 | if ((options & MHD_USE_DEBUG) != 0) | 477 | if ((options & MHD_USE_DEBUG) != 0) |
478 | fprintf(stderr, | 478 | fprintf(stderr, |
479 | "Call to socket failed: %s\n", | 479 | "Call to socket failed: %s\n", |
480 | strerror(errno)); | 480 | STRERROR(errno)); |
481 | return NULL; | 481 | return NULL; |
482 | } | 482 | } |
483 | /* FIXME: setsockopt: SO_REUSEADDR? */ | 483 | /* FIXME: setsockopt: SO_REUSEADDR? */ |
@@ -486,23 +486,23 @@ MHD_start_daemon(unsigned int options, | |||
486 | sizeof(struct sockaddr_in)); | 486 | sizeof(struct sockaddr_in)); |
487 | servaddr.sin_family = AF_INET; | 487 | servaddr.sin_family = AF_INET; |
488 | servaddr.sin_port = htons(port); | 488 | servaddr.sin_port = htons(port); |
489 | if (bind(socket_fd, | 489 | if (BIND(socket_fd, |
490 | (struct sockaddr *)&servaddr, | 490 | (struct sockaddr *)&servaddr, |
491 | sizeof(struct sockaddr_in)) < 0) { | 491 | sizeof(struct sockaddr_in)) < 0) { |
492 | if ( (options & MHD_USE_DEBUG) != 0) | 492 | if ( (options & MHD_USE_DEBUG) != 0) |
493 | fprintf(stderr, | 493 | fprintf(stderr, |
494 | "Failed to bind to port %u: %s\n", | 494 | "Failed to bind to port %u: %s\n", |
495 | port, | 495 | port, |
496 | strerror(errno)); | 496 | STRERROR(errno)); |
497 | close(socket_fd); | 497 | CLOSE(socket_fd); |
498 | return NULL; | 498 | return NULL; |
499 | } | 499 | } |
500 | if (listen(socket_fd, 20) < 0) { | 500 | if (LISTEN(socket_fd, 20) < 0) { |
501 | if ((options & MHD_USE_DEBUG) != 0) | 501 | if ((options & MHD_USE_DEBUG) != 0) |
502 | fprintf(stderr, | 502 | fprintf(stderr, |
503 | "Failed to listen for connections: %s\n", | 503 | "Failed to listen for connections: %s\n", |
504 | strerror(errno)); | 504 | STRERROR(errno)); |
505 | close(socket_fd); | 505 | CLOSE(socket_fd); |
506 | return NULL; | 506 | return NULL; |
507 | } | 507 | } |
508 | retVal = malloc(sizeof(struct MHD_Daemon)); | 508 | retVal = malloc(sizeof(struct MHD_Daemon)); |
@@ -526,9 +526,9 @@ MHD_start_daemon(unsigned int options, | |||
526 | retVal)) ) { | 526 | retVal)) ) { |
527 | MHD_DLOG(retVal, | 527 | MHD_DLOG(retVal, |
528 | "Failed to create listen thread: %s\n", | 528 | "Failed to create listen thread: %s\n", |
529 | strerror(errno)); | 529 | STRERROR(errno)); |
530 | free(retVal); | 530 | free(retVal); |
531 | close(socket_fd); | 531 | CLOSE(socket_fd); |
532 | return NULL; | 532 | return NULL; |
533 | } | 533 | } |
534 | return retVal; | 534 | return retVal; |
@@ -544,7 +544,7 @@ MHD_stop_daemon(struct MHD_Daemon * daemon) { | |||
544 | if (daemon == NULL) | 544 | if (daemon == NULL) |
545 | return; | 545 | return; |
546 | daemon->shutdown = 1; | 546 | daemon->shutdown = 1; |
547 | close(daemon->socket_fd); | 547 | CLOSE(daemon->socket_fd); |
548 | daemon->socket_fd = -1; | 548 | daemon->socket_fd = -1; |
549 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || | 549 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || |
550 | (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) { | 550 | (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) { |
@@ -553,7 +553,7 @@ MHD_stop_daemon(struct MHD_Daemon * daemon) { | |||
553 | } | 553 | } |
554 | while (daemon->connections != NULL) { | 554 | while (daemon->connections != NULL) { |
555 | if (-1 != daemon->connections->socket_fd) { | 555 | if (-1 != daemon->connections->socket_fd) { |
556 | close(daemon->connections->socket_fd); | 556 | CLOSE(daemon->connections->socket_fd); |
557 | daemon->connections->socket_fd = -1; | 557 | daemon->connections->socket_fd = -1; |
558 | } | 558 | } |
559 | MHD_cleanup_sessions(daemon); | 559 | MHD_cleanup_sessions(daemon); |