aboutsummaryrefslogtreecommitdiff
path: root/src/util/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/server.c')
-rw-r--r--src/util/server.c79
1 files changed, 67 insertions, 12 deletions
diff --git a/src/util/server.c b/src/util/server.c
index 6f1b8cdb4..24804d2d2 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -140,6 +140,10 @@ struct GNUNET_SERVER_Handle
140 */ 140 */
141 int clients_ignore_shutdown; 141 int clients_ignore_shutdown;
142 142
143 GNUNET_SERVER_MstCreateCallback mst_create;
144 GNUNET_SERVER_MstDestroyCallback mst_destroy;
145 GNUNET_SERVER_MstReceiveCallback mst_receive;
146 void *mst_cls;
143}; 147};
144 148
145 149
@@ -157,7 +161,7 @@ struct GNUNET_SERVER_Client
157 /** 161 /**
158 * Processing of incoming data. 162 * Processing of incoming data.
159 */ 163 */
160 struct GNUNET_SERVER_MessageStreamTokenizer *mst; 164 void *mst;
161 165
162 /** 166 /**
163 * Server that this client belongs to. 167 * Server that this client belongs to.
@@ -243,6 +247,11 @@ struct GNUNET_SERVER_Client
243 int receive_pending; 247 int receive_pending;
244 248
245 /** 249 /**
250 * Finish pending write when disconnecting?
251 */
252 int finish_pending_write;
253
254 /**
246 * Persist the file handle for this client no matter what happens, 255 * Persist the file handle for this client no matter what happens,
247 * force the OS to close once the process actually dies. Should only 256 * force the OS to close once the process actually dies. Should only
248 * be used in special cases! 257 * be used in special cases!
@@ -597,6 +606,20 @@ GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server,
597} 606}
598 607
599 608
609void
610GNUNET_SERVER_set_callbacks (struct GNUNET_SERVER_Handle *server,
611 GNUNET_SERVER_MstCreateCallback create,
612 GNUNET_SERVER_MstDestroyCallback destroy,
613 GNUNET_SERVER_MstReceiveCallback receive,
614 void *cls)
615{
616 server->mst_create = create;
617 server->mst_destroy = destroy;
618 server->mst_receive = receive;
619 server->mst_cls = cls;
620}
621
622
600/** 623/**
601 * Task run to warn about missing calls to 'GNUNET_SERVER_receive_done'. 624 * Task run to warn about missing calls to 'GNUNET_SERVER_receive_done'.
602 * 625 *
@@ -776,9 +799,14 @@ process_mst (struct GNUNET_SERVER_Client *client, int ret)
776 LOG (GNUNET_ERROR_TYPE_DEBUG, 799 LOG (GNUNET_ERROR_TYPE_DEBUG,
777 "Server processes additional messages instantly.\n"); 800 "Server processes additional messages instantly.\n");
778#endif 801#endif
779 ret = 802 if (client->server->mst_receive != NULL)
780 GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO, 803 ret =
781 GNUNET_YES); 804 client->server->mst_receive (client->server->mst_cls, client->mst,
805 client, NULL, 0, GNUNET_NO, GNUNET_YES);
806 else
807 ret =
808 GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO,
809 GNUNET_YES);
782 } 810 }
783#if DEBUG_SERVER 811#if DEBUG_SERVER
784 LOG (GNUNET_ERROR_TYPE_DEBUG, 812 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -857,9 +885,16 @@ process_incoming (void *cls, const void *buf, size_t available,
857#endif 885#endif
858 GNUNET_SERVER_client_keep (client); 886 GNUNET_SERVER_client_keep (client);
859 client->last_activity = now; 887 client->last_activity = now;
860 ret = 888
861 GNUNET_SERVER_mst_receive (client->mst, client, buf, available, GNUNET_NO, 889 if (server->mst_receive != NULL)
862 GNUNET_YES); 890 ret =
891 client->server->mst_receive (client->server->mst_cls, client->mst,
892 client, buf, available, GNUNET_NO, GNUNET_YES);
893 else
894 ret =
895 GNUNET_SERVER_mst_receive (client->mst, client, buf, available, GNUNET_NO,
896 GNUNET_YES);
897
863 process_mst (client, ret); 898 process_mst (client, ret);
864} 899}
865 900
@@ -966,6 +1001,14 @@ GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server,
966 client->receive_pending = GNUNET_YES; 1001 client->receive_pending = GNUNET_YES;
967 client->callback = NULL; 1002 client->callback = NULL;
968 client->callback_cls = NULL; 1003 client->callback_cls = NULL;
1004
1005 if (server->mst_create != NULL)
1006 client->mst =
1007 server->mst_create (server->mst_cls, client);
1008 else
1009 client->mst =
1010 GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, server);
1011
969 GNUNET_CONNECTION_receive (client->connection, 1012 GNUNET_CONNECTION_receive (client->connection,
970 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, 1013 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
971 client->idle_timeout, &process_incoming, client); 1014 client->idle_timeout, &process_incoming, client);
@@ -989,6 +1032,14 @@ GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client,
989} 1032}
990 1033
991 1034
1035void
1036GNUNET_SERVER_client_set_finish_pending_write (struct GNUNET_SERVER_Client *client,
1037 int finish)
1038{
1039 client->finish_pending_write = finish;
1040}
1041
1042
992/** 1043/**
993 * Notify the server that the given client handle should 1044 * Notify the server that the given client handle should
994 * be kept (keeps the connection up if possible, increments 1045 * be kept (keeps the connection up if possible, increments
@@ -1137,10 +1188,9 @@ GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client)
1137 } 1188 }
1138 1189
1139 rc = client->reference_count; 1190 rc = client->reference_count;
1140 if (client->server != NULL) 1191 if (client->shutdown_now != GNUNET_YES)
1141 { 1192 {
1142 server = client->server; 1193 server = client->server;
1143 client->server = NULL;
1144 client->shutdown_now = GNUNET_YES; 1194 client->shutdown_now = GNUNET_YES;
1145 prev = NULL; 1195 prev = NULL;
1146 pos = server->clients; 1196 pos = server->clients;
@@ -1190,8 +1240,13 @@ GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client)
1190 1240
1191 if (client->persist == GNUNET_YES) 1241 if (client->persist == GNUNET_YES)
1192 GNUNET_CONNECTION_persist_ (client->connection); 1242 GNUNET_CONNECTION_persist_ (client->connection);
1193 GNUNET_CONNECTION_destroy (client->connection, GNUNET_NO); 1243 GNUNET_CONNECTION_destroy (client->connection, client->finish_pending_write);
1194 GNUNET_SERVER_mst_destroy (client->mst); 1244
1245 if (client->server->mst_destroy != NULL)
1246 client->server->mst_destroy (client->server->mst_cls, client->mst);
1247 else
1248 GNUNET_SERVER_mst_destroy (client->mst);
1249
1195 GNUNET_free (client); 1250 GNUNET_free (client);
1196} 1251}
1197 1252
@@ -1326,7 +1381,7 @@ GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client, int success)
1326#endif 1381#endif
1327 return; 1382 return;
1328 } 1383 }
1329 if (client->server == NULL) 1384 if ((client->server == NULL) || (GNUNET_YES == client->shutdown_now))
1330 { 1385 {
1331 GNUNET_SERVER_client_disconnect (client); 1386 GNUNET_SERVER_client_disconnect (client);
1332 return; 1387 return;