[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r28625 - msh/src
From: |
gnunet |
Subject: |
[GNUnet-SVN] r28625 - msh/src |
Date: |
Wed, 14 Aug 2013 17:37:25 +0200 |
Author: harsha
Date: 2013-08-14 17:37:25 +0200 (Wed, 14 Aug 2013)
New Revision: 28625
Modified:
msh/src/msh.c
msh/src/mshd-server.c
Log:
- cleanup client context upon client disconnect
Modified: msh/src/msh.c
===================================================================
--- msh/src/msh.c 2013-08-14 14:59:17 UTC (rev 28624)
+++ msh/src/msh.c 2013-08-14 15:37:25 UTC (rev 28625)
@@ -601,7 +601,7 @@
if (NULL == msg)
{
- LOG_ERROR ("Broken IPC connection\n");
+ LOG_DEBUG ("Broken IPC connection\n");
goto err_ret;
}
switch (ntohs (msg->type))
Modified: msh/src/mshd-server.c
===================================================================
--- msh/src/mshd-server.c 2013-08-14 14:59:17 UTC (rev 28624)
+++ msh/src/mshd-server.c 2013-08-14 15:37:25 UTC (rev 28625)
@@ -225,7 +225,7 @@
if (NULL != ctx->tx)
GNUNET_SERVER_notify_transmit_ready_cancel (ctx->tx);
- GNUNET_SERVER_client_drop (ctx->client);
+ GNUNET_assert (NULL == ctx->client);
while (NULL != (mq = ctx->mq_head))
{
GNUNET_free (mq->msg);
@@ -262,7 +262,9 @@
wrote = 0;
if ((0 == size) || (NULL == buf))
{
- destroy_client_ctx (ctx);
+ GNUNET_assert (NULL != ctx->client);
+ GNUNET_SERVER_client_drop (ctx->client);
+ ctx->client = NULL;
return 0;
}
mq = ctx->mq_head;
@@ -505,7 +507,7 @@
* @param client the client handle
*/
static void
-local_server_client_connect (void *cls, struct GNUNET_SERVER_Client *client)
+local_server_connect (void *cls, struct GNUNET_SERVER_Client *client)
{
struct ClientCtx *ctx;
@@ -519,6 +521,31 @@
/**
+ * Callback to be called when ever a client connects to the local server
+ *
+ * @param cls NULL
+ * @param client the client handle
+ */
+static void
+local_server_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
+{
+ struct ClientCtx *ctx;
+
+ if (NULL == client)
+ return;
+ LOG_DEBUG ("A local client has disconnected\n");
+ ctx = GNUNET_SERVER_client_get_user_context (client, struct ClientCtx);
+ GNUNET_assert (NULL != ctx);
+ if (NULL != ctx->client)
+ {
+ GNUNET_SERVER_client_drop (ctx->client);
+ ctx->client = NULL;
+ }
+ destroy_client_ctx (ctx);
+}
+
+
+/**
* Initialise the local server
*
* @param unixpath the name to use while opening the abstract UNIX domain
socket
@@ -561,7 +588,8 @@
return GNUNET_SYSERR;
}
GNUNET_SERVER_add_handlers (local_serv, handlers);
- GNUNET_SERVER_connect_notify (local_serv, &local_server_client_connect,
NULL);
+ GNUNET_SERVER_connect_notify (local_serv, &local_server_connect, NULL);
+ GNUNET_SERVER_disconnect_notify (local_serv, &local_server_disconnect, NULL);
return GNUNET_OK;
}
@@ -635,8 +663,9 @@
close_conn:
GNUNET_break_op (0);
- destroy_client_ctx (ctx);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_SERVER_client_drop (ctx->client);
+ ctx->client = NULL;
}
@@ -685,7 +714,6 @@
{
GNUNET_break (GNUNET_SYSERR != size);
GNUNET_SERVER_client_disconnect (ctx->client);
- destroy_client_ctx (ctx);
return;
}
msize = size + sizeof (struct MSH_MSG_CmdIO);
@@ -814,7 +842,8 @@
err_ret:
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- destroy_client_ctx (ctx);
+ GNUNET_SERVER_client_drop (ctx->client);
+ ctx->client = NULL;
}
@@ -837,18 +866,14 @@
GNUNET_free (exec_ctx->buf);
exec_ctx->buf = NULL;
exec_ctx->bufsize = 0;
- GNUNET_SERVER_receive_done (ctx->client, GNUNET_SYSERR);
- destroy_client_ctx (ctx);
- return;
+ goto err_ret;
}
wrote = GNUNET_DISK_file_write (exec_ctx->fin,
exec_ctx->buf, exec_ctx->bufsize);
if (GNUNET_SYSERR == wrote)
{
LOG_ERROR ("Error writing to proc's STDIN\n");
- GNUNET_SERVER_receive_done (ctx->client, GNUNET_SYSERR);
- destroy_client_ctx (ctx);
- return;
+ goto err_ret;
}
if (wrote == exec_ctx->bufsize)
{
@@ -867,6 +892,12 @@
GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
exec_ctx->fin,
&write_fin, ctx);
+ return;
+
+ err_ret:
+ GNUNET_SERVER_receive_done (ctx->client, GNUNET_SYSERR);
+ GNUNET_SERVER_client_drop (ctx->client);
+ ctx->client = NULL;
}
@@ -902,7 +933,8 @@
{
LOG_ERROR ("Error writing to proc's STDIN\n");
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- destroy_client_ctx (ctx);
+ GNUNET_SERVER_client_drop (ctx->client);
+ ctx->client = NULL;
return;
}
LOG_DEBUG ("Wrote %zd to proc's STDIN\n", wrote);
@@ -927,6 +959,31 @@
/**
+ * Callback to be called when ever a client connects to the local server
+ *
+ * @param cls NULL
+ * @param client the client handle
+ */
+static void
+daemon_server_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
+{
+ struct ClientCtx *ctx;
+
+ if (NULL == client)
+ return;
+ LOG_DEBUG ("A remote client has disconnected\n");
+ ctx = GNUNET_SERVER_client_get_user_context (client, struct ClientCtx);
+ GNUNET_assert (NULL != ctx);
+ if (NULL != ctx->client)
+ {
+ GNUNET_SERVER_client_drop (ctx->client);
+ ctx->client = NULL;
+ }
+ destroy_client_ctx (ctx);
+}
+
+
+/**
* Initialises the server which spawns processes and forwards it stdin and
stdout
*
* @param h the network handle of the socket to listen for incoming connections
@@ -950,6 +1007,7 @@
if (NULL == daemon_serv)
return GNUNET_SYSERR;
GNUNET_SERVER_add_handlers (daemon_serv, handlers);
+ GNUNET_SERVER_disconnect_notify (daemon_serv, &daemon_server_disconnect,
NULL);
return GNUNET_OK;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r28625 - msh/src,
gnunet <=