From e6f799e41d7910e1388c68630c49bf3141cb8d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Tue, 1 Sep 2015 14:30:54 +0000 Subject: sync with git svn path=/trunk/externals/iem/iemnet/; revision=17545 --- tcpclient.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'tcpclient.c') diff --git a/tcpclient.c b/tcpclient.c index a1519b1..40a32ea 100644 --- a/tcpclient.c +++ b/tcpclient.c @@ -1,5 +1,5 @@ /* tcpclient.c - * copyright (c) 2010 IOhannes m zmölnig, IEM + * copyright © 2010-2015 IOhannes m zmölnig, IEM * copyright (c) 2006-2010 Martin Peach * copyright (c) 2004 Olaf Matthes */ @@ -116,14 +116,15 @@ static int tcpclient_do_connect(const char*host, unsigned short port, server.sin_family = AF_INET; hp = gethostbyname(host); if (hp == 0) { - sys_sockerror("tcpclient: bad host?\n"); + iemnet_log(x, IEMNET_ERROR, "bad host '%s'?", host); return (-1); } memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length); sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { - sys_sockerror("tcpclient: socket"); + iemnet_log(x, IEMNET_ERROR, "unable to open socket"); + sys_sockerror("socket"); return (sockfd); } @@ -132,7 +133,8 @@ static int tcpclient_do_connect(const char*host, unsigned short port, /* try to connect */ if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) < 0) { - sys_sockerror("tcpclient: connecting stream socket"); + iemnet_log(x, IEMNET_ERROR, "unable to connect to stream socket"); + sys_sockerror("connect"); iemnet__closesocket(sockfd); return (-1); } @@ -166,14 +168,12 @@ static void tcpclient_connect(t_tcpclient *x, t_symbol *hostname, { long addr=0; int state; + + // first disconnect any active connection if(x->x_hostname || x->x_port) { state=tcpclient_do_disconnect(x->x_fd, x->x_sender, x->x_receiver); if(state) { outlet_float(x->x_connectout, 0); - } else { - if(!x->x_port) { - pd_error(x, "[%s]: not connected", objName); - } } } @@ -191,7 +191,6 @@ static void tcpclient_connect(t_tcpclient *x, t_symbol *hostname, if(state>0) { outlet_float(x->x_connectout, 1); } - } static void tcpclient_disconnect(t_tcpclient *x) @@ -200,7 +199,7 @@ static void tcpclient_disconnect(t_tcpclient *x) int state=tcpclient_do_disconnect(x->x_fd, x->x_sender, x->x_receiver); if(!state && !x->x_port) { - pd_error(x, "[%s]: not connected", objName); + iemnet_log(x, IEMNET_ERROR, "not connected"); } } outlet_float(x->x_connectout, 0); -- cgit v1.2.1