aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Peach <mrpeach@users.sourceforge.net>2007-08-06 22:18:12 +0000
committerMartin Peach <mrpeach@users.sourceforge.net>2007-08-06 22:18:12 +0000
commit0d3baf9be42d1083de7473481bc3113114568d6d (patch)
tree294c5da3ca1d1ec3420b7bf4ebe69260ecce6033
parent6a66486589f875fd4ca18eaead3db168c15a1f8e (diff)
Closing socket should actually work now. Before it was just removing it from the list.
svn path=/trunk/externals/mrpeach/; revision=8439
-rwxr-xr-xnet/tcpserver.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/net/tcpserver.c b/net/tcpserver.c
index ccc59c9..156d5e0 100755
--- a/net/tcpserver.c
+++ b/net/tcpserver.c
@@ -104,6 +104,7 @@ static void tcpserver_socketreceiver_free(t_tcpserver_socketreceiver *x);
static void tcpserver_send(t_tcpserver *x, t_symbol *s, int argc, t_atom *argv);
static void tcp_server_send_bytes(int sockfd, t_tcpserver *x, int argc, t_atom *argv);
static void tcpserver_client_send(t_tcpserver *x, t_symbol *s, int argc, t_atom *argv);
+static void tcpserver_disconnect(t_tcpserver *x);
static void tcpserver_client_disconnect(t_tcpserver *x, t_floatarg fclient);
static void tcpserver_socket_disconnect(t_tcpserver *x, t_floatarg fsocket);
static void tcpserver_broadcast(t_tcpserver *x, t_symbol *s, int argc, t_atom *argv);
@@ -406,6 +407,30 @@ static void tcpserver_send(t_tcpserver *x, t_symbol *s, int argc, t_atom *argv)
tcp_server_send_bytes(client, x, argc-1, &argv[1]);
}
+/* disconnect the client at x_sock_fd */
+static void tcpserver_disconnect(t_tcpserver *x)
+{
+ int i, fd;
+ t_tcpserver_socketreceiver *y;
+
+ if (x->x_sock_fd >= 0)
+ {
+ /* find the socketreceiver for this socket */
+ for(i = 0; i < x->x_nconnections; i++)
+ {
+ if(x->x_fd[i] == x->x_sock_fd)
+ {
+ y = x->x_sr[i];
+ fd = x->x_fd[i];
+ if (y->sr_notifier) (*y->sr_notifier)(x);
+ sys_rmpollfn(fd);
+ sys_closesocket(fd);
+ x->x_sock_fd = -1;
+ }
+ }
+ }
+}
+
/* disconnect a client by socket */
static void tcpserver_socket_disconnect(t_tcpserver *x, t_floatarg fsocket)
{
@@ -417,10 +442,9 @@ static void tcpserver_socket_disconnect(t_tcpserver *x, t_floatarg fsocket)
return;
}
x->x_sock_fd = sock;
- tcpserver_notify(x);
+ tcpserver_disconnect(x);
}
-
/* disconnect a client by number */
static void tcpserver_client_disconnect(t_tcpserver *x, t_floatarg fclient)
{
@@ -438,7 +462,7 @@ static void tcpserver_client_disconnect(t_tcpserver *x, t_floatarg fclient)
}
--client;/* zero based index*/
x->x_sock_fd = x->x_fd[client];
- tcpserver_notify(x);
+ tcpserver_disconnect(x);
}