aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--iemnet.c12
-rw-r--r--iemnet.h9
-rw-r--r--shared.c14
-rw-r--r--tcpclient.c22
-rw-r--r--tcpserver.c16
5 files changed, 48 insertions, 25 deletions
diff --git a/iemnet.c b/iemnet.c
new file mode 100644
index 0000000..c58c54d
--- /dev/null
+++ b/iemnet.c
@@ -0,0 +1,12 @@
+#include "iemnet.h"
+
+void tcpclient_setup(void);
+void tcpserver_setup(void);
+
+
+IEMNET_EXTERN void iemnet_setup(void) {
+tcpserver_setup();
+tcpclient_setup();
+
+
+} \ No newline at end of file
diff --git a/iemnet.h b/iemnet.h
index 4d35794..6bc7190 100644
--- a/iemnet.h
+++ b/iemnet.h
@@ -1,6 +1,13 @@
#include "m_pd.h"
-#include <sys/socket.h>
+#ifdef _WIN32
+# define IEMNET_EXTERN __declspec(dllexport) extern
+# include <winsock2.h>
+# include <ws2tcpip.h>
+#else
+# define IEMNET_EXTERN extern
+# include <sys/socket.h>
+#endif
typedef struct _iemnet_chunk {
unsigned char* data;
diff --git a/shared.c b/shared.c
index 09faaad..1a46a92 100644
--- a/shared.c
+++ b/shared.c
@@ -387,10 +387,10 @@ static int iemnet__sender_dosend(int sockfd, t_queue*q) {
if(c) {
unsigned char*data=c->data;
unsigned int size=c->size;
-
+ int result=-1;
fprintf(stderr, "sending %d bytes at %x to %d\n", size, data, sockfd);
- int result = send(sockfd, data, size, 0);
+ result = send(sockfd, data, size, 0);
// shouldn't we do something with the result here?
iemnet__chunk_destroy(c);
} else {
@@ -508,12 +508,13 @@ static void*iemnet__receiver_readthread(void*arg) {
for(i=0; i<size; i++)data[i]=0;
receiver->running=1;
while(1) {
+ t_iemnet_chunk*c=NULL;
fprintf(stderr, "reading %d bytes...\n", size);
result = recv(sockfd, data, size, 0);
fprintf(stderr, "read %d bytes...\n", result);
if(result<=0)break;
- t_iemnet_chunk*c = iemnet__chunk_create_data(result, data);
+ c= iemnet__chunk_create_data(result, data);
queue_push(q, c);
@@ -531,27 +532,20 @@ static void*iemnet__receiver_readthread(void*arg) {
return NULL;
}
-#define WHERE fprintf(stderr, "%s:%d", __FUNCTION__, __LINE__)
static void iemnet__receiver_tick(t_iemnet_receiver *x)
{
- WHERE; fprintf(stderr, "\treceiver=%x", x);
// received data
t_iemnet_chunk*c=queue_pop_noblock(x->queue);
- WHERE; fprintf(stderr, "\tchunk=%x", c);
while(NULL!=c) {
x->flist = iemnet__chunk2list(c, x->flist);
(x->callback)(x->owner, x->sockfd, x->flist->argc, x->flist->argv);
iemnet__chunk_destroy(c);
c=queue_pop_noblock(x->queue);
}
-
- WHERE; fprintf(stderr, "\trunning=%d", x->running);
-
if(!x->running) {
// read terminated
x->callback(x->owner, x->sockfd, 0, NULL);
}
- WHERE; fprintf(stderr, "\ttick done\n");
}
diff --git a/tcpclient.c b/tcpclient.c
index 3800b47..5f6ff06 100644
--- a/tcpclient.c
+++ b/tcpclient.c
@@ -28,7 +28,11 @@
#include "s_stuff.h"
-#include <netdb.h> /* gethostbyname, htons... */
+#ifdef _WIN32
+#else
+# include <netdb.h> /* gethostbyname, htons... */
+#endif
+
#include <string.h>
@@ -189,7 +193,7 @@ static void tcpclient_receive_callback(t_tcpclient *x, int sockfd, int argc, t_a
// ignore sockfd
if(argc) {
- outlet_list(x->x_msgout, &s_list, argc, argv);
+ outlet_list(x->x_msgout, gensym("list"), argc, argv);
} else {
// disconnected
tcpclient_disconnect(x);
@@ -203,10 +207,10 @@ static void *tcpclient_new(void)
int i;
t_tcpclient *x = (t_tcpclient *)pd_new(tcpclient_class);
- x->x_msgout = outlet_new(&x->x_obj, &s_anything); /* received data */
- x->x_addrout = outlet_new(&x->x_obj, &s_list);
- x->x_connectout = outlet_new(&x->x_obj, &s_float); /* connection state */
- x->x_statusout = outlet_new(&x->x_obj, &s_anything);/* last outlet for everything else */
+ x->x_msgout = outlet_new(&x->x_obj, 0); /* received data */
+ x->x_addrout = outlet_new(&x->x_obj, gensym("list"));
+ 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_fd = -1;
@@ -239,7 +243,7 @@ static void tcpclient_free(t_tcpclient *x)
clock_free(x->x_clock);
}
-void tcpclient_setup(void)
+IEMNET_EXTERN void tcpclient_setup(void)
{
tcpclient_class = class_new(gensym(objName), (t_newmethod)tcpclient_new,
(t_method)tcpclient_free,
@@ -249,6 +253,10 @@ void tcpclient_setup(void)
class_addmethod(tcpclient_class, (t_method)tcpclient_disconnect, gensym("disconnect"), 0);
class_addmethod(tcpclient_class, (t_method)tcpclient_send, gensym("send"), A_GIMME, 0);
class_addlist(tcpclient_class, (t_method)tcpclient_send);
+
+ post("iemnet: networking with Pd :: %s", objName);
+ post(" (c) 2010 IOhannes m zmoelnig, IEM");
+ post(" based on mrpeach/net, based on maxlib");
}
/* end of tcpclient.c */
diff --git a/tcpserver.c b/tcpserver.c
index f5f4f09..74e8211 100644
--- a/tcpserver.c
+++ b/tcpserver.c
@@ -159,9 +159,10 @@ static void tcpserver_send_client(t_tcpserver *x, t_symbol *s, int argc, t_atom
{
if (argc > 1)
{
+ t_iemnet_chunk*chunk=NULL;
int client=tcpserver_fixindex(x, atom_getint(argv));
if(client<0)return;
- t_iemnet_chunk*chunk=iemnet__chunk_create_list(argc-1, argv+1);
+ chunk=iemnet__chunk_create_list(argc-1, argv+1);
--client;/* zero based index*/
tcpserver_send_bytes(x, client, chunk);
return;
@@ -214,6 +215,7 @@ static void tcpserver_broadcastbut(t_tcpserver *x, t_symbol *s, int argc, t_atom
static void tcpserver_send_socket(t_tcpserver *x, t_symbol *s, int argc, t_atom *argv)
{
int client = -1;
+ t_iemnet_chunk*chunk=NULL;
if(argc) {
client = tcpserver_socket2index(x, atom_getint(argv));
if(client<0)return;
@@ -239,7 +241,7 @@ static void tcpserver_send_socket(t_tcpserver *x, t_symbol *s, int argc, t_atom
return;
}
- t_iemnet_chunk*chunk=iemnet__chunk_create_list(argc-1, argv+1);
+ chunk=iemnet__chunk_create_list(argc-1, argv+1);
tcpserver_send_bytes(x, client, chunk);
iemnet__chunk_destroy(chunk);
}
@@ -299,7 +301,7 @@ static void tcpserver_disconnect_all(t_tcpserver *x)
/* ---------------- main tcpserver (receive) stuff --------------------- */
static void tcpserver_receive_callback(t_tcpserver *x, int sockfd, int argc, t_atom*argv) {
if(argc) {
- outlet_list(x->x_msgout, &s_list, argc, argv);
+ outlet_list(x->x_msgout, gensym("list"), argc, argv);
} else {
// disconnected
tcpserver_disconnect_socket(x, sockfd);
@@ -364,7 +366,7 @@ static void *tcpserver_new(t_floatarg fportno)
}
x = (t_tcpserver *)pd_new(tcpserver_class);
- x->x_msgout = outlet_new(&x->x_obj, &s_anything); /* 1st outlet for received data */
+ x->x_msgout = outlet_new(&x->x_obj, 0); /* 1st outlet for received data */
@@ -378,8 +380,8 @@ static void *tcpserver_new(t_floatarg fportno)
else
{
sys_addpollfn(sockfd, (t_fdpollfn)tcpserver_connectpoll, x); // wait for new connections
- x->x_connectout = outlet_new(&x->x_obj, &s_float); /* 2nd outlet for number of connected clients */
- x->x_status_outlet = outlet_new(&x->x_obj, &s_anything);/* 5th outlet for everything else */
+ x->x_connectout = outlet_new(&x->x_obj, gensym("float")); /* 2nd outlet for number of connected clients */
+ x->x_status_outlet = outlet_new(&x->x_obj, 0);/* 5th outlet for everything else */
}
x->x_connectsocket = sockfd;
x->x_nconnections = 0;
@@ -415,7 +417,7 @@ static void tcpserver_free(t_tcpserver *x)
}
-void tcpserver_setup(void)
+IEMNET_EXTERN void tcpserver_setup(void)
{
tcpserver_class = class_new(gensym(objName),(t_newmethod)tcpserver_new, (t_method)tcpserver_free,
sizeof(t_tcpserver), 0, A_DEFFLOAT, 0);