*/
int clients_ignore_shutdown;
+ GNUNET_SERVER_MstCreateCallback mst_create;
+ GNUNET_SERVER_MstDestroyCallback mst_destroy;
+ GNUNET_SERVER_MstReceiveCallback mst_receive;
+ void *mst_cls;
};
/**
* Processing of incoming data.
*/
- struct GNUNET_SERVER_MessageStreamTokenizer *mst;
+ void *mst;
/**
* Server that this client belongs to.
*/
int receive_pending;
+ /**
+ * Finish pending write when disconnecting?
+ */
+ int finish_pending_write;
+
/**
* Persist the file handle for this client no matter what happens,
* force the OS to close once the process actually dies. Should only
}
+void
+GNUNET_SERVER_set_callbacks (struct GNUNET_SERVER_Handle *server,
+ GNUNET_SERVER_MstCreateCallback create,
+ GNUNET_SERVER_MstDestroyCallback destroy,
+ GNUNET_SERVER_MstReceiveCallback receive,
+ void *cls)
+{
+ server->mst_create = create;
+ server->mst_destroy = destroy;
+ server->mst_receive = receive;
+ server->mst_cls = cls;
+}
+
+
/**
* Task run to warn about missing calls to 'GNUNET_SERVER_receive_done'.
*
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Server processes additional messages instantly.\n");
#endif
- ret =
- GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO,
- GNUNET_YES);
+ if (client->server->mst_receive != NULL)
+ ret =
+ client->server->mst_receive (client->server->mst_cls, client->mst,
+ client, NULL, 0, GNUNET_NO, GNUNET_YES);
+ else
+ ret =
+ GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO,
+ GNUNET_YES);
}
#if DEBUG_SERVER
LOG (GNUNET_ERROR_TYPE_DEBUG,
#endif
GNUNET_SERVER_client_keep (client);
client->last_activity = now;
- ret =
- GNUNET_SERVER_mst_receive (client->mst, client, buf, available, GNUNET_NO,
- GNUNET_YES);
+
+ if (server->mst_receive != NULL)
+ ret =
+ client->server->mst_receive (client->server->mst_cls, client->mst,
+ client, buf, available, GNUNET_NO, GNUNET_YES);
+ else
+ ret =
+ GNUNET_SERVER_mst_receive (client->mst, client, buf, available, GNUNET_NO,
+ GNUNET_YES);
+
process_mst (client, ret);
}
client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client));
client->connection = connection;
- client->mst =
- GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, server);
client->reference_count = 1;
client->server = server;
client->last_activity = GNUNET_TIME_absolute_get ();
client->receive_pending = GNUNET_YES;
client->callback = NULL;
client->callback_cls = NULL;
+
+ if (server->mst_create != NULL)
+ client->mst =
+ server->mst_create (server->mst_cls, client);
+ else
+ client->mst =
+ GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, server);
+
GNUNET_CONNECTION_receive (client->connection,
GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
client->idle_timeout, &process_incoming, client);
}
+void
+GNUNET_SERVER_client_set_finish_pending_write (struct GNUNET_SERVER_Client *client,
+ int finish)
+{
+ client->finish_pending_write = finish;
+}
+
+
/**
* Notify the server that the given client handle should
* be kept (keeps the connection up if possible, increments
}
rc = client->reference_count;
- if (client->server != NULL)
+ if (client->shutdown_now != GNUNET_YES)
{
server = client->server;
- client->server = NULL;
client->shutdown_now = GNUNET_YES;
prev = NULL;
pos = server->clients;
if (client->persist == GNUNET_YES)
GNUNET_CONNECTION_persist_ (client->connection);
- GNUNET_CONNECTION_destroy (client->connection, GNUNET_NO);
- GNUNET_SERVER_mst_destroy (client->mst);
+ GNUNET_CONNECTION_destroy (client->connection, client->finish_pending_write);
+
+ if (client->server->mst_destroy != NULL)
+ client->server->mst_destroy (client->server->mst_cls, client->mst);
+ else
+ GNUNET_SERVER_mst_destroy (client->mst);
+
GNUNET_free (client);
}
#endif
return;
}
- if (client->server == NULL)
+ if ((client->server == NULL) || (GNUNET_YES == client->shutdown_now))
{
GNUNET_SERVER_client_disconnect (client);
return;