You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.2 KiB

  1. --- a/src/libwaitress/waitress.c
  2. +++ b/src/libwaitress/waitress.c
  3. @@ -805,34 +805,37 @@ static WaitressReturn_t WaitressConnect
  4. int pollres;
  5. /* we need shorter timeouts for connect() */
  6. - fcntl (sock, F_SETFL, O_NONBLOCK);
  7. + pollres = fcntl (sock, F_SETFL, O_NONBLOCK);
  8. + assert (pollres != -1);
  9. - /* increase socket receive buffer */
  10. - const int sockopt = 256*1024;
  11. - setsockopt (sock, SOL_SOCKET, SO_RCVBUF, &sockopt,
  12. - sizeof (sockopt));
  13. -
  14. - /* non-blocking connect will return immediately */
  15. - connect (sock, gacurr->ai_addr, gacurr->ai_addrlen);
  16. -
  17. - pollres = WaitressPollLoop (sock, POLLOUT, waith->timeout);
  18. - if (pollres == 0) {
  19. - ret = WAITRESS_RET_TIMEOUT;
  20. - } else if (pollres == -1) {
  21. - ret = WAITRESS_RET_ERR;
  22. - } else {
  23. - /* check connect () return value */
  24. - socklen_t pollresSize = sizeof (pollres);
  25. - getsockopt (sock, SOL_SOCKET, SO_ERROR, &pollres,
  26. - &pollresSize);
  27. - if (pollres != 0) {
  28. - ret = WAITRESS_RET_CONNECT_REFUSED;
  29. + if (connect (sock, gacurr->ai_addr, gacurr->ai_addrlen) != -1) {
  30. + /* working */
  31. + waith->request.sockfd = sock;
  32. + break;
  33. + } else if (errno == EINPROGRESS) {
  34. + /* wait for connect to succeed */
  35. + pollres = WaitressPollLoop (sock, POLLOUT, waith->timeout);
  36. + if (pollres == 0) {
  37. + ret = WAITRESS_RET_TIMEOUT;
  38. + } else if (pollres == -1) {
  39. + ret = WAITRESS_RET_ERR;
  40. } else {
  41. - /* this one is working */
  42. - waith->request.sockfd = sock;
  43. - break;
  44. + /* check connect () return value */
  45. + socklen_t pollresSize = sizeof (pollres);
  46. + getsockopt (sock, SOL_SOCKET, SO_ERROR, &pollres,
  47. + &pollresSize);
  48. + if (pollres != 0) {
  49. + ret = WAITRESS_RET_CONNECT_REFUSED;
  50. + } else {
  51. + /* this one is working */
  52. + waith->request.sockfd = sock;
  53. + break;
  54. + }
  55. }
  56. + } else {
  57. + ret = WAITRESS_RET_ERR;
  58. }
  59. +
  60. close (sock);
  61. }
  62. }
  63. --- a/src/libfootball/fb_service.c
  64. +++ b/src/libfootball/fb_service.c
  65. @@ -111,6 +111,8 @@ static bool fb_setup_socket (FB_SERVICE
  66. service->socket [which] = 0;
  67. } else {
  68. fb_perror ("socket");
  69. + // Element must be zero (not -1)
  70. + service->socket [which] = 0;
  71. };
  72. return false;
  73. }