aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2010-04-01 07:21:24 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2010-04-01 07:21:24 +0000
commit6129f96ce81d32b7884b3ada7c895a86c280f95a (patch)
treee6cf877e4b2e2f3822faa1c1ae2eb9fac201eaf1
parent7ac448bb91b48fcc835c623272ef41cbbbba6d9b (diff)
exporting symbols; using objName
svn path=/trunk/externals/iem/iemnet/; revision=13330
-rw-r--r--iemnet.c39
-rw-r--r--iemnet.h13
-rw-r--r--tcpclient.c9
-rw-r--r--tcpreceive.c18
-rw-r--r--tcpsend.c9
-rw-r--r--tcpserver.c10
-rw-r--r--udpclient.c20
-rw-r--r--udpreceive.c15
-rw-r--r--udpsend.c21
9 files changed, 99 insertions, 55 deletions
diff --git a/iemnet.c b/iemnet.c
index bd8a15c..42513f5 100644
--- a/iemnet.c
+++ b/iemnet.c
@@ -51,9 +51,48 @@ void iemnet__streamout(t_outlet*outlet, int argc, t_atom*argv) {
outlet_list(outlet, gensym("list"), 1, argv);
argv++;
}
+}
+
+typedef struct _names {
+ t_symbol*name;
+ struct _names*next;
+} t_iemnet_names;
+static t_iemnet_names*namelist=0;
+static int iemnet__nametaken(const char*namestring) {
+ t_symbol*name=gensym(namestring);
+ t_iemnet_names*curname=namelist;
+ t_iemnet_names*lastname=curname;
+ while(curname) {
+ if(name==(curname->name)) {
+ return 1;
+ }
+ lastname=curname;
+ curname=curname->next;
+ }
+
+ // new name!
+ curname=(t_iemnet_names*)getbytes(sizeof(t_iemnet_names));
+ curname->name=name;
+ curname->next=0;
+
+ if(lastname)
+ lastname->next=curname;
+ else
+ namelist=curname;
+ return 0;
}
+int iemnet__register(const char*name) {
+ if(iemnet__nametaken(name))return 0;
+ post("iemnet: networking with Pd :: %s", name);
+ post(" (c) 2010 IOhannes m zmoelnig, IEM");
+ post(" based on mrpeach/net, based on maxlib");
+ return 1;
+}
+
+
+
#ifdef _MSC_VER
void tcpclient_setup(void);
diff --git a/iemnet.h b/iemnet.h
index a484ccd..38e4bec 100644
--- a/iemnet.h
+++ b/iemnet.h
@@ -245,7 +245,6 @@ void iemnet__socketout(t_outlet*status_outlet, t_outlet*socket_outlet, int sockf
*/
void iemnet__numconnout(t_outlet*status_outlet, t_outlet*numconn_outlet, int numconnections);
-
/**
* output a list as a stream (serialize)
*
@@ -259,6 +258,18 @@ void iemnet__numconnout(t_outlet*status_outlet, t_outlet*numconn_outlet, int num
*/
void iemnet__streamout(t_outlet*outlet, int argc, t_atom*argv);
+/**
+ * register an objectname and printout a banner
+ *
+ * this will printout a copyright notice
+ * additionally, it will return whether it has already been called for the given name
+ *
+ * \param name an objectname to "register"
+ * \return 1 if this function has been called the first time with the given name, 0 otherwise
+ *
+ */
+int iemnet__register(const char*name);
+
#if defined(_MSC_VER)
# define snprintf _snprintf
diff --git a/tcpclient.c b/tcpclient.c
index b7af925..35dc2e8 100644
--- a/tcpclient.c
+++ b/tcpclient.c
@@ -270,7 +270,7 @@ static void tcpclient_free(t_tcpclient *x)
IEMNET_EXTERN void tcpclient_setup(void)
{
- static int again=0; if(again)return; again=1;
+ if(!iemnet__register(objName))return;
tcpclient_class = class_new(gensym(objName), (t_newmethod)tcpclient_new,
(t_method)tcpclient_free,
sizeof(t_tcpclient), 0, A_DEFFLOAT, 0);
@@ -281,13 +281,6 @@ IEMNET_EXTERN void tcpclient_setup(void)
class_addlist(tcpclient_class, (t_method)tcpclient_send);
class_addbang(tcpclient_class, (t_method)tcpclient_info);
-
-
-
-
- post("iemnet: networking with Pd :: %s", objName);
- post(" (c) 2010 IOhannes m zmoelnig, IEM");
- post(" based on mrpeach/net, based on maxlib");
}
diff --git a/tcpreceive.c b/tcpreceive.c
index e44e088..a9d08dc 100644
--- a/tcpreceive.c
+++ b/tcpreceive.c
@@ -125,7 +125,7 @@ static void tcpreceive_connectpoll(t_tcpreceive *x)
int fd;
fd = accept(x->x_connectsocket, (struct sockaddr *)&from, &fromlen);
- if (fd < 0) post("tcpreceive: accept failed");
+ if (fd < 0) error("[%s] accept failed", objName);
else
{
// t_socketreceiver *y = socketreceiver_new((void *)x,
@@ -143,7 +143,7 @@ static void tcpreceive_connectpoll(t_tcpreceive *x)
}
else
{
- error ("tcpreceive: Too many connections");
+ error ("[%s] Too many connections", objName);
sys_closesocket(fd);
}
}
@@ -258,7 +258,7 @@ static void tcpreceive_port(t_tcpreceive*x, t_floatarg fportno)
/* streaming protocol */
if (listen(sockfd, 5) < 0)
{
- sys_sockerror("tcpreceive: listen");
+ sys_sockerror("[tcpreceive] listen");
sys_closesocket(sockfd);
sockfd = -1;
outlet_anything(x->x_statout, gensym("port"), 1, ap);
@@ -319,19 +319,16 @@ static void *tcpreceive_new(t_floatarg fportno)
x->x_connection[i].port = 0;
}
-
-
-
-
tcpreceive_port(x, portno);
return (x);
}
-void tcpreceive_setup(void)
+IEMNET_EXTERN void tcpreceive_setup(void)
{
- tcpreceive_class = class_new(gensym("tcpreceive"),
+ if(!iemnet__register(objName))return;
+ tcpreceive_class = class_new(gensym(objName),
(t_newmethod)tcpreceive_new, (t_method)tcpreceive_free,
sizeof(t_tcpreceive),
0,
@@ -340,6 +337,9 @@ void tcpreceive_setup(void)
class_addmethod(tcpreceive_class, (t_method)tcpreceive_port, gensym("port"), A_DEFFLOAT, 0);
}
+IEMNET_INITIALIZER(tcpreceive_setup);
+
+
/* end x_net_tcpreceive.c */
diff --git a/tcpsend.c b/tcpsend.c
index 9277b57..8b2dd1e 100644
--- a/tcpsend.c
+++ b/tcpsend.c
@@ -22,6 +22,7 @@
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* */
+static const char objName[] = "tcpserver";
#include "iemnet.h"
#include <string.h>
@@ -135,9 +136,10 @@ static void *tcpsend_new(void)
return (x);
}
-void tcpsend_setup(void)
+IEMNET_EXTERN void tcpsend_setup(void)
{
- tcpsend_class = class_new(gensym("tcpsend"),
+ if(!iemnet__register(objName))return;
+ tcpsend_class = class_new(gensym(objName),
(t_newmethod)tcpsend_new, (t_method)tcpsend_free,
sizeof(t_tcpsend),
0, 0);
@@ -151,4 +153,7 @@ void tcpsend_setup(void)
class_addlist(tcpsend_class, (t_method)tcpsend_send);
}
+IEMNET_INITIALIZER(tcpsend_setup);
+
+
/* end tcpsend.c */
diff --git a/tcpserver.c b/tcpserver.c
index 15e1e4c..caa8611 100644
--- a/tcpserver.c
+++ b/tcpserver.c
@@ -33,7 +33,7 @@
/* ----------------------------- tcpserver ------------------------- */
static t_class *tcpserver_class;
-static char objName[] = "tcpserver";
+static const char objName[] = "tcpserver";
typedef struct _tcpserver_socketreceiver
{
@@ -608,7 +608,7 @@ static void tcpserver_free(t_tcpserver *x)
for(i = 0; i < MAX_CONNECT; i++)
{
if (NULL!=x->x_sr[i]) {
- DEBUG("tcpserver_free %x", x);
+ DEBUG("[%s] free %x", objName, x);
tcpserver_socketreceiver_free(x->x_sr[i]);
x->x_sr[i]=NULL;
}
@@ -622,7 +622,7 @@ static void tcpserver_free(t_tcpserver *x)
IEMNET_EXTERN void tcpserver_setup(void)
{
- static int again=0; if(again)return; again=1;
+ if(!iemnet__register(objName))return;
tcpserver_class = class_new(gensym(objName),(t_newmethod)tcpserver_new, (t_method)tcpserver_free,
sizeof(t_tcpserver), 0, A_DEFFLOAT, 0);
@@ -642,10 +642,6 @@ IEMNET_EXTERN void tcpserver_setup(void)
class_addmethod(tcpserver_class, (t_method)tcpserver_port, gensym("port"), A_DEFFLOAT, 0);
class_addbang (tcpserver_class, (t_method)tcpserver_info);
-
- post("iemnet: networking with Pd :: %s", objName);
- post(" (c) 2010 IOhannes m zmoelnig, IEM");
- post(" based on mrpeach/net, based on maxlib");
}
IEMNET_INITIALIZER(tcpserver_setup);
diff --git a/udpclient.c b/udpclient.c
index 0c72266..9a14c08 100644
--- a/udpclient.c
+++ b/udpclient.c
@@ -30,7 +30,7 @@
static t_class *udpclient_class;
-static char objName[] = "udpclient";
+static const char objName[] = "udpclient";
typedef struct _udpclient
@@ -78,7 +78,7 @@ static void *udpclient_child_connect(void *w)
if (x->x_sender)
{
- error("udpsend: already connected");
+ error("[%s] already connected", objName);
return (x);
}
@@ -87,7 +87,7 @@ static void *udpclient_child_connect(void *w)
DEBUG("send socket %d\n", sockfd);
if (sockfd < 0)
{
- sys_sockerror("udpsend: socket");
+ sys_sockerror("udpclient: socket");
return (x);
}
@@ -96,7 +96,7 @@ static void *udpclient_child_connect(void *w)
#ifdef SO_BROADCAST
if( 0 != setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, (const void *)&broadcast, sizeof(broadcast)))
{
- error("udpsend: couldn't switch to broadcast mode");
+ error("[%s] couldn't switch to broadcast mode", objName);
}
#endif /* SO_BROADCAST */
@@ -105,7 +105,7 @@ static void *udpclient_child_connect(void *w)
hp = gethostbyname(x->x_hostname);
if (hp == 0)
{
- error("udpsend: bad host '%s'?", x->x_hostname);
+ error("[%s] bad host '%s'?", objName, x->x_hostname);
return (x);
}
memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
@@ -117,7 +117,7 @@ static void *udpclient_child_connect(void *w)
/* try to connect. */
if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) < 0)
{
- sys_sockerror("udpsend: connecting stream socket");
+ sys_sockerror("udpclient: connecting stream socket");
sys_closesocket(sockfd);
return (x);
}
@@ -237,9 +237,7 @@ static void udpclient_free(t_udpclient *x)
IEMNET_EXTERN void udpclient_setup(void)
{
- post("udpclient");
- //static int again=0; if(again)return; again=1;
-
+ if(!iemnet__register(objName))return;
udpclient_class = class_new(gensym(objName), (t_newmethod)udpclient_new,
(t_method)udpclient_free,
sizeof(t_udpclient), 0, A_DEFFLOAT, 0);
@@ -248,10 +246,6 @@ IEMNET_EXTERN void udpclient_setup(void)
class_addmethod(udpclient_class, (t_method)udpclient_disconnect, gensym("disconnect"), 0);
class_addmethod(udpclient_class, (t_method)udpclient_send, gensym("send"), A_GIMME, 0);
class_addlist(udpclient_class, (t_method)udpclient_send);
-
- post("iemnet: networking with Pd :: %s", objName);
- post(" (c) 2010 IOhannes m zmoelnig, IEM");
- post(" based on mrpeach/net, based on maxlib");
}
diff --git a/udpreceive.c b/udpreceive.c
index ede632d..bf933f4 100644
--- a/udpreceive.c
+++ b/udpreceive.c
@@ -22,11 +22,9 @@
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* */
+static const char objName[] = "udpreceive";
#include "iemnet.h"
-#ifndef _WIN32
-# include <netinet/tcp.h>
-#endif
/* ----------------------------- udpreceive ------------------------- */
@@ -50,7 +48,7 @@ static void udpreceive_read_callback(void*y,
iemnet__addrout(NULL, x->x_addrout, c->addr, c->port);
outlet_list(x->x_msgout, gensym("list"), argc, argv);
} else {
- post("nothing received");
+ post("[%s] nothing received", objName);
}
}
@@ -77,7 +75,7 @@ static void *udpreceive_new(t_floatarg fportno)
intarg = 1;
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
(char *)&intarg, sizeof(intarg)) < 0)
- post("udpreceive: setsockopt (SO_REUSEADDR) failed");
+ error("[%s] setsockopt (SO_REUSEADDR) failed", objName);
/* assign server port number */
server.sin_port = htons((u_short)portno);
@@ -110,11 +108,14 @@ static void udpreceive_free(t_udpreceive *x)
x->x_connectsocket=0;
}
-void udpreceive_setup(void)
+IEMNET_EXTERN void udpreceive_setup(void)
{
- udpreceive_class = class_new(gensym("udpreceive"),
+ if(!iemnet__register(objName))return;
+ udpreceive_class = class_new(gensym(objName),
(t_newmethod)udpreceive_new, (t_method)udpreceive_free,
sizeof(t_udpreceive), CLASS_NOINLET, A_DEFFLOAT, 0);
}
+IEMNET_INITIALIZER(udpreceive_setup);
+
/* end udpreceive.c */
diff --git a/udpsend.c b/udpsend.c
index 8751ddb..6544071 100644
--- a/udpsend.c
+++ b/udpsend.c
@@ -22,6 +22,8 @@
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* */
+static const char objName[] = "udpsend";
+
#include "iemnet.h"
#include <string.h>
@@ -44,7 +46,7 @@ static void udpsend_connect(t_udpsend *x, t_symbol *hostname,
if (x->x_sender)
{
- error("udpsend: already connected");
+ error("[%s] already connected", objName);
return;
}
@@ -53,7 +55,7 @@ static void udpsend_connect(t_udpsend *x, t_symbol *hostname,
DEBUG("send socket %d\n", sockfd);
if (sockfd < 0)
{
- sys_sockerror("udpsend: socket");
+ sys_sockerror("[udpsend] socket");
return;
}
@@ -62,7 +64,7 @@ static void udpsend_connect(t_udpsend *x, t_symbol *hostname,
#ifdef SO_BROADCAST
if( 0 != setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, (const void *)&broadcast, sizeof(broadcast)))
{
- error("udpsend: couldn't switch to broadcast mode");
+ error("[%s] couldn't switch to broadcast mode", objName);
}
#endif /* SO_BROADCAST */
@@ -71,7 +73,7 @@ static void udpsend_connect(t_udpsend *x, t_symbol *hostname,
hp = gethostbyname(hostname->s_name);
if (hp == 0)
{
- error("udpsend: bad host '%s'?", hostname->s_name);
+ error("[%s] bad host '%s'?", objName, hostname->s_name);
return;
}
memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
@@ -83,7 +85,7 @@ static void udpsend_connect(t_udpsend *x, t_symbol *hostname,
/* try to connect. */
if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) < 0)
{
- sys_sockerror("udpsend: connecting stream socket");
+ sys_sockerror("[udpsend] connecting stream socket");
sys_closesocket(sockfd);
return;
}
@@ -107,7 +109,7 @@ static void udpsend_send(t_udpsend *x, t_symbol *s, int argc, t_atom *argv)
iemnet__sender_send(x->x_sender, chunk);
iemnet__chunk_destroy(chunk);
} else {
- error("udpsend: not connected");
+ error("[%s]: not connected");
}
}
@@ -124,9 +126,10 @@ static void *udpsend_new(void)
return (x);
}
-void udpsend_setup(void)
+IEMNET_EXTERN void udpsend_setup(void)
{
- udpsend_class = class_new(gensym("udpsend"), (t_newmethod)udpsend_new,
+ if(!iemnet__register(objName))return;
+ udpsend_class = class_new(gensym(objName), (t_newmethod)udpsend_new,
(t_method)udpsend_free,
sizeof(t_udpsend), 0, 0);
@@ -140,5 +143,7 @@ void udpsend_setup(void)
class_addlist(udpsend_class, (t_method)udpsend_send);
}
+IEMNET_INITIALIZER(udpsend_setup);
+
/* end udpsend.c*/