diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-28 14:12:31 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-28 14:12:31 +0000 |
commit | 37079402ef1ba6e9a78d878d8d321e4d67c492ae (patch) | |
tree | a552ca29690e8d13f58ccfada2a0eedffb3e4783 /src/util/connection.c | |
parent | bb6cb0741b947c83113b8d89797e6718dcf5391a (diff) | |
download | gnunet-37079402ef1ba6e9a78d878d8d321e4d67c492ae.tar.gz gnunet-37079402ef1ba6e9a78d878d8d321e4d67c492ae.zip |
-doxygen, i18n and indentation
Diffstat (limited to 'src/util/connection.c')
-rw-r--r-- | src/util/connection.c | 106 |
1 files changed, 61 insertions, 45 deletions
diff --git a/src/util/connection.c b/src/util/connection.c index f6dab2bc4..8560f52af 100644 --- a/src/util/connection.c +++ b/src/util/connection.c | |||
@@ -170,7 +170,7 @@ struct GNUNET_CONNECTION_Handle | |||
170 | GNUNET_CONNECTION_Receiver receiver; | 170 | GNUNET_CONNECTION_Receiver receiver; |
171 | 171 | ||
172 | /** | 172 | /** |
173 | * Closure for receiver. | 173 | * Closure for @e receiver. |
174 | */ | 174 | */ |
175 | void *receiver_cls; | 175 | void *receiver_cls; |
176 | 176 | ||
@@ -180,24 +180,24 @@ struct GNUNET_CONNECTION_Handle | |||
180 | char *write_buffer; | 180 | char *write_buffer; |
181 | 181 | ||
182 | /** | 182 | /** |
183 | * Current size of our write buffer. | 183 | * Current size of our @e write_buffer. |
184 | */ | 184 | */ |
185 | size_t write_buffer_size; | 185 | size_t write_buffer_size; |
186 | 186 | ||
187 | /** | 187 | /** |
188 | * Current write-offset in write buffer (where | 188 | * Current write-offset in @e write_buffer (where |
189 | * would we write next). | 189 | * would we write next). |
190 | */ | 190 | */ |
191 | size_t write_buffer_off; | 191 | size_t write_buffer_off; |
192 | 192 | ||
193 | /** | 193 | /** |
194 | * Current read-offset in write buffer (how many | 194 | * Current read-offset in @e write_buffer (how many |
195 | * bytes have already been sent). | 195 | * bytes have already been sent). |
196 | */ | 196 | */ |
197 | size_t write_buffer_pos; | 197 | size_t write_buffer_pos; |
198 | 198 | ||
199 | /** | 199 | /** |
200 | * Length of addr. | 200 | * Length of @e addr. |
201 | */ | 201 | */ |
202 | socklen_t addrlen; | 202 | socklen_t addrlen; |
203 | 203 | ||
@@ -246,7 +246,7 @@ struct GNUNET_CONNECTION_Handle | |||
246 | 246 | ||
247 | /** | 247 | /** |
248 | * Usually 0. Set to 1 if this handle is in used and should | 248 | * Usually 0. Set to 1 if this handle is in used and should |
249 | * 'GNUNET_CONNECTION_destroy' be called right now, the action needs | 249 | * #GNUNET_CONNECTION_destroy() be called right now, the action needs |
250 | * to be deferred by setting it to -1. | 250 | * to be deferred by setting it to -1. |
251 | */ | 251 | */ |
252 | int8_t destroy_later; | 252 | int8_t destroy_later; |
@@ -277,7 +277,7 @@ GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *connection) | |||
277 | * reach the other side before the process is terminated. | 277 | * reach the other side before the process is terminated. |
278 | * | 278 | * |
279 | * @param connection the connection to make flushing and blocking | 279 | * @param connection the connection to make flushing and blocking |
280 | * @return GNUNET_OK on success | 280 | * @return #GNUNET_OK on success |
281 | */ | 281 | */ |
282 | int | 282 | int |
283 | GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *connection) | 283 | GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *connection) |
@@ -289,7 +289,7 @@ GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *connection) | |||
289 | /** | 289 | /** |
290 | * Create a connection handle by boxing an existing OS socket. The OS | 290 | * Create a connection handle by boxing an existing OS socket. The OS |
291 | * socket should henceforth be no longer used directly. | 291 | * socket should henceforth be no longer used directly. |
292 | * GNUNET_connection_destroy will close it. | 292 | * #GNUNET_connection_destroy() will close it. |
293 | * | 293 | * |
294 | * @param osSocket existing socket to box | 294 | * @param osSocket existing socket to box |
295 | * @return the boxed connection handle | 295 | * @return the boxed connection handle |
@@ -448,12 +448,13 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
448 | * | 448 | * |
449 | * @param connection the client to get the address for | 449 | * @param connection the client to get the address for |
450 | * @param addr where to store the address | 450 | * @param addr where to store the address |
451 | * @param addrlen where to store the length of the address | 451 | * @param addrlen where to store the length of the @a addr |
452 | * @return GNUNET_OK on success | 452 | * @return #GNUNET_OK on success |
453 | */ | 453 | */ |
454 | int | 454 | int |
455 | GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *connection, | 455 | GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *connection, |
456 | void **addr, size_t * addrlen) | 456 | void **addr, |
457 | size_t *addrlen) | ||
457 | { | 458 | { |
458 | if ((NULL == connection->addr) || (0 == connection->addrlen)) | 459 | if ((NULL == connection->addr) || (0 == connection->addrlen)) |
459 | return GNUNET_NO; | 460 | return GNUNET_NO; |
@@ -501,7 +502,8 @@ signal_receive_timeout (struct GNUNET_CONNECTION_Handle *connection) | |||
501 | { | 502 | { |
502 | GNUNET_CONNECTION_Receiver receiver; | 503 | GNUNET_CONNECTION_Receiver receiver; |
503 | 504 | ||
504 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connection signals timeout to receiver (%p)!\n", | 505 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
506 | "Connection signals timeout to receiver (%p)!\n", | ||
505 | connection); | 507 | connection); |
506 | GNUNET_assert (NULL != (receiver = connection->receiver)); | 508 | GNUNET_assert (NULL != (receiver = connection->receiver)); |
507 | connection->receiver = NULL; | 509 | connection->receiver = NULL; |
@@ -560,8 +562,9 @@ static void | |||
560 | connect_fail_continuation (struct GNUNET_CONNECTION_Handle *connection) | 562 | connect_fail_continuation (struct GNUNET_CONNECTION_Handle *connection) |
561 | { | 563 | { |
562 | LOG (GNUNET_ERROR_TYPE_INFO, | 564 | LOG (GNUNET_ERROR_TYPE_INFO, |
563 | _("Failed to establish TCP connection to `%s:%u', no further addresses to try.\n"), | 565 | "Failed to establish TCP connection to `%s:%u', no further addresses to try.\n", |
564 | connection->hostname, connection->port); | 566 | connection->hostname, |
567 | connection->port); | ||
565 | GNUNET_break (NULL == connection->ap_head); | 568 | GNUNET_break (NULL == connection->ap_head); |
566 | GNUNET_break (NULL == connection->ap_tail); | 569 | GNUNET_break (NULL == connection->ap_tail); |
567 | GNUNET_break (GNUNET_NO == connection->dns_active); | 570 | GNUNET_break (GNUNET_NO == connection->dns_active); |
@@ -623,7 +626,8 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection) | |||
623 | { | 626 | { |
624 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 627 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
625 | "Connection to `%s' succeeded! (%p)\n", | 628 | "Connection to `%s' succeeded! (%p)\n", |
626 | GNUNET_a2s (connection->addr, connection->addrlen), connection); | 629 | GNUNET_a2s (connection->addr, connection->addrlen), |
630 | connection); | ||
627 | /* trigger jobs that waited for the connection */ | 631 | /* trigger jobs that waited for the connection */ |
628 | if (NULL != connection->receiver) | 632 | if (NULL != connection->receiver) |
629 | { | 633 | { |
@@ -709,12 +713,13 @@ connect_probe_continuation (void *cls, | |||
709 | * Try to establish a connection given the specified address. | 713 | * Try to establish a connection given the specified address. |
710 | * This function is called by the resolver once we have a DNS reply. | 714 | * This function is called by the resolver once we have a DNS reply. |
711 | * | 715 | * |
712 | * @param cls our "struct GNUNET_CONNECTION_Handle *" | 716 | * @param cls our `struct GNUNET_CONNECTION_Handle *` |
713 | * @param addr address to try, NULL for "last call" | 717 | * @param addr address to try, NULL for "last call" |
714 | * @param addrlen length of addr | 718 | * @param addrlen length of @a addr |
715 | */ | 719 | */ |
716 | static void | 720 | static void |
717 | try_connect_using_address (void *cls, const struct sockaddr *addr, | 721 | try_connect_using_address (void *cls, |
722 | const struct sockaddr *addr, | ||
718 | socklen_t addrlen) | 723 | socklen_t addrlen) |
719 | { | 724 | { |
720 | struct GNUNET_CONNECTION_Handle *connection = cls; | 725 | struct GNUNET_CONNECTION_Handle *connection = cls; |
@@ -733,8 +738,11 @@ try_connect_using_address (void *cls, const struct sockaddr *addr, | |||
733 | GNUNET_assert (NULL == connection->addr); | 738 | GNUNET_assert (NULL == connection->addr); |
734 | /* try to connect */ | 739 | /* try to connect */ |
735 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 740 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
736 | "Trying to connect using address `%s:%u/%s:%u'\n", connection->hostname, connection->port, | 741 | "Trying to connect using address `%s:%u/%s:%u'\n", |
737 | GNUNET_a2s (addr, addrlen), connection->port); | 742 | connection->hostname, |
743 | connection->port, | ||
744 | GNUNET_a2s (addr, addrlen), | ||
745 | connection->port); | ||
738 | ap = GNUNET_malloc (sizeof (struct AddressProbe) + addrlen); | 746 | ap = GNUNET_malloc (sizeof (struct AddressProbe) + addrlen); |
739 | ap->addr = (const struct sockaddr *) &ap[1]; | 747 | ap->addr = (const struct sockaddr *) &ap[1]; |
740 | memcpy (&ap[1], addr, addrlen); | 748 | memcpy (&ap[1], addr, addrlen); |
@@ -760,8 +768,10 @@ try_connect_using_address (void *cls, const struct sockaddr *addr, | |||
760 | GNUNET_free (ap); | 768 | GNUNET_free (ap); |
761 | return; /* not supported by OS */ | 769 | return; /* not supported by OS */ |
762 | } | 770 | } |
763 | LOG (GNUNET_ERROR_TYPE_INFO, _("Trying to connect to `%s' (%p)\n"), | 771 | LOG (GNUNET_ERROR_TYPE_INFO, |
764 | GNUNET_a2s (ap->addr, ap->addrlen), connection); | 772 | "Trying to connect to `%s' (%p)\n", |
773 | GNUNET_a2s (ap->addr, ap->addrlen), | ||
774 | connection); | ||
765 | if ((GNUNET_OK != | 775 | if ((GNUNET_OK != |
766 | GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) && | 776 | GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) && |
767 | (EINPROGRESS != errno)) | 777 | (EINPROGRESS != errno)) |
@@ -832,9 +842,8 @@ GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle | |||
832 | * @return the connection handle, NULL on systems without UNIX support | 842 | * @return the connection handle, NULL on systems without UNIX support |
833 | */ | 843 | */ |
834 | struct GNUNET_CONNECTION_Handle * | 844 | struct GNUNET_CONNECTION_Handle * |
835 | GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct | 845 | GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURATION_Handle *cfg, |
836 | GNUNET_CONFIGURATION_Handle | 846 | const char *unixpath) |
837 | *cfg, const char *unixpath) | ||
838 | { | 847 | { |
839 | #ifdef AF_UNIX | 848 | #ifdef AF_UNIX |
840 | struct GNUNET_CONNECTION_Handle *connection; | 849 | struct GNUNET_CONNECTION_Handle *connection; |
@@ -897,7 +906,7 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct | |||
897 | * | 906 | * |
898 | * @param s socket to connect | 907 | * @param s socket to connect |
899 | * @param serv_addr server address | 908 | * @param serv_addr server address |
900 | * @param addrlen length of server address | 909 | * @param addrlen length of @a serv_addr |
901 | * @return the connection handle | 910 | * @return the connection handle |
902 | */ | 911 | */ |
903 | struct GNUNET_CONNECTION_Handle * | 912 | struct GNUNET_CONNECTION_Handle * |
@@ -907,14 +916,17 @@ GNUNET_CONNECTION_connect_socket (struct GNUNET_NETWORK_Handle *s, | |||
907 | { | 916 | { |
908 | struct GNUNET_CONNECTION_Handle *connection; | 917 | struct GNUNET_CONNECTION_Handle *connection; |
909 | 918 | ||
910 | if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && | 919 | if ( (GNUNET_OK != |
911 | (EINPROGRESS != errno)) | 920 | GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && |
921 | (EINPROGRESS != errno) ) | ||
912 | { | 922 | { |
913 | /* maybe refused / unsupported address, try next */ | 923 | /* maybe refused / unsupported address, try next */ |
914 | LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect"); | 924 | LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, |
915 | LOG (GNUNET_ERROR_TYPE_INFO, | 925 | "connect"); |
916 | _("Attempt to connect to `%s' failed\n"), | 926 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
917 | GNUNET_a2s (serv_addr, addrlen)); | 927 | "Attempt to connect to `%s' failed\n", |
928 | GNUNET_a2s (serv_addr, | ||
929 | addrlen)); | ||
918 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); | 930 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); |
919 | return NULL; | 931 | return NULL; |
920 | } | 932 | } |
@@ -923,8 +935,9 @@ GNUNET_CONNECTION_connect_socket (struct GNUNET_NETWORK_Handle *s, | |||
923 | memcpy (connection->addr, serv_addr, addrlen); | 935 | memcpy (connection->addr, serv_addr, addrlen); |
924 | connection->addrlen = addrlen; | 936 | connection->addrlen = addrlen; |
925 | LOG (GNUNET_ERROR_TYPE_INFO, | 937 | LOG (GNUNET_ERROR_TYPE_INFO, |
926 | _("Trying to connect to `%s' (%p)\n"), | 938 | "Trying to connect to `%s' (%p)\n", |
927 | GNUNET_a2s (serv_addr, addrlen), connection); | 939 | GNUNET_a2s (serv_addr, addrlen), |
940 | connection); | ||
928 | return connection; | 941 | return connection; |
929 | } | 942 | } |
930 | 943 | ||
@@ -1129,7 +1142,7 @@ RETRY: | |||
1129 | 1142 | ||
1130 | /** | 1143 | /** |
1131 | * Receive data from the given connection. Note that this function will | 1144 | * Receive data from the given connection. Note that this function will |
1132 | * call "receiver" asynchronously using the scheduler. It will | 1145 | * call @a receiver asynchronously using the scheduler. It will |
1133 | * "immediately" return. Note that there MUST only be one active | 1146 | * "immediately" return. Note that there MUST only be one active |
1134 | * receive call per connection at any given point in time (so do not | 1147 | * receive call per connection at any given point in time (so do not |
1135 | * call receive again until the receiver callback has been invoked). | 1148 | * call receive again until the receiver callback has been invoked). |
@@ -1138,10 +1151,11 @@ RETRY: | |||
1138 | * @param max maximum number of bytes to read | 1151 | * @param max maximum number of bytes to read |
1139 | * @param timeout maximum amount of time to wait | 1152 | * @param timeout maximum amount of time to wait |
1140 | * @param receiver function to call with received data | 1153 | * @param receiver function to call with received data |
1141 | * @param receiver_cls closure for receiver | 1154 | * @param receiver_cls closure for @a receiver |
1142 | */ | 1155 | */ |
1143 | void | 1156 | void |
1144 | GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection, size_t max, | 1157 | GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection, |
1158 | size_t max, | ||
1145 | struct GNUNET_TIME_Relative timeout, | 1159 | struct GNUNET_TIME_Relative timeout, |
1146 | GNUNET_CONNECTION_Receiver receiver, | 1160 | GNUNET_CONNECTION_Receiver receiver, |
1147 | void *receiver_cls) | 1161 | void *receiver_cls) |
@@ -1196,7 +1210,7 @@ GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *connection) | |||
1196 | * have enough space available first)! | 1210 | * have enough space available first)! |
1197 | * | 1211 | * |
1198 | * @param connection connection for which we should do this processing | 1212 | * @param connection connection for which we should do this processing |
1199 | * @return GNUNET_YES if we were able to call notify | 1213 | * @return #GNUNET_YES if we were able to call notify |
1200 | */ | 1214 | */ |
1201 | static int | 1215 | static int |
1202 | process_notify (struct GNUNET_CONNECTION_Handle *connection) | 1216 | process_notify (struct GNUNET_CONNECTION_Handle *connection) |
@@ -1206,12 +1220,13 @@ process_notify (struct GNUNET_CONNECTION_Handle *connection) | |||
1206 | size_t size; | 1220 | size_t size; |
1207 | GNUNET_CONNECTION_TransmitReadyNotify notify; | 1221 | GNUNET_CONNECTION_TransmitReadyNotify notify; |
1208 | 1222 | ||
1209 | LOG (GNUNET_ERROR_TYPE_DEBUG, "process_notify is running\n"); | 1223 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1210 | 1224 | "process_notify is running\n"); | |
1211 | GNUNET_assert (NULL == connection->write_task); | 1225 | GNUNET_assert (NULL == connection->write_task); |
1212 | if (NULL == (notify = connection->nth.notify_ready)) | 1226 | if (NULL == (notify = connection->nth.notify_ready)) |
1213 | { | 1227 | { |
1214 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Noone to notify\n"); | 1228 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1229 | "No one to notify\n"); | ||
1215 | return GNUNET_NO; | 1230 | return GNUNET_NO; |
1216 | } | 1231 | } |
1217 | used = connection->write_buffer_off - connection->write_buffer_pos; | 1232 | used = connection->write_buffer_off - connection->write_buffer_pos; |
@@ -1219,7 +1234,8 @@ process_notify (struct GNUNET_CONNECTION_Handle *connection) | |||
1219 | size = connection->nth.notify_size; | 1234 | size = connection->nth.notify_size; |
1220 | if (size > avail) | 1235 | if (size > avail) |
1221 | { | 1236 | { |
1222 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Not enough buffer\n"); | 1237 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1238 | "Not enough buffer\n"); | ||
1223 | return GNUNET_NO; | 1239 | return GNUNET_NO; |
1224 | } | 1240 | } |
1225 | connection->nth.notify_ready = NULL; | 1241 | connection->nth.notify_ready = NULL; |
@@ -1251,7 +1267,7 @@ process_notify (struct GNUNET_CONNECTION_Handle *connection) | |||
1251 | * | 1267 | * |
1252 | * This task notifies the client about the timeout. | 1268 | * This task notifies the client about the timeout. |
1253 | * | 1269 | * |
1254 | * @param cls the 'struct GNUNET_CONNECTION_Handle' | 1270 | * @param cls the `struct GNUNET_CONNECTION_Handle` |
1255 | * @param tc scheduler context | 1271 | * @param tc scheduler context |
1256 | */ | 1272 | */ |
1257 | static void | 1273 | static void |
@@ -1278,7 +1294,7 @@ transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1278 | * | 1294 | * |
1279 | * This task notifies the client about the error. | 1295 | * This task notifies the client about the error. |
1280 | * | 1296 | * |
1281 | * @param cls the 'struct GNUNET_CONNECTION_Handle' | 1297 | * @param cls the `struct GNUNET_CONNECTION_Handle` |
1282 | * @param tc scheduler context | 1298 | * @param tc scheduler context |
1283 | */ | 1299 | */ |
1284 | static void | 1300 | static void |
@@ -1432,7 +1448,7 @@ SCHEDULE_WRITE: | |||
1432 | * @param connection connection | 1448 | * @param connection connection |
1433 | * @param size number of bytes to send | 1449 | * @param size number of bytes to send |
1434 | * @param timeout after how long should we give up (and call | 1450 | * @param timeout after how long should we give up (and call |
1435 | * notify with buf NULL and size 0)? | 1451 | * @a notify with buf NULL and size 0)? |
1436 | * @param notify function to call | 1452 | * @param notify function to call |
1437 | * @param notify_cls closure for @a notify | 1453 | * @param notify_cls closure for @a notify |
1438 | * @return non-NULL if the notify callback was queued, | 1454 | * @return non-NULL if the notify callback was queued, |