diff options
Diffstat (limited to 'src/daemon/daemon.c')
-rw-r--r-- | src/daemon/daemon.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 5a7db531..3935832e 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c | |||
@@ -415,8 +415,6 @@ MHD_start_daemon(unsigned int options, | |||
415 | void * dh_cls) { | 415 | void * dh_cls) { |
416 | struct MHD_Daemon * retVal; | 416 | struct MHD_Daemon * retVal; |
417 | int socket_fd; | 417 | int socket_fd; |
418 | int opt; | ||
419 | int res; | ||
420 | struct sockaddr_in servaddr; | 418 | struct sockaddr_in servaddr; |
421 | 419 | ||
422 | if ((options & MHD_USE_SSL) != 0) | 420 | if ((options & MHD_USE_SSL) != 0) |
@@ -430,7 +428,10 @@ MHD_start_daemon(unsigned int options, | |||
430 | return NULL; | 428 | return NULL; |
431 | socket_fd = socket(AF_INET, SOCK_STREAM, 0); | 429 | socket_fd = socket(AF_INET, SOCK_STREAM, 0); |
432 | if (socket_fd < 0) { | 430 | if (socket_fd < 0) { |
433 | /* FIXME: log error */ | 431 | if ((options & MHD_USE_DEBUG) != 0) |
432 | fprintf(stderr, | ||
433 | "Call to socket failed: %s\n", | ||
434 | strerror(errno)); | ||
434 | return NULL; | 435 | return NULL; |
435 | } | 436 | } |
436 | memset(&servaddr, | 437 | memset(&servaddr, |
@@ -441,22 +442,22 @@ MHD_start_daemon(unsigned int options, | |||
441 | if (bind(socket_fd, | 442 | if (bind(socket_fd, |
442 | (struct sockaddr *)&servaddr, | 443 | (struct sockaddr *)&servaddr, |
443 | sizeof(struct sockaddr_in)) < 0) { | 444 | sizeof(struct sockaddr_in)) < 0) { |
444 | /* FIXME: log error */ | 445 | if ( (options & MHD_USE_DEBUG) != 0) |
446 | fprintf(stderr, | ||
447 | "Failed to bind to port %u: %s\n", | ||
448 | port, | ||
449 | strerror(errno)); | ||
445 | close(socket_fd); | 450 | close(socket_fd); |
446 | return NULL; | 451 | return NULL; |
447 | } | 452 | } |
448 | if (listen(socket_fd, 20) < 0) { | 453 | if (listen(socket_fd, 20) < 0) { |
449 | /* FIXME: log error */ | 454 | if ((options & MHD_USE_DEBUG) != 0) |
455 | fprintf(stderr, | ||
456 | "Failed to listen for connections: %s\n", | ||
457 | strerror(errno)); | ||
458 | close(socket_fd); | ||
450 | return NULL; | 459 | return NULL; |
451 | } | 460 | } |
452 | opt = fcntl(socket_fd, F_GETFL, 0); | ||
453 | res = fcntl(socket_fd, F_SETFL, opt | O_NONBLOCK); | ||
454 | if (res < 0) { | ||
455 | /* FIXME: log error */ | ||
456 | close(socket_fd); | ||
457 | return NULL; | ||
458 | } | ||
459 | |||
460 | retVal = malloc(sizeof(struct MHD_Daemon)); | 461 | retVal = malloc(sizeof(struct MHD_Daemon)); |
461 | memset(retVal, | 462 | memset(retVal, |
462 | 0, | 463 | 0, |
@@ -476,7 +477,9 @@ MHD_start_daemon(unsigned int options, | |||
476 | NULL, | 477 | NULL, |
477 | &MHD_select_thread, | 478 | &MHD_select_thread, |
478 | daemon)) ) { | 479 | daemon)) ) { |
479 | /* FIXME: log error */ | 480 | MHD_DLOG(retVal, |
481 | "Failed to create listen thread: %s\n", | ||
482 | strerror(errno)); | ||
480 | free(retVal); | 483 | free(retVal); |
481 | close(socket_fd); | 484 | close(socket_fd); |
482 | return NULL; | 485 | return NULL; |
@@ -512,3 +515,4 @@ MHD_stop_daemon(struct MHD_Daemon * daemon) { | |||
512 | free(daemon); | 515 | free(daemon); |
513 | } | 516 | } |
514 | 517 | ||
518 | /* end of daemon.c */ | ||