From a77528f82a9c7078eddca92ea84160895c115c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Wed, 24 Mar 2010 16:40:47 +0000 Subject: check for validity before disconnecting (and invalidate pointers after) svn path=/trunk/externals/iem/iemnet/; revision=13257 --- tcpclient.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tcpclient.c') diff --git a/tcpclient.c b/tcpclient.c index 5f6ff06..42fe2e0 100644 --- a/tcpclient.c +++ b/tcpclient.c @@ -143,9 +143,11 @@ static void tcpclient_tick(t_tcpclient *x) } +static void tcpclient_disconnect(t_tcpclient *x); static void tcpclient_connect(t_tcpclient *x, t_symbol *hostname, t_floatarg fportno) { + if(x->x_fd>=0)tcpclient_disconnect(x); /* we get hostname and port and pass them on to the child thread that establishes the connection */ x->x_hostname = hostname->s_name; @@ -158,11 +160,11 @@ static void tcpclient_connect(t_tcpclient *x, t_symbol *hostname, t_floatarg fpo static void tcpclient_disconnect(t_tcpclient *x) { - if(x->x_sender)iemnet__sender_destroy(x->x_sender); - if(x->x_receiver)iemnet__receiver_destroy(x->x_receiver); - if (x->x_fd >= 0) { + if(x->x_sender)iemnet__sender_destroy(x->x_sender); x->x_sender=NULL; + if(x->x_receiver)iemnet__receiver_destroy(x->x_receiver); x->x_receiver=NULL; + sys_closesocket(x->x_fd); x->x_fd = -1; x->x_connectstate = 0; -- cgit v1.2.1