aboutsummaryrefslogtreecommitdiff
path: root/tcpsend.c
diff options
context:
space:
mode:
Diffstat (limited to 'tcpsend.c')
-rw-r--r--tcpsend.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/tcpsend.c b/tcpsend.c
index 664137c..f35c4e1 100644
--- a/tcpsend.c
+++ b/tcpsend.c
@@ -1,5 +1,5 @@
/* tcpsend.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) Miller Puckette
*/
@@ -33,7 +33,6 @@ static const char objName[] = "tcpsend";
# include <netinet/tcp.h>
#endif
-
static t_class *tcpsend_class;
typedef struct _tcpsend {
@@ -44,20 +43,17 @@ typedef struct _tcpsend {
static void tcpsend_disconnect(t_tcpsend *x)
{
+ if(x->x_sender) {
+ iemnet__sender_destroy(x->x_sender, 0);
+ }
+ x->x_sender=NULL;
if (x->x_fd >= 0) {
- if(x->x_sender) {
- iemnet__sender_destroy(x->x_sender, 0);
- }
- x->x_sender=NULL;
iemnet__closesocket(x->x_fd);
x->x_fd = -1;
outlet_float(x->x_obj.ob_outlet, 0);
- //post("tcpsend: disconnected");
}
}
-
-
static void tcpsend_connect(t_tcpsend *x, t_symbol *hostname,
t_floatarg fportno)
{
@@ -69,7 +65,7 @@ static void tcpsend_connect(t_tcpsend *x, t_symbol *hostname,
memset(&server, 0, sizeof(server));
if (x->x_fd >= 0) {
- error("tcpsend: already connected");
+ iemnet_log(x, IEMNET_ERROR, "already connected");
return;
}
@@ -77,21 +73,23 @@ static void tcpsend_connect(t_tcpsend *x, t_symbol *hostname,
sockfd = socket(AF_INET, SOCK_STREAM, 0);
DEBUG("send socket %d\n", sockfd);
if (sockfd < 0) {
- sys_sockerror("tcpsend: socket");
+ iemnet_log(x, IEMNET_ERROR, "unable to open socket");
+ sys_sockerror("socket");
return;
}
/* connect socket using hostname provided in command line */
server.sin_family = AF_INET;
hp = gethostbyname(hostname->s_name);
if (hp == 0) {
- post("tcpsend: bad host?\n");
+ iemnet_log(x, IEMNET_ERROR, "bad host '%s'?", hostname->s_name);
return;
}
/* for stream (TCP) sockets, specify "nodelay" */
intarg = 1;
if (setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY,
(char *)&intarg, sizeof(intarg)) < 0) {
- post("tcpsend: setsockopt (TCP_NODELAY) failed\n");
+ iemnet_log(x, IEMNET_ERROR, "unable to enable immediate sending");
+ sys_sockerror("setsockopt");
}
memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
@@ -99,10 +97,11 @@ static void tcpsend_connect(t_tcpsend *x, t_symbol *hostname,
/* assign client port number */
server.sin_port = htons((u_short)portno);
- post("tcpsend: connecting to port %d", portno);
+ iemnet_log(x, IEMNET_VERBOSE, "connecting to port %d", portno);
/* try to connect. */
if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) < 0) {
- sys_sockerror("tcpsend: connecting stream socket");
+ iemnet_log(x, IEMNET_ERROR, "unable to initiate connection on socket %d", sockfd);
+ sys_sockerror("connect");
iemnet__closesocket(sockfd);
return;
}
@@ -160,5 +159,4 @@ IEMNET_EXTERN void tcpsend_setup(void)
IEMNET_INITIALIZER(tcpsend_setup);
-
/* end tcpsend.c */