From 4902493c79875a2e39468b31f384fe333cb81e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Wed, 7 Apr 2010 14:45:28 +0000 Subject: iemnet__streamout() takes an argument telling us whether to serialize or not (non-serialization might be useful for proxies) svn path=/trunk/externals/iem/iemnet/; revision=13393 --- iemnet.c | 13 +++++++++---- iemnet.h | 5 +++-- tcpclient.c | 13 ++++++++++++- tcpreceive.c | 13 ++++++++++++- tcpserver.c | 13 ++++++++++++- 5 files changed, 48 insertions(+), 9 deletions(-) diff --git a/iemnet.c b/iemnet.c index 6cf8d2b..8e95384 100644 --- a/iemnet.c +++ b/iemnet.c @@ -45,11 +45,16 @@ void iemnet__socketout(t_outlet*status_outlet, t_outlet*socket_outlet, int socke } -void iemnet__streamout(t_outlet*outlet, int argc, t_atom*argv) { +void iemnet__streamout(t_outlet*outlet, int argc, t_atom*argv, int stream) { if(NULL==outlet)return; - while(argc-->0) { - outlet_list(outlet, gensym("list"), 1, argv); - argv++; + + if(stream) { + while(argc-->0) { + outlet_list(outlet, gensym("list"), 1, argv); + argv++; + } + } else { + outlet_list(outlet, gensym("list"), argc, argv); } } diff --git a/iemnet.h b/iemnet.h index 2c45d3c..ca1a971 100644 --- a/iemnet.h +++ b/iemnet.h @@ -195,10 +195,11 @@ void iemnet__numconnout(t_outlet*status_outlet, t_outlet*numconn_outlet, int num * \param outlet outlet to sent the data to * \param argc size of the list * \param argv data + * \param stream if true, serialize the data; if false output as "packets" * - * \note with stream based protocols (TCP/IP) the length of the received lists has no meaning, so the data has to be serialized anyhow + * \note with stream based protocols (TCP/IP) the length of the received lists has no meaning, so the data has to be serialized anyhow; however when creating proxies, sending serialized data is often slow, so there is an option to disable serialization */ -void iemnet__streamout(t_outlet*outlet, int argc, t_atom*argv); +void iemnet__streamout(t_outlet*outlet, int argc, t_atom*argv, int stream); /** * register an objectname and printout a banner diff --git a/tcpclient.c b/tcpclient.c index ebc0119..7a37c53 100644 --- a/tcpclient.c +++ b/tcpclient.c @@ -46,6 +46,7 @@ typedef struct _tcpclient t_iemnet_sender *x_sender; t_iemnet_receiver*x_receiver; + int x_serialize; int x_fd; // the socket char *x_hostname; // address we want to connect to as text @@ -221,13 +222,18 @@ static void tcpclient_receive_callback(void*y, t_iemnet_chunk*c) { if(c) { iemnet__addrout(x->x_statusout, x->x_addrout, x->x_addr, x->x_port); x->x_floatlist=iemnet__chunk2list(c, x->x_floatlist); // get's destroyed in the dtor - iemnet__streamout(x->x_msgout, x->x_floatlist->argc, x->x_floatlist->argv); + iemnet__streamout(x->x_msgout, x->x_floatlist->argc, x->x_floatlist->argv, x->x_serialize); } else { // disconnected tcpclient_disconnect(x); } } +static void tcpclient_serialize(t_tcpclient *x, t_floatarg doit) { + x->x_serialize=doit; +} + + /* constructor/destructor */ static void *tcpclient_new(void) @@ -240,6 +246,8 @@ static void *tcpclient_new(void) x->x_connectout = outlet_new(&x->x_obj, gensym("float")); /* connection state */ x->x_statusout = outlet_new(&x->x_obj, 0);/* last outlet for everything else */ + x->x_serialize=1; + x->x_fd = -1; x->x_addr = 0L; @@ -277,6 +285,9 @@ IEMNET_EXTERN void tcpclient_setup(void) class_addmethod(tcpclient_class, (t_method)tcpclient_connect, gensym("connect") , A_SYMBOL, A_FLOAT, 0); class_addmethod(tcpclient_class, (t_method)tcpclient_disconnect, gensym("disconnect"), 0); + + class_addmethod(tcpclient_class, (t_method)tcpclient_serialize, gensym("serialize"), A_FLOAT, 0); + class_addmethod(tcpclient_class, (t_method)tcpclient_send, gensym("send"), A_GIMME, 0); class_addlist(tcpclient_class, (t_method)tcpclient_send); diff --git a/tcpreceive.c b/tcpreceive.c index e0e348b..3bd73a8 100644 --- a/tcpreceive.c +++ b/tcpreceive.c @@ -55,6 +55,8 @@ typedef struct _tcpreceive int x_connectsocket; int x_port; + int x_serialize; + int x_nconnections; t_tcpconnection x_connection[MAX_CONNECTIONS]; @@ -84,7 +86,7 @@ static void tcpreceive_read_callback(void *w, t_iemnet_chunk*c) if(c) { // TODO?: outlet info about connection x->x_floatlist=iemnet__chunk2list(c, x->x_floatlist); // gets destroyed in the dtor - iemnet__streamout(x->x_msgout, x->x_floatlist->argc, x->x_floatlist->argv); + iemnet__streamout(x->x_msgout, x->x_floatlist->argc, x->x_floatlist->argv, x->x_serialize); } else { // disconnected tcpreceive_disconnect(x, index); @@ -287,6 +289,10 @@ static void tcpreceive_port(t_tcpreceive*x, t_floatarg fportno) outlet_anything(x->x_statout, gensym("port"), 1, ap); } +static void tcpreceive_serialize(t_tcpreceive *x, t_floatarg doit) { + x->x_serialize=doit; +} + static void tcpreceive_free(t_tcpreceive *x) { /* is this ever called? */ @@ -311,6 +317,8 @@ static void *tcpreceive_new(t_floatarg fportno) x->x_connectout = outlet_new(&x->x_obj, gensym("float")); /* legacy */ x->x_statout = outlet_new(&x->x_obj, 0);/* outlet for everything else */ + x->x_serialize=1; + x->x_connectsocket=-1; x->x_port=-1; x->x_nconnections=0; @@ -341,6 +349,9 @@ IEMNET_EXTERN void tcpreceive_setup(void) A_DEFFLOAT, 0); class_addmethod(tcpreceive_class, (t_method)tcpreceive_port, gensym("port"), A_DEFFLOAT, 0); + + class_addmethod(tcpreceive_class, (t_method)tcpreceive_serialize, gensym("serialize"), A_FLOAT, 0); + } IEMNET_INITIALIZER(tcpreceive_setup); diff --git a/tcpserver.c b/tcpserver.c index b1b5042..f9b9095 100644 --- a/tcpserver.c +++ b/tcpserver.c @@ -56,6 +56,8 @@ typedef struct _tcpserver t_outlet *x_addrout; // legacy t_outlet *x_statout; + int x_serialize; + t_tcpserver_socketreceiver *x_sr[MAX_CONNECT]; /* socket per connection */ t_int x_nconnections; @@ -468,7 +470,7 @@ static void tcpserver_receive_callback(void *y0, if(c) { tcpserver_info_connection(x, y); x->x_floatlist=iemnet__chunk2list(c, x->x_floatlist); // get's destroyed in the dtor - iemnet__streamout(x->x_msgout, x->x_floatlist->argc, x->x_floatlist->argv); + iemnet__streamout(x->x_msgout, x->x_floatlist->argc, x->x_floatlist->argv, x->x_serialize); } else { // disconnected int sockfd=y->sr_fd; @@ -572,6 +574,11 @@ static void tcpserver_port(t_tcpserver*x, t_floatarg fportno) outlet_anything(x->x_statout, gensym("port"), 1, ap); } +static void tcpserver_serialize(t_tcpserver *x, t_floatarg doit) { + x->x_serialize=doit; +} + + static void *tcpserver_new(t_floatarg fportno) { t_tcpserver *x; @@ -585,6 +592,7 @@ static void *tcpserver_new(t_floatarg fportno) x->x_addrout = outlet_new(&x->x_obj, gensym("list" )); x->x_statout = outlet_new(&x->x_obj, 0);/* 5th outlet for everything else */ + x->x_serialize=1; x->x_connectsocket = -1; x->x_port = -1; @@ -645,6 +653,9 @@ IEMNET_EXTERN void tcpserver_setup(void) class_addlist (tcpserver_class, (t_method)tcpserver_defaultsend); + class_addmethod(tcpserver_class, (t_method)tcpserver_serialize, gensym("serialize"), A_FLOAT, 0); + + class_addmethod(tcpserver_class, (t_method)tcpserver_port, gensym("port"), A_DEFFLOAT, 0); class_addbang (tcpserver_class, (t_method)tcpserver_info); } -- cgit v1.2.1