diff options
author | LRN <lrn1986@gmail.com> | 2013-03-13 17:49:26 +0000 |
---|---|---|
committer | LRN <lrn1986@gmail.com> | 2013-03-13 17:49:26 +0000 |
commit | 405f776bc08486af4edb80e18149c0829732b347 (patch) | |
tree | d5fc635a51641dec6b53cb2540276f34ae8f6210 /src/util | |
parent | 3ceae682287492ecc768aea5c4c463216a35774d (diff) | |
download | gnunet-405f776bc08486af4edb80e18149c0829732b347.tar.gz gnunet-405f776bc08486af4edb80e18149c0829732b347.zip |
All-encompassing ARM update
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/client.c | 1 | ||||
-rw-r--r-- | src/util/connection.c | 8 | ||||
-rw-r--r-- | src/util/server.c | 78 |
3 files changed, 85 insertions, 2 deletions
diff --git a/src/util/client.c b/src/util/client.c index 69380c9b0..8b4776201 100644 --- a/src/util/client.c +++ b/src/util/client.c | |||
@@ -1007,6 +1007,7 @@ client_notify (void *cls, size_t size, void *buf) | |||
1007 | size_t ret; | 1007 | size_t ret; |
1008 | struct GNUNET_TIME_Relative delay; | 1008 | struct GNUNET_TIME_Relative delay; |
1009 | 1009 | ||
1010 | LOG (GNUNET_ERROR_TYPE_DEBUG, "client_notify is running\n"); | ||
1010 | th->th = NULL; | 1011 | th->th = NULL; |
1011 | client->th = NULL; | 1012 | client->th = NULL; |
1012 | if (NULL == buf) | 1013 | if (NULL == buf) |
diff --git a/src/util/connection.c b/src/util/connection.c index c4795cebe..ea35b04e1 100644 --- a/src/util/connection.c +++ b/src/util/connection.c | |||
@@ -1153,14 +1153,22 @@ process_notify (struct GNUNET_CONNECTION_Handle *connection) | |||
1153 | size_t size; | 1153 | size_t size; |
1154 | GNUNET_CONNECTION_TransmitReadyNotify notify; | 1154 | GNUNET_CONNECTION_TransmitReadyNotify notify; |
1155 | 1155 | ||
1156 | LOG (GNUNET_ERROR_TYPE_DEBUG, "process_notify is running\n"); | ||
1157 | |||
1156 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->write_task); | 1158 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->write_task); |
1157 | if (NULL == (notify = connection->nth.notify_ready)) | 1159 | if (NULL == (notify = connection->nth.notify_ready)) |
1160 | { | ||
1161 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Noone to notify\n"); | ||
1158 | return GNUNET_NO; | 1162 | return GNUNET_NO; |
1163 | } | ||
1159 | used = connection->write_buffer_off - connection->write_buffer_pos; | 1164 | used = connection->write_buffer_off - connection->write_buffer_pos; |
1160 | avail = connection->write_buffer_size - used; | 1165 | avail = connection->write_buffer_size - used; |
1161 | size = connection->nth.notify_size; | 1166 | size = connection->nth.notify_size; |
1162 | if (size > avail) | 1167 | if (size > avail) |
1168 | { | ||
1169 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Not enough buffer\n"); | ||
1163 | return GNUNET_NO; | 1170 | return GNUNET_NO; |
1171 | } | ||
1164 | connection->nth.notify_ready = NULL; | 1172 | connection->nth.notify_ready = NULL; |
1165 | if (connection->write_buffer_size - connection->write_buffer_off < size) | 1173 | if (connection->write_buffer_size - connection->write_buffer_off < size) |
1166 | { | 1174 | { |
diff --git a/src/util/server.c b/src/util/server.c index fc5f263bf..526821477 100644 --- a/src/util/server.c +++ b/src/util/server.c | |||
@@ -111,6 +111,16 @@ struct GNUNET_SERVER_Handle | |||
111 | struct NotifyList *disconnect_notify_list_tail; | 111 | struct NotifyList *disconnect_notify_list_tail; |
112 | 112 | ||
113 | /** | 113 | /** |
114 | * Head of linked list of functions to call on connects by clients. | ||
115 | */ | ||
116 | struct NotifyList *connect_notify_list_head; | ||
117 | |||
118 | /** | ||
119 | * Tail of linked list of functions to call on connects by clients. | ||
120 | */ | ||
121 | struct NotifyList *connect_notify_list_tail; | ||
122 | |||
123 | /** | ||
114 | * Function to call for access control. | 124 | * Function to call for access control. |
115 | */ | 125 | */ |
116 | GNUNET_CONNECTION_AccessCheck access; | 126 | GNUNET_CONNECTION_AccessCheck access; |
@@ -756,6 +766,14 @@ GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server) | |||
756 | npos); | 766 | npos); |
757 | GNUNET_free (npos); | 767 | GNUNET_free (npos); |
758 | } | 768 | } |
769 | while (NULL != (npos = server->connect_notify_list_head)) | ||
770 | { | ||
771 | npos->callback (npos->callback_cls, NULL); | ||
772 | GNUNET_CONTAINER_DLL_remove (server->connect_notify_list_head, | ||
773 | server->connect_notify_list_tail, | ||
774 | npos); | ||
775 | GNUNET_free (npos); | ||
776 | } | ||
759 | GNUNET_free (server); | 777 | GNUNET_free (server); |
760 | } | 778 | } |
761 | 779 | ||
@@ -1161,6 +1179,7 @@ GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server, | |||
1161 | struct GNUNET_CONNECTION_Handle *connection) | 1179 | struct GNUNET_CONNECTION_Handle *connection) |
1162 | { | 1180 | { |
1163 | struct GNUNET_SERVER_Client *client; | 1181 | struct GNUNET_SERVER_Client *client; |
1182 | struct NotifyList *n; | ||
1164 | 1183 | ||
1165 | client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client)); | 1184 | client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client)); |
1166 | client->connection = connection; | 1185 | client->connection = connection; |
@@ -1178,6 +1197,9 @@ GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server, | |||
1178 | client->mst = | 1197 | client->mst = |
1179 | GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, server); | 1198 | GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, server); |
1180 | GNUNET_assert (NULL != client->mst); | 1199 | GNUNET_assert (NULL != client->mst); |
1200 | for (n = server->connect_notify_list_head; NULL != n; n = n->next) | ||
1201 | n->callback (n->callback_cls, client); | ||
1202 | |||
1181 | client->receive_pending = GNUNET_YES; | 1203 | client->receive_pending = GNUNET_YES; |
1182 | GNUNET_CONNECTION_receive (client->connection, | 1204 | GNUNET_CONNECTION_receive (client->connection, |
1183 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, | 1205 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, |
@@ -1277,10 +1299,34 @@ GNUNET_SERVER_disconnect_notify (struct GNUNET_SERVER_Handle *server, | |||
1277 | 1299 | ||
1278 | 1300 | ||
1279 | /** | 1301 | /** |
1280 | * Ask the server to stop notifying us whenever a client disconnects. | 1302 | * Ask the server to notify us whenever a client connects. |
1303 | * This function is called whenever the actual network connection | ||
1304 | * is opened. | ||
1281 | * | 1305 | * |
1282 | * @param server the server manageing the clients | 1306 | * @param server the server manageing the clients |
1283 | * @param callback function to call on disconnect | 1307 | * @param callback function to call on sconnect |
1308 | * @param callback_cls closure for callback | ||
1309 | */ | ||
1310 | void | ||
1311 | GNUNET_SERVER_connect_notify (struct GNUNET_SERVER_Handle *server, | ||
1312 | GNUNET_SERVER_ConnectCallback callback, void *callback_cls) | ||
1313 | { | ||
1314 | struct NotifyList *n; | ||
1315 | |||
1316 | n = GNUNET_malloc (sizeof (struct NotifyList)); | ||
1317 | n->callback = callback; | ||
1318 | n->callback_cls = callback_cls; | ||
1319 | GNUNET_CONTAINER_DLL_insert (server->connect_notify_list_head, | ||
1320 | server->connect_notify_list_tail, | ||
1321 | n); | ||
1322 | } | ||
1323 | |||
1324 | |||
1325 | /** | ||
1326 | * Ask the server to stop notifying us whenever a client connects. | ||
1327 | * | ||
1328 | * @param server the server manageing the clients | ||
1329 | * @param callback function to call on connect | ||
1284 | * @param callback_cls closure for callback | 1330 | * @param callback_cls closure for callback |
1285 | */ | 1331 | */ |
1286 | void | 1332 | void |
@@ -1306,6 +1352,34 @@ GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server, | |||
1306 | 1352 | ||
1307 | 1353 | ||
1308 | /** | 1354 | /** |
1355 | * Ask the server to stop notifying us whenever a client disconnects. | ||
1356 | * | ||
1357 | * @param server the server manageing the clients | ||
1358 | * @param callback function to call on disconnect | ||
1359 | * @param callback_cls closure for callback | ||
1360 | */ | ||
1361 | void | ||
1362 | GNUNET_SERVER_connect_notify_cancel (struct GNUNET_SERVER_Handle *server, | ||
1363 | GNUNET_SERVER_ConnectCallback callback, void *callback_cls) | ||
1364 | { | ||
1365 | struct NotifyList *pos; | ||
1366 | |||
1367 | for (pos = server->connect_notify_list_head; NULL != pos; pos = pos->next) | ||
1368 | if ((pos->callback == callback) && (pos->callback_cls == callback_cls)) | ||
1369 | break; | ||
1370 | if (NULL == pos) | ||
1371 | { | ||
1372 | GNUNET_break (0); | ||
1373 | return; | ||
1374 | } | ||
1375 | GNUNET_CONTAINER_DLL_remove (server->connect_notify_list_head, | ||
1376 | server->connect_notify_list_tail, | ||
1377 | pos); | ||
1378 | GNUNET_free (pos); | ||
1379 | } | ||
1380 | |||
1381 | |||
1382 | /** | ||
1309 | * Destroy the connection that is passed in via 'cls'. Used | 1383 | * Destroy the connection that is passed in via 'cls'. Used |
1310 | * as calling 'GNUNET_CONNECTION_destroy' from within a function | 1384 | * as calling 'GNUNET_CONNECTION_destroy' from within a function |
1311 | * that was itself called from within 'process_notify' of | 1385 | * that was itself called from within 'process_notify' of |