aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--iemnet.h65
-rw-r--r--iemnet_receiver.c19
-rw-r--r--tcpclient.c20
-rw-r--r--tcpreceive.c12
-rw-r--r--tcpserver.c14
-rw-r--r--udpclient.c18
-rw-r--r--udpreceive.c16
7 files changed, 52 insertions, 112 deletions
diff --git a/iemnet.h b/iemnet.h
index aca5b65..2c45d3c 100644
--- a/iemnet.h
+++ b/iemnet.h
@@ -50,69 +50,11 @@ EXTERN void sys_rmpollfn(int fd);
# include <netdb.h>
# include <arpa/inet.h>
# include <sys/socket.h>
-# include <sys/types.h>
#endif
+#include <sys/types.h>
/* iemnet_data.c */
-
-/**
- * chunk of data as sent to a socket or received from it
- * for received data, this might additionally hold the originator (if available)
- */
-typedef struct _iemnet_chunk {
- unsigned char* data;
- size_t size;
-
- long addr;
- unsigned short port;
-} t_iemnet_chunk;
-
-/**
- * free a "chunk" (de-allocate memory,...)
- */
-void iemnet__chunk_destroy(t_iemnet_chunk*);
-
-/**
- * initialize a "chunk" (allocate memory,...) of fixed size
- * receiver address will be set to 0
- *
- * \param size of the chunk (data will be zeroed out)
- * \return a new chunk of given size
- */
-t_iemnet_chunk*iemnet__chunk_create_empty(int);
-/**
- * initialize a "chunk" (allocate memory,...) with given data
- * receiver address will be set to 0
- *
- * \param size of data
- * \param data of size
- * \return a new chunk that holds a copy of data
- */
-t_iemnet_chunk*iemnet__chunk_create_data(int size, unsigned char*data);
-/**
- * initialize a "chunk" (allocate memory,...) with given data from specified address
- * \param size of data
- * \param data of size
- * \param addr originating address (can be NULL)
- * \return a new chunk that holds a copy of data
- */
-t_iemnet_chunk*iemnet__chunk_create_dataaddr(int size, unsigned char*data, struct sockaddr_in*addr);
-/**
- * initialize a "chunk" (allocate memory,...) with given data
- * receiver address will be set to 0
- *
- * \param argc size of list
- * \param argv list of atoms containing only "bytes" (t_floats [0..255])
- * \return a new chunk that holds a copy of the list data
- */
-t_iemnet_chunk*iemnet__chunk_create_list(int argc, t_atom*argv);
-/**
- * initialize a "chunk" (allocate memory,...) from another chunk
- *
- * \param src the source chunk
- * \return a new chunk that holds a copy of the source data
- */
-t_iemnet_chunk*iemnet__chunk_create_chunk(t_iemnet_chunk*source);
+#include "iemnet_data.h"
/* iemnet_sender.c */
@@ -173,8 +115,7 @@ EXTERN_STRUCT _iemnet_receiver;
* whenever data arrives at the socket, a callback will be called synchronously
*/
typedef void (*t_iemnet_receivecallback)(void*userdata,
- t_iemnet_chunk*rawdata,
- int argc, t_atom*argv);
+ t_iemnet_chunk*rawdata);
/**
* create a receiver object
diff --git a/iemnet_receiver.c b/iemnet_receiver.c
index d6f5bdf..3121e32 100644
--- a/iemnet_receiver.c
+++ b/iemnet_receiver.c
@@ -11,15 +11,6 @@
#include <stdio.h>
#include <errno.h>
-#include <sys/types.h>
-
-#ifdef _WIN32
-# include <winsock2.h>
-# include <ws2tcpip.h> /* for socklen_t */
-#else
-# include <sys/socket.h>
-#endif
-
#include <pthread.h>
#define INBUFSIZE 65536L /* was 4096: size of receiving data buffer */
@@ -34,7 +25,6 @@ struct _iemnet_receiver {
t_iemnet_queue*queue;
int running;
t_clock *clock;
- t_iemnet_floatlist*flist;
int keepreceiving;
@@ -108,8 +98,7 @@ static void iemnet__receiver_tick(t_iemnet_receiver *x)
// received data
t_iemnet_chunk*c=queue_pop_noblock(x->queue);
while(NULL!=c) {
- x->flist = iemnet__chunk2list(c, x->flist);
- (x->callback)(x->userdata, c, x->flist->argc, x->flist->argv);
+ (x->callback)(x->userdata, c);
iemnet__chunk_destroy(c);
c=queue_pop_noblock(x->queue);
}
@@ -124,7 +113,7 @@ static void iemnet__receiver_tick(t_iemnet_receiver *x)
/* keepreceiving is set, if receiver is not yet in shutdown mode */
if(x->keepreceiving)
- x->callback(x->userdata, NULL, 0, NULL);
+ x->callback(x->userdata, NULL);
}
DEBUG("tick DONE");
}
@@ -156,7 +145,6 @@ t_iemnet_receiver*iemnet__receiver_create(int sock, void*userdata, t_iemnet_rece
rec->userdata=userdata;
rec->data=data;
rec->callback=callback;
- rec->flist=iemnet__floatlist_create(1024);
memcpy(&rec->newdatamtx , &mtx, sizeof(pthread_mutex_t));
rec->newdataflag=0;
@@ -174,6 +162,7 @@ t_iemnet_receiver*iemnet__receiver_create(int sock, void*userdata, t_iemnet_rece
void iemnet__receiver_destroy(t_iemnet_receiver*rec) {
static int instance=0;
int inst=instance++;
+ return;
int sockfd;
DEBUG("[%d] destroy receiver %x", inst, rec);
@@ -203,7 +192,6 @@ void iemnet__receiver_destroy(t_iemnet_receiver*rec) {
DEBUG("[%d] tack", inst);
if(rec->data)iemnet__chunk_destroy(rec->data);
- if(rec->flist)iemnet__floatlist_destroy(rec->flist);
pthread_mutex_destroy(&rec->newdatamtx);
@@ -213,7 +201,6 @@ void iemnet__receiver_destroy(t_iemnet_receiver*rec) {
rec->userdata=NULL;
rec->data=NULL;
rec->callback=NULL;
- rec->flist=NULL;
rec->queue=NULL;
freebytes(rec, sizeof(t_iemnet_receiver));
diff --git a/tcpclient.c b/tcpclient.c
index 35dc2e8..ebc0119 100644
--- a/tcpclient.c
+++ b/tcpclient.c
@@ -56,14 +56,12 @@ typedef struct _tcpclient
/* multithread stuff */
pthread_t x_threadid; /* id of child thread */
pthread_attr_t x_threadattr; /* attributes of child thread */
-} t_tcpclient;
-
-static void tcpclient_receive_callback(void *x,
- t_iemnet_chunk*,
- int argc, t_atom*argv);
+ t_iemnet_floatlist *x_floatlist;
+} t_tcpclient;
+static void tcpclient_receive_callback(void *x, t_iemnet_chunk*);
static void tcpclient_info(t_tcpclient *x)
{
@@ -217,12 +215,13 @@ static void tcpclient_send(t_tcpclient *x, t_symbol *s, int argc, t_atom *argv)
}
}
-static void tcpclient_receive_callback(void*y, t_iemnet_chunk*c, int argc, t_atom*argv) {
+static void tcpclient_receive_callback(void*y, t_iemnet_chunk*c) {
t_tcpclient *x=(t_tcpclient*)y;
- if(argc) {
+ if(c) {
iemnet__addrout(x->x_statusout, x->x_addrout, x->x_addr, x->x_port);
- iemnet__streamout(x->x_msgout, argc, argv);
+ 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);
} else {
// disconnected
tcpclient_disconnect(x);
@@ -249,8 +248,8 @@ static void *tcpclient_new(void)
x->x_sender=NULL;
x->x_receiver=NULL;
-
x->x_clock = clock_new(x, (t_method)tcpclient_tick);
+ x->x_floatlist=iemnet__floatlist_create(1024);
/* prepare child thread */
if(pthread_attr_init(&x->x_threadattr) < 0)
@@ -265,7 +264,8 @@ static void *tcpclient_new(void)
static void tcpclient_free(t_tcpclient *x)
{
tcpclient_disconnect(x);
- clock_free(x->x_clock);
+ if(x->x_clock)clock_free(x->x_clock);x->x_clock=NULL;
+ if(x->x_floatlist)iemnet__floatlist_destroy(x->x_floatlist);x->x_floatlist=NULL;
}
IEMNET_EXTERN void tcpclient_setup(void)
diff --git a/tcpreceive.c b/tcpreceive.c
index a9d08dc..e0e348b 100644
--- a/tcpreceive.c
+++ b/tcpreceive.c
@@ -57,6 +57,8 @@ typedef struct _tcpreceive
int x_nconnections;
t_tcpconnection x_connection[MAX_CONNECTIONS];
+
+ t_iemnet_floatlist *x_floatlist;
} t_tcpreceive;
@@ -70,7 +72,7 @@ static int tcpreceive_find_socket(t_tcpreceive *x, int fd) {
static int tcpreceive_disconnect(t_tcpreceive *x, int id);
-static void tcpreceive_read_callback(void *w, t_iemnet_chunk*c, int argc, t_atom*argv)
+static void tcpreceive_read_callback(void *w, t_iemnet_chunk*c)
{
t_tcpconnection*y=(t_tcpconnection*)w;
t_tcpreceive*x=NULL;
@@ -79,9 +81,10 @@ static void tcpreceive_read_callback(void *w, t_iemnet_chunk*c, int argc, t_atom
index=tcpreceive_find_socket(x, y->socket);
if(index>=0) {
- if(argc) {
+ if(c) {
// TODO?: outlet info about connection
- iemnet__streamout(x->x_msgout, argc, argv);
+ 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);
} else {
// disconnected
tcpreceive_disconnect(x, index);
@@ -293,6 +296,7 @@ static void tcpreceive_free(t_tcpreceive *x)
sys_closesocket(x->x_connectsocket);
}
tcpreceive_disconnect_all(x);
+ if(x->x_floatlist)iemnet__floatlist_destroy(x->x_floatlist);x->x_floatlist=NULL;
}
static void *tcpreceive_new(t_floatarg fportno)
@@ -319,6 +323,8 @@ static void *tcpreceive_new(t_floatarg fportno)
x->x_connection[i].port = 0;
}
+ x->x_floatlist=iemnet__floatlist_create(1024);
+
tcpreceive_port(x, portno);
return (x);
diff --git a/tcpserver.c b/tcpserver.c
index fef0c65..b1b5042 100644
--- a/tcpserver.c
+++ b/tcpserver.c
@@ -63,10 +63,10 @@ typedef struct _tcpserver
t_int x_port;
int x_defaulttarget; /* the default connection to send to; 0=broadcast; >0 use this client; <0 exclude this client */
- t_iemnet_floatlist*x_floatlist;
+ t_iemnet_floatlist *x_floatlist;
} t_tcpserver;
-static void tcpserver_receive_callback(void*x, t_iemnet_chunk*,int argc, t_atom*argv);
+static void tcpserver_receive_callback(void*x, t_iemnet_chunk*);
static t_tcpserver_socketreceiver *tcpserver_socketreceiver_new(t_tcpserver *owner, int sockfd, struct sockaddr_in*addr)
{
@@ -460,16 +460,14 @@ static void tcpserver_disconnect_all(t_tcpserver *x)
/* ---------------- main tcpserver (receive) stuff --------------------- */
static void tcpserver_receive_callback(void *y0,
- t_iemnet_chunk*c,
- int argc, t_atom*argv) {
+ t_iemnet_chunk*c) {
t_tcpserver_socketreceiver *y=(t_tcpserver_socketreceiver*)y0;
t_tcpserver*x=NULL;
if(NULL==y || NULL==(x=y->sr_owner))return;
- if(argc) {
+ if(c) {
tcpserver_info_connection(x, y);
- x->x_floatlist=iemnet__chunk2list(c, x->x_floatlist);
-
+ 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);
} else {
// disconnected
@@ -624,7 +622,7 @@ static void tcpserver_free(t_tcpserver *x)
sys_rmpollfn(x->x_connectsocket);
sys_closesocket(x->x_connectsocket);
}
- if(x->x_floatlist)iemnet__floatlist_destroy(x->x_floatlist);
+ if(x->x_floatlist)iemnet__floatlist_destroy(x->x_floatlist);x->x_floatlist=NULL;
}
IEMNET_EXTERN void tcpserver_setup(void)
diff --git a/udpclient.c b/udpclient.c
index a1e1bea..0034fca 100644
--- a/udpclient.c
+++ b/udpclient.c
@@ -56,12 +56,12 @@ typedef struct _udpclient
/* multithread stuff */
pthread_t x_threadid; /* id of child thread */
pthread_attr_t x_threadattr; /* attributes of child thread */
+
+ t_iemnet_floatlist *x_floatlist;
} t_udpclient;
-static void udpclient_receive_callback(void *x,
- t_iemnet_chunk*,
- int argc, t_atom*argv);
+static void udpclient_receive_callback(void *x, t_iemnet_chunk*);
@@ -185,12 +185,13 @@ static void udpclient_send(t_udpclient *x, t_symbol *s, int argc, t_atom *argv)
outlet_anything( x->x_statusout, gensym("sent"), 1, &output_atom);
}
-static void udpclient_receive_callback(void*y, t_iemnet_chunk*c, int argc, t_atom*argv) {
+static void udpclient_receive_callback(void*y, t_iemnet_chunk*c) {
t_udpclient *x=(t_udpclient*)y;
- if(argc) {
+ if(c) {
iemnet__addrout(x->x_statusout, x->x_addrout, x->x_addr, x->x_port);
- outlet_list(x->x_msgout, gensym("list"), argc, argv);
+ x->x_floatlist=iemnet__chunk2list(c, x->x_floatlist); // gets destroyed in the dtor
+ outlet_list(x->x_msgout, gensym("list"),x->x_floatlist->argc, x->x_floatlist->argv);
} else {
// disconnected
DEBUG("disconnected");
@@ -219,6 +220,8 @@ static void *udpclient_new(void)
x->x_clock = clock_new(x, (t_method)udpclient_tick);
+ x->x_floatlist=iemnet__floatlist_create(1024);
+
/* prepare child thread */
if(pthread_attr_init(&x->x_threadattr) < 0)
verbose(1, "[%s] warning: could not prepare child thread", objName);
@@ -232,7 +235,8 @@ static void *udpclient_new(void)
static void udpclient_free(t_udpclient *x)
{
udpclient_disconnect(x);
- clock_free(x->x_clock);
+ if(x->x_clock)clock_free(x->x_clock);x->x_clock=NULL;
+ if(x->x_floatlist)iemnet__floatlist_destroy(x->x_floatlist);x->x_floatlist=NULL;
}
IEMNET_EXTERN void udpclient_setup(void)
diff --git a/udpreceive.c b/udpreceive.c
index 0d60c2d..63e226e 100644
--- a/udpreceive.c
+++ b/udpreceive.c
@@ -40,16 +40,15 @@ typedef struct _udpreceive
int x_connectsocket;
int x_port;
t_iemnet_receiver*x_receiver;
+ t_iemnet_floatlist *x_floatlist;
} t_udpreceive;
-static void udpreceive_read_callback(void*y,
- t_iemnet_chunk*c,
- int argc, t_atom*argv) {
+static void udpreceive_read_callback(void*y, t_iemnet_chunk*c) {
t_udpreceive*x=(t_udpreceive*)y;
- if(argc) {
- iemnet__addrout(x->x_statout, x->x_addrout, c->addr, c->port);
- outlet_list(x->x_msgout, gensym("list"), argc, argv);
+ if(c) {
+ x->x_floatlist=iemnet__chunk2list(c, x->x_floatlist); // gets destroyed in the dtor
+ outlet_list(x->x_msgout, gensym("list"), x->x_floatlist->argc, x->x_floatlist->argv);
} else {
post("[%s] nothing received", objName);
}
@@ -133,6 +132,9 @@ static void *udpreceive_new(t_floatarg fportno)
x->x_connectsocket = -1;
x->x_port = -1;
x->x_receiver = NULL;
+
+ x->x_floatlist=iemnet__floatlist_create(1024);
+
udpreceive_port(x, fportno);
return (x);
@@ -146,6 +148,8 @@ static void udpreceive_free(t_udpreceive *x)
outlet_free(x->x_msgout);
outlet_free(x->x_addrout);
outlet_free(x->x_statout);
+
+ if(x->x_floatlist)iemnet__floatlist_destroy(x->x_floatlist);x->x_floatlist=NULL;
}
IEMNET_EXTERN void udpreceive_setup(void)