diff options
-rw-r--r-- | src/util/client.c | 99 | ||||
-rw-r--r-- | src/util/connection.c | 73 | ||||
-rw-r--r-- | src/util/network.c | 4 | ||||
-rw-r--r-- | src/util/server.c | 114 |
4 files changed, 199 insertions, 91 deletions
diff --git a/src/util/client.c b/src/util/client.c index 2271c4c5c..11abecfcf 100644 --- a/src/util/client.c +++ b/src/util/client.c | |||
@@ -217,7 +217,9 @@ struct GNUNET_CLIENT_Connection | |||
217 | 217 | ||
218 | /** | 218 | /** |
219 | * Are we currently busy doing receive-processing? | 219 | * Are we currently busy doing receive-processing? |
220 | * #GNUNET_YES if so, #GNUNET_NO if not. | 220 | * #GNUNET_YES if so, #GNUNET_NO if not. #GNUNET_SYSERR |
221 | * if the connection has failed (but we may not have | ||
222 | * closed the handle itself yet). | ||
221 | */ | 223 | */ |
222 | int in_receive; | 224 | int in_receive; |
223 | 225 | ||
@@ -504,8 +506,12 @@ check_complete (struct GNUNET_CLIENT_Connection *client) | |||
504 | * @param errCode value of errno (on errors receiving) | 506 | * @param errCode value of errno (on errors receiving) |
505 | */ | 507 | */ |
506 | static void | 508 | static void |
507 | receive_helper (void *cls, const void *buf, size_t available, | 509 | receive_helper (void *cls, |
508 | const struct sockaddr *addr, socklen_t addrlen, int errCode) | 510 | const void *buf, |
511 | size_t available, | ||
512 | const struct sockaddr *addr, | ||
513 | socklen_t addrlen, | ||
514 | int errCode) | ||
509 | { | 515 | { |
510 | struct GNUNET_CLIENT_Connection *client = cls; | 516 | struct GNUNET_CLIENT_Connection *client = cls; |
511 | struct GNUNET_TIME_Relative remaining; | 517 | struct GNUNET_TIME_Relative remaining; |
@@ -515,19 +521,25 @@ receive_helper (void *cls, const void *buf, size_t available, | |||
515 | GNUNET_assert (GNUNET_NO == client->msg_complete); | 521 | GNUNET_assert (GNUNET_NO == client->msg_complete); |
516 | GNUNET_assert (GNUNET_YES == client->in_receive); | 522 | GNUNET_assert (GNUNET_YES == client->in_receive); |
517 | client->in_receive = GNUNET_NO; | 523 | client->in_receive = GNUNET_NO; |
518 | if ((0 == available) || (NULL == client->connection) || (0 != errCode)) | 524 | if ( (0 == available) || |
525 | (NULL == client->connection) || | ||
526 | (0 != errCode) ) | ||
519 | { | 527 | { |
520 | /* signal timeout! */ | 528 | /* signal timeout! */ |
521 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 529 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
522 | "Timeout in receive_helper, available %u, client->connection %s, errCode `%s'\n", | 530 | "Timeout in receive_helper, available %u, client->connection %s, errCode `%s'\n", |
523 | (unsigned int) available, NULL == client->connection ? "NULL" : "non-NULL", | 531 | (unsigned int) available, |
532 | NULL == client->connection ? "NULL" : "non-NULL", | ||
524 | STRERROR (errCode)); | 533 | STRERROR (errCode)); |
525 | if (NULL != (receive_handler = client->receiver_handler)) | 534 | if (NULL != (receive_handler = client->receiver_handler)) |
526 | { | 535 | { |
527 | receive_handler_cls = client->receiver_handler_cls; | 536 | receive_handler_cls = client->receiver_handler_cls; |
528 | client->receiver_handler = NULL; | 537 | client->receiver_handler = NULL; |
529 | receive_handler (receive_handler_cls, NULL); | 538 | receive_handler (receive_handler_cls, |
539 | NULL); | ||
530 | } | 540 | } |
541 | /* remember failure */ | ||
542 | client->in_receive = GNUNET_SYSERR; | ||
531 | return; | 543 | return; |
532 | } | 544 | } |
533 | /* FIXME: optimize for common fast case where buf contains the | 545 | /* FIXME: optimize for common fast case where buf contains the |
@@ -565,7 +577,8 @@ receive_helper (void *cls, const void *buf, size_t available, | |||
565 | * @param tc scheduler context | 577 | * @param tc scheduler context |
566 | */ | 578 | */ |
567 | static void | 579 | static void |
568 | receive_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 580 | receive_task (void *cls, |
581 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
569 | { | 582 | { |
570 | struct GNUNET_CLIENT_Connection *client = cls; | 583 | struct GNUNET_CLIENT_Connection *client = cls; |
571 | GNUNET_CLIENT_MessageHandler handler = client->receiver_handler; | 584 | GNUNET_CLIENT_MessageHandler handler = client->receiver_handler; |
@@ -576,12 +589,22 @@ receive_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
576 | char mbuf[msize] GNUNET_ALIGN; | 589 | char mbuf[msize] GNUNET_ALIGN; |
577 | struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) mbuf; | 590 | struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) mbuf; |
578 | 591 | ||
592 | client->receive_task = NULL; | ||
593 | if ( (GNUNET_SYSERR == client->in_receive) && | ||
594 | (GNUNET_YES != client->msg_complete) ) | ||
595 | { | ||
596 | /* Connection failure, signal to caller! */ | ||
597 | client->receiver_handler = NULL; | ||
598 | if (NULL != handler) | ||
599 | handler (handler_cls, | ||
600 | NULL); | ||
601 | return; | ||
602 | } | ||
579 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 603 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
580 | "Received message of type %u and size %u from %s service.\n", | 604 | "Received message of type %u and size %u from %s service.\n", |
581 | ntohs (cmsg->type), | 605 | ntohs (cmsg->type), |
582 | msize, | 606 | msize, |
583 | client->service_name); | 607 | client->service_name); |
584 | client->receive_task = NULL; | ||
585 | GNUNET_assert (GNUNET_YES == client->msg_complete); | 608 | GNUNET_assert (GNUNET_YES == client->msg_complete); |
586 | GNUNET_assert (client->received_pos >= msize); | 609 | GNUNET_assert (client->received_pos >= msize); |
587 | memcpy (msg, cmsg, msize); | 610 | memcpy (msg, cmsg, msize); |
@@ -618,25 +641,29 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *client, | |||
618 | client->service_name); | 641 | client->service_name); |
619 | GNUNET_break (0); /* this should not happen in well-written code! */ | 642 | GNUNET_break (0); /* this should not happen in well-written code! */ |
620 | if (NULL != handler) | 643 | if (NULL != handler) |
621 | handler (handler_cls, NULL); | 644 | handler (handler_cls, |
645 | NULL); | ||
622 | return; | 646 | return; |
623 | } | 647 | } |
624 | client->receiver_handler = handler; | 648 | client->receiver_handler = handler; |
625 | client->receiver_handler_cls = handler_cls; | 649 | client->receiver_handler_cls = handler_cls; |
626 | client->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout); | 650 | client->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
627 | if (GNUNET_YES == client->msg_complete) | 651 | if ( (GNUNET_YES == client->msg_complete) || |
652 | (GNUNET_SYSERR == client->in_receive) ) | ||
628 | { | 653 | { |
629 | GNUNET_assert (NULL == client->receive_task); | 654 | GNUNET_assert (NULL == client->receive_task); |
630 | client->receive_task = GNUNET_SCHEDULER_add_now (&receive_task, client); | 655 | client->receive_task = GNUNET_SCHEDULER_add_now (&receive_task, client); |
656 | return; | ||
631 | } | 657 | } |
632 | else | 658 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
633 | { | 659 | "calling GNUNET_CONNECTION_receive\n"); |
634 | LOG (GNUNET_ERROR_TYPE_DEBUG, "calling GNUNET_CONNECTION_receive\n"); | 660 | GNUNET_assert (GNUNET_NO == client->in_receive); |
635 | GNUNET_assert (GNUNET_NO == client->in_receive); | 661 | client->in_receive = GNUNET_YES; |
636 | client->in_receive = GNUNET_YES; | 662 | GNUNET_CONNECTION_receive (client->connection, |
637 | GNUNET_CONNECTION_receive (client->connection, GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, | 663 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, |
638 | timeout, &receive_helper, client); | 664 | timeout, |
639 | } | 665 | &receive_helper, |
666 | client); | ||
640 | } | 667 | } |
641 | 668 | ||
642 | 669 | ||
@@ -751,7 +778,8 @@ service_test_report (struct GNUNET_CLIENT_TestHandle *th, | |||
751 | * @param msg message received, NULL on timeout or fatal error | 778 | * @param msg message received, NULL on timeout or fatal error |
752 | */ | 779 | */ |
753 | static void | 780 | static void |
754 | confirm_handler (void *cls, const struct GNUNET_MessageHeader *msg) | 781 | confirm_handler (void *cls, |
782 | const struct GNUNET_MessageHeader *msg) | ||
755 | { | 783 | { |
756 | struct GNUNET_CLIENT_TestHandle *th = cls; | 784 | struct GNUNET_CLIENT_TestHandle *th = cls; |
757 | 785 | ||
@@ -1036,7 +1064,7 @@ GNUNET_CLIENT_service_test (const char *service, | |||
1036 | * @param cls our `struct GNUNET_CLIENT_TransmissionHandle` | 1064 | * @param cls our `struct GNUNET_CLIENT_TransmissionHandle` |
1037 | * @param size number of bytes available for transmission | 1065 | * @param size number of bytes available for transmission |
1038 | * @param buf where to write them | 1066 | * @param buf where to write them |
1039 | * @return number of bytes written to buf | 1067 | * @return number of bytes written to @a buf |
1040 | */ | 1068 | */ |
1041 | static size_t | 1069 | static size_t |
1042 | client_notify (void *cls, size_t size, void *buf); | 1070 | client_notify (void *cls, size_t size, void *buf); |
@@ -1111,7 +1139,9 @@ client_delayed_retry (void *cls, | |||
1111 | * @return number of bytes written to @a buf | 1139 | * @return number of bytes written to @a buf |
1112 | */ | 1140 | */ |
1113 | static size_t | 1141 | static size_t |
1114 | client_notify (void *cls, size_t size, void *buf) | 1142 | client_notify (void *cls, |
1143 | size_t size, | ||
1144 | void *buf) | ||
1115 | { | 1145 | { |
1116 | struct GNUNET_CLIENT_TransmitHandle *th = cls; | 1146 | struct GNUNET_CLIENT_TransmitHandle *th = cls; |
1117 | struct GNUNET_CLIENT_Connection *client = th->client; | 1147 | struct GNUNET_CLIENT_Connection *client = th->client; |
@@ -1126,14 +1156,16 @@ client_notify (void *cls, size_t size, void *buf) | |||
1126 | { | 1156 | { |
1127 | delay = GNUNET_TIME_absolute_get_remaining (th->timeout); | 1157 | delay = GNUNET_TIME_absolute_get_remaining (th->timeout); |
1128 | delay.rel_value_us /= 2; | 1158 | delay.rel_value_us /= 2; |
1129 | if ((GNUNET_YES != th->auto_retry) || (0 == --th->attempts_left) || | 1159 | if ( (GNUNET_YES != th->auto_retry) || |
1130 | (delay.rel_value_us < 1)|| | 1160 | (0 == --th->attempts_left) || |
1131 | (0 != (GNUNET_SCHEDULER_get_reason() & GNUNET_SCHEDULER_REASON_SHUTDOWN))) | 1161 | (delay.rel_value_us < 1)|| |
1162 | (0 != (GNUNET_SCHEDULER_get_reason() & GNUNET_SCHEDULER_REASON_SHUTDOWN))) | ||
1132 | { | 1163 | { |
1133 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1164 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1134 | "Transmission failed %u times, giving up.\n", | 1165 | "Transmission failed %u times, giving up.\n", |
1135 | MAX_ATTEMPTS - th->attempts_left); | 1166 | MAX_ATTEMPTS - th->attempts_left); |
1136 | GNUNET_break (0 == th->notify (th->notify_cls, 0, NULL)); | 1167 | GNUNET_break (0 == |
1168 | th->notify (th->notify_cls, 0, NULL)); | ||
1137 | GNUNET_free (th); | 1169 | GNUNET_free (th); |
1138 | return 0; | 1170 | return 0; |
1139 | } | 1171 | } |
@@ -1232,13 +1264,14 @@ GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *client, | |||
1232 | GNUNET_SCHEDULER_add_delayed (client->back_off, | 1264 | GNUNET_SCHEDULER_add_delayed (client->back_off, |
1233 | &client_delayed_retry, | 1265 | &client_delayed_retry, |
1234 | th); | 1266 | th); |
1235 | |||
1236 | } | 1267 | } |
1237 | else | 1268 | else |
1238 | { | 1269 | { |
1239 | th->th = | 1270 | th->th = GNUNET_CONNECTION_notify_transmit_ready (client->connection, |
1240 | GNUNET_CONNECTION_notify_transmit_ready (client->connection, size, timeout, | 1271 | size, |
1241 | &client_notify, th); | 1272 | timeout, |
1273 | &client_notify, | ||
1274 | th); | ||
1242 | if (NULL == th->th) | 1275 | if (NULL == th->th) |
1243 | { | 1276 | { |
1244 | GNUNET_break (0); | 1277 | GNUNET_break (0); |
@@ -1281,7 +1314,7 @@ GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle | |||
1281 | * NULL and @a size zero if the socket was closed for | 1314 | * NULL and @a size zero if the socket was closed for |
1282 | * writing in the meantime. | 1315 | * writing in the meantime. |
1283 | * | 1316 | * |
1284 | * @param cls closure of type "struct TransmitGetResponseContext*" | 1317 | * @param cls closure of type `struct TransmitGetResponseContext *` |
1285 | * @param size number of bytes available in @a buf | 1318 | * @param size number of bytes available in @a buf |
1286 | * @param buf where the callee should write the message | 1319 | * @param buf where the callee should write the message |
1287 | * @return number of bytes written to @a buf | 1320 | * @return number of bytes written to @a buf |
@@ -1299,7 +1332,7 @@ transmit_for_response (void *cls, | |||
1299 | if (NULL == buf) | 1332 | if (NULL == buf) |
1300 | { | 1333 | { |
1301 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1334 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1302 | _("Could not submit request, not expecting to receive a response.\n")); | 1335 | "Could not submit request, not expecting to receive a response.\n"); |
1303 | if (NULL != tc->rn) | 1336 | if (NULL != tc->rn) |
1304 | tc->rn (tc->rn_cls, NULL); | 1337 | tc->rn (tc->rn_cls, NULL); |
1305 | GNUNET_free (tc); | 1338 | GNUNET_free (tc); |
@@ -1307,7 +1340,9 @@ transmit_for_response (void *cls, | |||
1307 | } | 1340 | } |
1308 | GNUNET_assert (size >= msize); | 1341 | GNUNET_assert (size >= msize); |
1309 | memcpy (buf, tc->hdr, msize); | 1342 | memcpy (buf, tc->hdr, msize); |
1310 | GNUNET_CLIENT_receive (tc->client, tc->rn, tc->rn_cls, | 1343 | GNUNET_CLIENT_receive (tc->client, |
1344 | tc->rn, | ||
1345 | tc->rn_cls, | ||
1311 | GNUNET_TIME_absolute_get_remaining (tc->timeout)); | 1346 | GNUNET_TIME_absolute_get_remaining (tc->timeout)); |
1312 | GNUNET_free (tc); | 1347 | GNUNET_free (tc); |
1313 | return msize; | 1348 | return msize; |
diff --git a/src/util/connection.c b/src/util/connection.c index 8fe136b02..b600baa12 100644 --- a/src/util/connection.c +++ b/src/util/connection.c | |||
@@ -469,7 +469,8 @@ GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *connection, | |||
469 | * @param errcode error code to send | 469 | * @param errcode error code to send |
470 | */ | 470 | */ |
471 | static void | 471 | static void |
472 | signal_receive_error (struct GNUNET_CONNECTION_Handle *connection, int errcode) | 472 | signal_receive_error (struct GNUNET_CONNECTION_Handle *connection, |
473 | int errcode) | ||
473 | { | 474 | { |
474 | GNUNET_CONNECTION_Receiver receiver; | 475 | GNUNET_CONNECTION_Receiver receiver; |
475 | 476 | ||
@@ -479,7 +480,12 @@ signal_receive_error (struct GNUNET_CONNECTION_Handle *connection, int errcode) | |||
479 | connection); | 480 | connection); |
480 | GNUNET_assert (NULL != (receiver = connection->receiver)); | 481 | GNUNET_assert (NULL != (receiver = connection->receiver)); |
481 | connection->receiver = NULL; | 482 | connection->receiver = NULL; |
482 | receiver (connection->receiver_cls, NULL, 0, connection->addr, connection->addrlen, errcode); | 483 | receiver (connection->receiver_cls, |
484 | NULL, | ||
485 | 0, | ||
486 | connection->addr, | ||
487 | connection->addrlen, | ||
488 | errcode); | ||
483 | } | 489 | } |
484 | 490 | ||
485 | 491 | ||
@@ -519,8 +525,9 @@ signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection, | |||
519 | connection); | 525 | connection); |
520 | if (NULL != connection->sock) | 526 | if (NULL != connection->sock) |
521 | { | 527 | { |
522 | GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR); | 528 | (void) GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR); |
523 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock)); | 529 | GNUNET_break (GNUNET_OK == |
530 | GNUNET_NETWORK_socket_close (connection->sock)); | ||
524 | connection->sock = NULL; | 531 | connection->sock = NULL; |
525 | GNUNET_assert (NULL == connection->write_task); | 532 | GNUNET_assert (NULL == connection->write_task); |
526 | } | 533 | } |
@@ -561,13 +568,15 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *connection) | |||
561 | /* signal errors for jobs that used to wait on the connection */ | 568 | /* signal errors for jobs that used to wait on the connection */ |
562 | connection->destroy_later = 1; | 569 | connection->destroy_later = 1; |
563 | if (NULL != connection->receiver) | 570 | if (NULL != connection->receiver) |
564 | signal_receive_error (connection, ECONNREFUSED); | 571 | signal_receive_error (connection, |
572 | ECONNREFUSED); | ||
565 | if (NULL != connection->nth.notify_ready) | 573 | if (NULL != connection->nth.notify_ready) |
566 | { | 574 | { |
567 | GNUNET_assert (connection->nth.timeout_task != NULL); | 575 | GNUNET_assert (NULL != connection->nth.timeout_task); |
568 | GNUNET_SCHEDULER_cancel (connection->nth.timeout_task); | 576 | GNUNET_SCHEDULER_cancel (connection->nth.timeout_task); |
569 | connection->nth.timeout_task = NULL; | 577 | connection->nth.timeout_task = NULL; |
570 | signal_transmit_error (connection, ECONNREFUSED); | 578 | signal_transmit_error (connection, |
579 | ECONNREFUSED); | ||
571 | } | 580 | } |
572 | if (-1 == connection->destroy_later) | 581 | if (-1 == connection->destroy_later) |
573 | { | 582 | { |
@@ -979,7 +988,9 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection) | |||
979 | connection->destroy_later = -1; | 988 | connection->destroy_later = -1; |
980 | return; | 989 | return; |
981 | } | 990 | } |
982 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down connection (%p)\n", connection); | 991 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
992 | "Shutting down connection (%p)\n", | ||
993 | connection); | ||
983 | GNUNET_assert (NULL == connection->nth.notify_ready); | 994 | GNUNET_assert (NULL == connection->nth.notify_ready); |
984 | GNUNET_assert (NULL == connection->receiver); | 995 | GNUNET_assert (NULL == connection->receiver); |
985 | if (NULL != connection->write_task) | 996 | if (NULL != connection->write_task) |
@@ -1014,15 +1025,21 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection) | |||
1014 | if ( (NULL != connection->sock) && | 1025 | if ( (NULL != connection->sock) && |
1015 | (GNUNET_YES != connection->persist) ) | 1026 | (GNUNET_YES != connection->persist) ) |
1016 | { | 1027 | { |
1017 | if ((GNUNET_YES != GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR)) && | 1028 | if ((GNUNET_OK != |
1029 | GNUNET_NETWORK_socket_shutdown (connection->sock, | ||
1030 | SHUT_RDWR)) && | ||
1018 | (ENOTCONN != errno) && | 1031 | (ENOTCONN != errno) && |
1019 | (ECONNRESET != errno) ) | 1032 | (ECONNRESET != errno) ) |
1020 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown"); | 1033 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, |
1034 | "shutdown"); | ||
1021 | } | 1035 | } |
1022 | if (NULL != connection->sock) | 1036 | if (NULL != connection->sock) |
1023 | { | 1037 | { |
1024 | if (GNUNET_YES != connection->persist) | 1038 | if (GNUNET_YES != connection->persist) |
1025 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock)); | 1039 | { |
1040 | GNUNET_break (GNUNET_OK == | ||
1041 | GNUNET_NETWORK_socket_close (connection->sock)); | ||
1042 | } | ||
1026 | else | 1043 | else |
1027 | { | 1044 | { |
1028 | GNUNET_NETWORK_socket_free_memory_only_ (connection->sock); /* at least no memory leak (we deliberately | 1045 | GNUNET_NETWORK_socket_free_memory_only_ (connection->sock); /* at least no memory leak (we deliberately |
@@ -1079,7 +1096,9 @@ receive_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1079 | } | 1096 | } |
1080 | GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, connection->sock)); | 1097 | GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, connection->sock)); |
1081 | RETRY: | 1098 | RETRY: |
1082 | ret = GNUNET_NETWORK_socket_recv (connection->sock, buffer, connection->max); | 1099 | ret = GNUNET_NETWORK_socket_recv (connection->sock, |
1100 | buffer, | ||
1101 | connection->max); | ||
1083 | if (-1 == ret) | 1102 | if (-1 == ret) |
1084 | { | 1103 | { |
1085 | if (EINTR == errno) | 1104 | if (EINTR == errno) |
@@ -1088,11 +1107,20 @@ RETRY: | |||
1088 | return; | 1107 | return; |
1089 | } | 1108 | } |
1090 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1109 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1091 | "receive_ready read %u/%u bytes from `%s' (%p)!\n", (unsigned int) ret, | 1110 | "receive_ready read %u/%u bytes from `%s' (%p)!\n", |
1092 | connection->max, GNUNET_a2s (connection->addr, connection->addrlen), connection); | 1111 | (unsigned int) ret, |
1112 | connection->max, | ||
1113 | GNUNET_a2s (connection->addr, | ||
1114 | connection->addrlen), | ||
1115 | connection); | ||
1093 | GNUNET_assert (NULL != (receiver = connection->receiver)); | 1116 | GNUNET_assert (NULL != (receiver = connection->receiver)); |
1094 | connection->receiver = NULL; | 1117 | connection->receiver = NULL; |
1095 | receiver (connection->receiver_cls, buffer, ret, connection->addr, connection->addrlen, 0); | 1118 | receiver (connection->receiver_cls, |
1119 | buffer, | ||
1120 | ret, | ||
1121 | connection->addr, | ||
1122 | connection->addrlen, | ||
1123 | 0); | ||
1096 | } | 1124 | } |
1097 | 1125 | ||
1098 | 1126 | ||
@@ -1398,7 +1426,7 @@ SCHEDULE_WRITE: | |||
1398 | * @param timeout after how long should we give up (and call | 1426 | * @param timeout after how long should we give up (and call |
1399 | * notify with buf NULL and size 0)? | 1427 | * notify with buf NULL and size 0)? |
1400 | * @param notify function to call | 1428 | * @param notify function to call |
1401 | * @param notify_cls closure for notify | 1429 | * @param notify_cls closure for @a notify |
1402 | * @return non-NULL if the notify callback was queued, | 1430 | * @return non-NULL if the notify callback was queued, |
1403 | * NULL if we are already going to notify someone else (busy) | 1431 | * NULL if we are already going to notify someone else (busy) |
1404 | */ | 1432 | */ |
@@ -1431,7 +1459,8 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec | |||
1431 | { | 1459 | { |
1432 | if (NULL != connection->write_task) | 1460 | if (NULL != connection->write_task) |
1433 | GNUNET_SCHEDULER_cancel (connection->write_task); | 1461 | GNUNET_SCHEDULER_cancel (connection->write_task); |
1434 | connection->write_task = GNUNET_SCHEDULER_add_now (&connect_error, connection); | 1462 | connection->write_task = GNUNET_SCHEDULER_add_now (&connect_error, |
1463 | connection); | ||
1435 | return &connection->nth; | 1464 | return &connection->nth; |
1436 | } | 1465 | } |
1437 | if (NULL != connection->write_task) | 1466 | if (NULL != connection->write_task) |
@@ -1439,7 +1468,9 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec | |||
1439 | if (NULL != connection->sock) | 1468 | if (NULL != connection->sock) |
1440 | { | 1469 | { |
1441 | /* connected, try to transmit now */ | 1470 | /* connected, try to transmit now */ |
1442 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduling transmission (%p).\n", connection); | 1471 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1472 | "Scheduling transmission (%p).\n", | ||
1473 | connection); | ||
1443 | connection->write_task = | 1474 | connection->write_task = |
1444 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining | 1475 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining |
1445 | (connection->nth.transmit_timeout), | 1476 | (connection->nth.transmit_timeout), |
@@ -1448,9 +1479,11 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec | |||
1448 | } | 1479 | } |
1449 | /* not yet connected, wait for connection */ | 1480 | /* not yet connected, wait for connection */ |
1450 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1481 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1451 | "Need to wait to schedule transmission for connection, adding timeout task (%p).\n", connection); | 1482 | "Need to wait to schedule transmission for connection, adding timeout task (%p).\n", |
1483 | connection); | ||
1452 | connection->nth.timeout_task = | 1484 | connection->nth.timeout_task = |
1453 | GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, connection); | 1485 | GNUNET_SCHEDULER_add_delayed (timeout, |
1486 | &transmit_timeout, connection); | ||
1454 | return &connection->nth; | 1487 | return &connection->nth; |
1455 | } | 1488 | } |
1456 | 1489 | ||
diff --git a/src/util/network.c b/src/util/network.c index dfc76f27f..22e77818d 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -973,10 +973,10 @@ GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, | |||
973 | 973 | ||
974 | ret = shutdown (desc->fd, how); | 974 | ret = shutdown (desc->fd, how); |
975 | #ifdef MINGW | 975 | #ifdef MINGW |
976 | if (ret != 0) | 976 | if (0 != ret) |
977 | SetErrnoFromWinsockError (WSAGetLastError ()); | 977 | SetErrnoFromWinsockError (WSAGetLastError ()); |
978 | #endif | 978 | #endif |
979 | return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; | 979 | return (0 == ret) ? GNUNET_OK : GNUNET_SYSERR; |
980 | } | 980 | } |
981 | 981 | ||
982 | 982 | ||
diff --git a/src/util/server.c b/src/util/server.c index d05df089f..279b65792 100644 --- a/src/util/server.c +++ b/src/util/server.c | |||
@@ -479,10 +479,13 @@ open_listen_socket (const struct sockaddr *server_addr, socklen_t socklen) | |||
479 | * fail if we already took the port on IPv6; if both IPv4 and | 479 | * fail if we already took the port on IPv6; if both IPv4 and |
480 | * IPv6 binds fail, then our caller will log using the | 480 | * IPv6 binds fail, then our caller will log using the |
481 | * errno preserved in 'eno' */ | 481 | * errno preserved in 'eno' */ |
482 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind"); | 482 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, |
483 | "bind"); | ||
483 | if (0 != port) | 484 | if (0 != port) |
484 | LOG (GNUNET_ERROR_TYPE_ERROR, _("`%s' failed for port %d (%s).\n"), | 485 | LOG (GNUNET_ERROR_TYPE_ERROR, |
485 | "bind", port, | 486 | _("`%s' failed for port %d (%s).\n"), |
487 | "bind", | ||
488 | port, | ||
486 | (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6"); | 489 | (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6"); |
487 | eno = 0; | 490 | eno = 0; |
488 | } | 491 | } |
@@ -507,13 +510,15 @@ open_listen_socket (const struct sockaddr *server_addr, socklen_t socklen) | |||
507 | } | 510 | } |
508 | if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5)) | 511 | if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5)) |
509 | { | 512 | { |
510 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "listen"); | 513 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, |
514 | "listen"); | ||
511 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); | 515 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); |
512 | errno = 0; | 516 | errno = 0; |
513 | return NULL; | 517 | return NULL; |
514 | } | 518 | } |
515 | if (0 != port) | 519 | if (0 != port) |
516 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Server starts to listen on port %u.\n", | 520 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
521 | "Server starts to listen on port %u.\n", | ||
517 | port); | 522 | port); |
518 | return sock; | 523 | return sock; |
519 | } | 524 | } |
@@ -620,7 +625,7 @@ GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access_cb, | |||
620 | { | 625 | { |
621 | lsocks = NULL; | 626 | lsocks = NULL; |
622 | } | 627 | } |
623 | return GNUNET_SERVER_create_with_sockets (access_cb, | 628 | return GNUNET_SERVER_create_with_sockets (access_cb, |
624 | access_cb_cls, | 629 | access_cb_cls, |
625 | lsocks, | 630 | lsocks, |
626 | idle_timeout, | 631 | idle_timeout, |
@@ -1040,7 +1045,8 @@ process_incoming (void *cls, | |||
1040 | * #GNUNET_SYSERR if we should instantly abort due to error in a previous step | 1045 | * #GNUNET_SYSERR if we should instantly abort due to error in a previous step |
1041 | */ | 1046 | */ |
1042 | static void | 1047 | static void |
1043 | process_mst (struct GNUNET_SERVER_Client *client, int ret) | 1048 | process_mst (struct GNUNET_SERVER_Client *client, |
1049 | int ret) | ||
1044 | { | 1050 | { |
1045 | while ((GNUNET_SYSERR != ret) && (NULL != client->server) && | 1051 | while ((GNUNET_SYSERR != ret) && (NULL != client->server) && |
1046 | (GNUNET_YES != client->shutdown_now) && (0 == client->suspended)) | 1052 | (GNUNET_YES != client->shutdown_now) && (0 == client->suspended)) |
@@ -1053,7 +1059,8 @@ process_mst (struct GNUNET_SERVER_Client *client, int ret) | |||
1053 | client->receive_pending = GNUNET_YES; | 1059 | client->receive_pending = GNUNET_YES; |
1054 | GNUNET_CONNECTION_receive (client->connection, | 1060 | GNUNET_CONNECTION_receive (client->connection, |
1055 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, | 1061 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, |
1056 | client->idle_timeout, &process_incoming, | 1062 | client->idle_timeout, |
1063 | &process_incoming, | ||
1057 | client); | 1064 | client); |
1058 | break; | 1065 | break; |
1059 | } | 1066 | } |
@@ -1092,12 +1099,16 @@ process_mst (struct GNUNET_SERVER_Client *client, int ret) | |||
1092 | * @param buf buffer with data received from network | 1099 | * @param buf buffer with data received from network |
1093 | * @param available number of bytes available in buf | 1100 | * @param available number of bytes available in buf |
1094 | * @param addr address of the sender | 1101 | * @param addr address of the sender |
1095 | * @param addrlen length of addr | 1102 | * @param addrlen length of @a addr |
1096 | * @param errCode code indicating errors receiving, 0 for success | 1103 | * @param errCode code indicating errors receiving, 0 for success |
1097 | */ | 1104 | */ |
1098 | static void | 1105 | static void |
1099 | process_incoming (void *cls, const void *buf, size_t available, | 1106 | process_incoming (void *cls, |
1100 | const struct sockaddr *addr, socklen_t addrlen, int errCode) | 1107 | const void *buf, |
1108 | size_t available, | ||
1109 | const struct sockaddr *addr, | ||
1110 | socklen_t addrlen, | ||
1111 | int errCode) | ||
1101 | { | 1112 | { |
1102 | struct GNUNET_SERVER_Client *client = cls; | 1113 | struct GNUNET_SERVER_Client *client = cls; |
1103 | struct GNUNET_SERVER_Handle *server = client->server; | 1114 | struct GNUNET_SERVER_Handle *server = client->server; |
@@ -1108,17 +1119,22 @@ process_incoming (void *cls, const void *buf, size_t available, | |||
1108 | GNUNET_assert (GNUNET_YES == client->receive_pending); | 1119 | GNUNET_assert (GNUNET_YES == client->receive_pending); |
1109 | client->receive_pending = GNUNET_NO; | 1120 | client->receive_pending = GNUNET_NO; |
1110 | now = GNUNET_TIME_absolute_get (); | 1121 | now = GNUNET_TIME_absolute_get (); |
1111 | end = GNUNET_TIME_absolute_add (client->last_activity, client->idle_timeout); | 1122 | end = GNUNET_TIME_absolute_add (client->last_activity, |
1112 | 1123 | client->idle_timeout); | |
1113 | if ((NULL == buf) && (0 == available) && (NULL == addr) && (0 == errCode) && | 1124 | |
1114 | (GNUNET_YES != client->shutdown_now) && (NULL != server) && | 1125 | if ( (NULL == buf) && |
1115 | (GNUNET_YES == GNUNET_CONNECTION_check (client->connection)) && | 1126 | (0 == available) && |
1116 | (end.abs_value_us > now.abs_value_us)) | 1127 | (NULL == addr) && |
1128 | (0 == errCode) && | ||
1129 | (GNUNET_YES != client->shutdown_now) && | ||
1130 | (NULL != server) && | ||
1131 | (GNUNET_YES == GNUNET_CONNECTION_check (client->connection)) && | ||
1132 | (end.abs_value_us > now.abs_value_us) ) | ||
1117 | { | 1133 | { |
1118 | /* wait longer, timeout changed (i.e. due to us sending) */ | 1134 | /* wait longer, timeout changed (i.e. due to us sending) */ |
1119 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1135 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1120 | "Receive time out, but no disconnect due to sending (%p)\n", | 1136 | "Receive time out, but no disconnect due to sending (%p)\n", |
1121 | GNUNET_a2s (addr, addrlen)); | 1137 | client); |
1122 | client->receive_pending = GNUNET_YES; | 1138 | client->receive_pending = GNUNET_YES; |
1123 | GNUNET_CONNECTION_receive (client->connection, | 1139 | GNUNET_CONNECTION_receive (client->connection, |
1124 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, | 1140 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, |
@@ -1126,27 +1142,45 @@ process_incoming (void *cls, const void *buf, size_t available, | |||
1126 | &process_incoming, client); | 1142 | &process_incoming, client); |
1127 | return; | 1143 | return; |
1128 | } | 1144 | } |
1129 | if ((NULL == buf) || (0 == available) || (0 != errCode) || (NULL == server) || | 1145 | if ( (NULL == buf) || |
1130 | (GNUNET_YES == client->shutdown_now) || | 1146 | (0 == available) || |
1131 | (GNUNET_YES != GNUNET_CONNECTION_check (client->connection))) | 1147 | (0 != errCode) || |
1148 | (NULL == server) || | ||
1149 | (GNUNET_YES == client->shutdown_now) || | ||
1150 | (GNUNET_YES != GNUNET_CONNECTION_check (client->connection)) ) | ||
1132 | { | 1151 | { |
1133 | /* other side closed connection, error connecting, etc. */ | 1152 | /* other side closed connection, error connecting, etc. */ |
1153 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1154 | "Failed to connect or other side closed connection (%p)\n", | ||
1155 | client); | ||
1134 | GNUNET_SERVER_client_disconnect (client); | 1156 | GNUNET_SERVER_client_disconnect (client); |
1135 | return; | 1157 | return; |
1136 | } | 1158 | } |
1137 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Server receives %u bytes from `%s'.\n", | 1159 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1138 | (unsigned int) available, GNUNET_a2s (addr, addrlen)); | 1160 | "Server receives %u bytes from `%s'.\n", |
1161 | (unsigned int) available, | ||
1162 | GNUNET_a2s (addr, addrlen)); | ||
1139 | GNUNET_SERVER_client_keep (client); | 1163 | GNUNET_SERVER_client_keep (client); |
1140 | client->last_activity = now; | 1164 | client->last_activity = now; |
1141 | 1165 | ||
1142 | if (NULL != server->mst_receive) | 1166 | if (NULL != server->mst_receive) |
1143 | ret = | 1167 | { |
1144 | client->server->mst_receive (client->server->mst_cls, client->mst, | 1168 | ret = client->server->mst_receive (client->server->mst_cls, |
1145 | client, buf, available, GNUNET_NO, GNUNET_YES); | 1169 | client->mst, |
1170 | client, | ||
1171 | buf, | ||
1172 | available, | ||
1173 | GNUNET_NO, | ||
1174 | GNUNET_YES); | ||
1175 | } | ||
1146 | else if (NULL != client->mst) | 1176 | else if (NULL != client->mst) |
1147 | { | 1177 | { |
1148 | ret = | 1178 | ret = |
1149 | GNUNET_SERVER_mst_receive (client->mst, client, buf, available, GNUNET_NO, | 1179 | GNUNET_SERVER_mst_receive (client->mst, |
1180 | client, | ||
1181 | buf, | ||
1182 | available, | ||
1183 | GNUNET_NO, | ||
1150 | GNUNET_YES); | 1184 | GNUNET_YES); |
1151 | } | 1185 | } |
1152 | else | 1186 | else |
@@ -1154,8 +1188,8 @@ process_incoming (void *cls, const void *buf, size_t available, | |||
1154 | GNUNET_break (0); | 1188 | GNUNET_break (0); |
1155 | return; | 1189 | return; |
1156 | } | 1190 | } |
1157 | 1191 | process_mst (client, | |
1158 | process_mst (client, ret); | 1192 | ret); |
1159 | GNUNET_SERVER_client_drop (client); | 1193 | GNUNET_SERVER_client_drop (client); |
1160 | } | 1194 | } |
1161 | 1195 | ||
@@ -1164,11 +1198,12 @@ process_incoming (void *cls, const void *buf, size_t available, | |||
1164 | * Task run to start again receiving from the network | 1198 | * Task run to start again receiving from the network |
1165 | * and process requests. | 1199 | * and process requests. |
1166 | * | 1200 | * |
1167 | * @param cls our 'struct GNUNET_SERVER_Client*' to process more requests from | 1201 | * @param cls our `struct GNUNET_SERVER_Client *` to process more requests from |
1168 | * @param tc scheduler context (unused) | 1202 | * @param tc scheduler context (unused) |
1169 | */ | 1203 | */ |
1170 | static void | 1204 | static void |
1171 | restart_processing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1205 | restart_processing (void *cls, |
1206 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1172 | { | 1207 | { |
1173 | struct GNUNET_SERVER_Client *client = cls; | 1208 | struct GNUNET_SERVER_Client *client = cls; |
1174 | 1209 | ||
@@ -1180,14 +1215,17 @@ restart_processing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1180 | client->receive_pending = GNUNET_YES; | 1215 | client->receive_pending = GNUNET_YES; |
1181 | GNUNET_CONNECTION_receive (client->connection, | 1216 | GNUNET_CONNECTION_receive (client->connection, |
1182 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, | 1217 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, |
1183 | client->idle_timeout, &process_incoming, client); | 1218 | client->idle_timeout, |
1219 | &process_incoming, | ||
1220 | client); | ||
1184 | return; | 1221 | return; |
1185 | } | 1222 | } |
1186 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1223 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1187 | "Server continues processing messages still in the buffer.\n"); | 1224 | "Server continues processing messages still in the buffer.\n"); |
1188 | GNUNET_SERVER_client_keep (client); | 1225 | GNUNET_SERVER_client_keep (client); |
1189 | client->receive_pending = GNUNET_NO; | 1226 | client->receive_pending = GNUNET_NO; |
1190 | process_mst (client, GNUNET_NO); | 1227 | process_mst (client, |
1228 | GNUNET_NO); | ||
1191 | GNUNET_SERVER_client_drop (client); | 1229 | GNUNET_SERVER_client_drop (client); |
1192 | } | 1230 | } |
1193 | 1231 | ||
@@ -1258,15 +1296,17 @@ GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server, | |||
1258 | server->mst_create (server->mst_cls, client); | 1296 | server->mst_create (server->mst_cls, client); |
1259 | else | 1297 | else |
1260 | client->mst = | 1298 | client->mst = |
1261 | GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, server); | 1299 | GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, |
1300 | server); | ||
1262 | GNUNET_assert (NULL != client->mst); | 1301 | GNUNET_assert (NULL != client->mst); |
1263 | for (n = server->connect_notify_list_head; NULL != n; n = n->next) | 1302 | for (n = server->connect_notify_list_head; NULL != n; n = n->next) |
1264 | n->callback (n->callback_cls, client); | 1303 | n->callback (n->callback_cls, client); |
1265 | |||
1266 | client->receive_pending = GNUNET_YES; | 1304 | client->receive_pending = GNUNET_YES; |
1267 | GNUNET_CONNECTION_receive (client->connection, | 1305 | GNUNET_CONNECTION_receive (client->connection, |
1268 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, | 1306 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, |
1269 | client->idle_timeout, &process_incoming, client); | 1307 | client->idle_timeout, |
1308 | &process_incoming, | ||
1309 | client); | ||
1270 | return client; | 1310 | return client; |
1271 | } | 1311 | } |
1272 | 1312 | ||
@@ -1572,7 +1612,7 @@ GNUNET_SERVER_client_disable_corking (struct GNUNET_SERVER_Client *client) | |||
1572 | * Wrapper for transmission notification that calls the original | 1612 | * Wrapper for transmission notification that calls the original |
1573 | * callback and update the last activity time for our connection. | 1613 | * callback and update the last activity time for our connection. |
1574 | * | 1614 | * |
1575 | * @param cls the `struct GNUNET_SERVER_Client` | 1615 | * @param cls the `struct GNUNET_SERVER_Client *` |
1576 | * @param size number of bytes we can transmit | 1616 | * @param size number of bytes we can transmit |
1577 | * @param buf where to copy the message | 1617 | * @param buf where to copy the message |
1578 | * @return number of bytes actually transmitted | 1618 | * @return number of bytes actually transmitted |