aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorMartin Peach <mrpeach@users.sourceforge.net>2006-11-07 21:20:20 +0000
committerMartin Peach <mrpeach@users.sourceforge.net>2006-11-07 21:20:20 +0000
commit9e84c5fa2d2704ac35d7ca5c600e80f8ae49c32d (patch)
treedb39e08ba6d7e5deaf0c83eb531da62eb3700d1b /net
parentbe9b6e3bc8622af69350918f3e1d4f90b333d0bb (diff)
added file send
svn path=/trunk/externals/mrpeach/; revision=6223
Diffstat (limited to 'net')
-rwxr-xr-xnet/tcpclient.c54
-rwxr-xr-xnet/tcpreceive.c6
-rwxr-xr-xnet/tcpsend.c58
-rwxr-xr-xnet/tcpserver.c53
-rwxr-xr-xnet/udpsend.c57
5 files changed, 171 insertions, 57 deletions
diff --git a/net/tcpclient.c b/net/tcpclient.c
index 366d421..9c19433 100755
--- a/net/tcpclient.c
+++ b/net/tcpclient.c
@@ -85,9 +85,6 @@ static void tcpclient_rcv(t_tcpclient *x);
static void tcpclient_poll(t_tcpclient *x);
static void *tcpclient_new(t_floatarg udpflag);
static void tcpclient_free(t_tcpclient *x);
-#ifdef MSW
-__declspec(dllexport)
-#endif
void tcpclient_setup(void);
static void tcpclient_dump(t_tcpclient *x, t_float dump)
@@ -219,8 +216,9 @@ static void tcpclient_disconnect(t_tcpclient *x)
static void tcpclient_send(t_tcpclient *x, t_symbol *s, int argc, t_atom *argv)
{
- static char byte_buf[65536];// arbitrary maximum similar to max IP packet size
- int i, d;
+#define BYTE_BUF_LEN 65536 // arbitrary maximum similar to max IP packet size
+ static char byte_buf[BYTE_BUF_LEN];
+ int i, j, d;
unsigned char c;
float f, e;
char *bp;
@@ -231,13 +229,15 @@ static void tcpclient_send(t_tcpclient *x, t_symbol *s, int argc, t_atom *argv)
double timebefore;
double timeafter;
int late;
+ char fpath[MAX_PATH];
+ FILE *fptr;
#ifdef DEBUG
post("s: %s", s->s_name);
post("argc: %d", argc);
#endif
- for (i = 0; i < argc; ++i)
+ for (i = j = 0; i < argc; ++i)
{
if (argv[i].a_type == A_FLOAT)
{
@@ -261,16 +261,49 @@ static void tcpclient_send(t_tcpclient *x, t_symbol *s, int argc, t_atom *argv)
#ifdef DEBUG
post("%s_send: argv[%d]: %d", objName, i, c);
#endif
- byte_buf[i] = c;
+ byte_buf[j++] = c;
+ }
+ else if (argv[i].a_type == A_SYMBOL)
+ {
+
+ atom_string(&argv[i], fpath, MAX_PATH);
+#ifdef DEBUG
+ post ("%s_send fname: %s", objName, fpath);
+#endif
+ fptr = fopen(fpath, "rb");
+ if (fptr == NULL)
+ {
+ post("%s_send: unable to open \"%s\"", objName, fpath);
+ return;
+ }
+ rewind(fptr);
+#ifdef DEBUG
+ post("%s_send: d is %d", objName, d);
+#endif
+ while ((d = fgetc(fptr)) != EOF)
+ {
+ byte_buf[j++] = (char)(d & 0x0FF);
+#ifdef DEBUG
+ post("%s_send: byte_buf[%d] = %d", objName, j-1, byte_buf[j-1]);
+#endif
+ if (j >= BYTE_BUF_LEN)
+ {
+ post ("%s_send: file too long, truncating at %lu", objName, BYTE_BUF_LEN);
+ break;
+ }
+ }
+ fclose(fptr);
+ fptr = NULL;
+ post("%s_send: read \"%s\" length %d byte%s", objName, fpath, j, ((d==1)?"":"s"));
}
else
{
- error("%s_send: item %d is not a float", objName, i);
+ error("%s_send: item %d is not a float or a file name", objName, i);
return;
}
}
- length = i;
+ length = j;
if ((x->x_fd >= 0) && (length > 0))
{
for (bp = byte_buf, sent = 0; sent < length;)
@@ -423,9 +456,6 @@ static void tcpclient_free(t_tcpclient *x)
clock_free(x->x_clock);
}
-#ifdef MSW
-__declspec(dllexport)
-#endif
void tcpclient_setup(void)
{
tcpclient_class = class_new(gensym(objName), (t_newmethod)tcpclient_new,
diff --git a/net/tcpreceive.c b/net/tcpreceive.c
index 4cce77d..9cbc791 100755
--- a/net/tcpreceive.c
+++ b/net/tcpreceive.c
@@ -46,9 +46,6 @@ typedef struct _tcpreceive
char x_msginbuf[MAX_UDP_RECEIVE];
} t_tcpreceive;
-#ifdef MSW
-__declspec(dllexport)
-#endif
void tcpreceive_setup(void);
static void tcpreceive_free(t_tcpreceive *x);
static void *tcpreceive_new(t_floatarg fportno);
@@ -300,9 +297,6 @@ static void tcpreceive_free(t_tcpreceive *x)
tcpreceive_closeall(x);
}
-#ifdef MSW
-__declspec(dllexport)
-#endif
void tcpreceive_setup(void)
{
tcpreceive_class = class_new(gensym("tcpreceive"),
diff --git a/net/tcpsend.c b/net/tcpsend.c
index cf8c33d..13e707c 100755
--- a/net/tcpsend.c
+++ b/net/tcpsend.c
@@ -7,6 +7,8 @@
#include "m_pd.h"
#include "s_stuff.h"
+#include <stdio.h>
+#include <string.h>
#ifdef MSW
#include <winsock2.h>
@@ -16,8 +18,6 @@
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
-#include <stdio.h>
-#include <string.h>
#endif
static t_class *tcpsend_class;
@@ -28,9 +28,6 @@ typedef struct _tcpsend
int x_fd;
} t_tcpsend;
-#ifdef MSW
-__declspec(dllexport)
-#endif
void tcpsend_setup(void);
static void tcpsend_free(t_tcpsend *x);
static void tcpsend_send(t_tcpsend *x, t_symbol *s, int argc, t_atom *argv);
@@ -115,8 +112,9 @@ static void tcpsend_disconnect(t_tcpsend *x)
static void tcpsend_send(t_tcpsend *x, t_symbol *s, int argc, t_atom *argv)
{
- static char byte_buf[65536];// arbitrary maximum similar to max IP packet size
- int i, d;
+#define BYTE_BUF_LEN 65536 // arbitrary maximum similar to max IP packet size
+ static char byte_buf[BYTE_BUF_LEN];
+ int i, j, d;
char c;
float f, e;
char *bp;
@@ -127,12 +125,14 @@ static void tcpsend_send(t_tcpsend *x, t_symbol *s, int argc, t_atom *argv)
double timebefore;
double timeafter;
int late;
+ char fpath[MAX_PATH];
+ FILE *fptr;
#ifdef DEBUG
post("s: %s", s->s_name);
post("argc: %d", argc);
#endif
- for (i = 0; i < argc; ++i)
+ for (i = j = 0; i < argc; ++i)
{
if (argv[i].a_type == A_FLOAT)
{
@@ -153,16 +153,49 @@ static void tcpsend_send(t_tcpsend *x, t_symbol *s, int argc, t_atom *argv)
#ifdef DEBUG
post("tcpsend_send: argv[%d]: %d", i, c);
#endif
- byte_buf[i] = c;
+ byte_buf[j++] = c;
+ }
+ else if (argv[i].a_type == A_SYMBOL)
+ {
+
+ atom_string(&argv[i], fpath, MAX_PATH);
+#ifdef DEBUG
+ post ("tcpsend fname: %s", fpath);
+#endif
+ fptr = fopen(fpath, "rb");
+ if (fptr == NULL)
+ {
+ post("tcpsend: unable to open \"%s\"", fpath);
+ return;
+ }
+ rewind(fptr);
+#ifdef DEBUG
+ post("tcpsend: d is %d", d);
+#endif
+ while ((d = fgetc(fptr)) != EOF)
+ {
+ byte_buf[j++] = (char)(d & 0x0FF);
+#ifdef DEBUG
+ post("tcpsend: byte_buf[%d] = %d", j-1, byte_buf[j-1]);
+#endif
+ if (j >= BYTE_BUF_LEN)
+ {
+ post ("tcpsend: file too long, truncating at %lu", BYTE_BUF_LEN);
+ break;
+ }
+ }
+ fclose(fptr);
+ fptr = NULL;
+ post("tcpsend: read \"%s\" length %d byte%s", fpath, j, ((d==1)?"":"s"));
}
else
{
- error("tcpsend_send: item %d is not a float", i);
+ error("tcpsend_send: item %d is not a float or a file name", i);
return;
}
}
- length = i;
+ length = j;
if ((x->x_fd >= 0) && (length > 0))
{
for (bp = byte_buf, sent = 0; sent < length;)
@@ -203,9 +236,6 @@ static void tcpsend_free(t_tcpsend *x)
tcpsend_disconnect(x);
}
-#ifdef MSW
-__declspec(dllexport)
-#endif
void tcpsend_setup(void)
{
tcpsend_class = class_new(gensym("tcpsend"), (t_newmethod)tcpsend_new,
diff --git a/net/tcpserver.c b/net/tcpserver.c
index f6526c0..97cd577 100755
--- a/net/tcpserver.c
+++ b/net/tcpserver.c
@@ -37,7 +37,7 @@
//#include <fcntl.h>
//#include <errno.h>
//#include <string.h>
-//#include <stdio.h>
+#include <stdio.h>
//#include <pthread.h>
#if defined(UNIX) || defined(unix)
#include <sys/socket.h>
@@ -111,9 +111,6 @@ static void tcpserver_connectpoll(t_tcpserver *x);
static void tcpserver_print(t_tcpserver *x);
static void *tcpserver_new(t_floatarg fportno);
static void tcpserver_free(t_tcpserver *x);
-#ifdef MSW
-__declspec(dllexport)
-#endif
void tcpserver_setup(void);
static t_tcpserver_socketreceiver *tcpserver_socketreceiver_new(void *owner, t_tcpserver_socketnotifier notifier,
@@ -246,7 +243,7 @@ static void tcpserver_socketreceiver_free(t_tcpserver_socketreceiver *x)
static void tcp_server_send_bytes(int client, t_tcpserver *x, int argc, t_atom *argv)
{
static char byte_buf[MAX_UDP_RECEIVE];// arbitrary maximum similar to max IP packet size
- int i, d;
+ int i, j, d;
unsigned char c;
float f, e;
char *bp;
@@ -258,11 +255,13 @@ static void tcp_server_send_bytes(int client, t_tcpserver *x, int argc, t_atom *
double timeafter;
int late;
int sockfd = x->x_fd[client];
+ char fpath[MAX_PATH];
+ FILE *fptr;
/* process & send data */
if(sockfd >= 0)
{
- for (i = 0; i < argc; ++i)
+ for (i = j = 0; i < argc; ++i)
{
if (argv[i].a_type == A_FLOAT)
{
@@ -286,15 +285,48 @@ static void tcp_server_send_bytes(int client, t_tcpserver *x, int argc, t_atom *
#ifdef DEBUG
post("%s: argv[%d]: %d", objName, i, c);
#endif
- byte_buf[i] = c;
+ byte_buf[j++] = c;
+ }
+ else if (argv[i].a_type == A_SYMBOL)
+ {
+
+ atom_string(&argv[i], fpath, MAX_PATH);
+#ifdef DEBUG
+ post ("%s: fname: %s", objName, fpath);
+#endif
+ fptr = fopen(fpath, "rb");
+ if (fptr == NULL)
+ {
+ post("%s: unable to open \"%s\"", objName, fpath);
+ return;
+ }
+ rewind(fptr);
+#ifdef DEBUG
+ post("%s: d is %d", objName, d);
+#endif
+ while ((d = fgetc(fptr)) != EOF)
+ {
+ byte_buf[j++] = (char)(d & 0x0FF);
+#ifdef DEBUG
+ post("%s: byte_buf[%d] = %d", objName, j-1, byte_buf[j-1]);
+#endif
+ if (j >= MAX_UDP_RECEIVE)
+ {
+ post ("%s: file too long, truncating at %lu", objName, MAX_UDP_RECEIVE);
+ break;
+ }
+ }
+ fclose(fptr);
+ fptr = NULL;
+ post("%s: read \"%s\" length %d byte%s", objName, fpath, j, ((d==1)?"":"s"));
}
else
{
- error("%s: item %d is not a float", objName, i);
+ error("%s: item %d is not a float or a file name", objName, i);
return;
}
}
- length = i;
+ length = j;
if (length > 0)
{
for (bp = byte_buf, sent = 0; sent < length;)
@@ -603,9 +635,6 @@ static void tcpserver_free(t_tcpserver *x)
binbuf_free(inbinbuf);
}
-#ifdef MSW
-__declspec(dllexport)
-#endif
void tcpserver_setup(void)
{
tcpserver_class = class_new(gensym(objName),(t_newmethod)tcpserver_new, (t_method)tcpserver_free,
diff --git a/net/udpsend.c b/net/udpsend.c
index 7b468f9..d82acf6 100755
--- a/net/udpsend.c
+++ b/net/udpsend.c
@@ -28,9 +28,6 @@ typedef struct _udpsend
int x_fd;
} t_udpsend;
-#ifdef MSW
-__declspec(dllexport)
-#endif
void udpsend_setup(void);
static void udpsend_free(t_udpsend *x);
static void udpsend_send(t_udpsend *x, t_symbol *s, int argc, t_atom *argv);
@@ -107,8 +104,10 @@ static void udpsend_disconnect(t_udpsend *x)
static void udpsend_send(t_udpsend *x, t_symbol *s, int argc, t_atom *argv)
{
- static char byte_buf[65536];// arbitrary maximum similar to max IP packet size
- int i, d;
+#define BYTE_BUF_LEN 65536 // arbitrary maximum similar to max IP packet size
+ static char byte_buf[BYTE_BUF_LEN];
+ int d;
+ int i, j;
char c;
float f, e;
char *bp;
@@ -119,12 +118,14 @@ static void udpsend_send(t_udpsend *x, t_symbol *s, int argc, t_atom *argv)
double timebefore;
double timeafter;
int late;
+ char fpath[MAX_PATH];
+ FILE *fptr;
#ifdef DEBUG
post("s: %s", s->s_name);
post("argc: %d", argc);
#endif
- for (i = 0; i < argc; ++i)
+ for (i = j = 0; i < argc; ++i)
{
if (argv[i].a_type == A_FLOAT)
{
@@ -145,16 +146,49 @@ static void udpsend_send(t_udpsend *x, t_symbol *s, int argc, t_atom *argv)
#ifdef DEBUG
post("udpsend_send: argv[%d]: %d", i, c);
#endif
- byte_buf[i] = c;
+ byte_buf[j++] = c;
+ }
+ else if (argv[i].a_type == A_SYMBOL)
+ {
+
+ atom_string(&argv[i], fpath, MAX_PATH);
+#ifdef DEBUG
+ post ("udpsend fname: %s", fpath);
+#endif
+ fptr = fopen(fpath, "rb");
+ if (fptr == NULL)
+ {
+ post("udpsend: unable to open \"%s\"", fpath);
+ return;
+ }
+ rewind(fptr);
+#ifdef DEBUG
+ post("udpsend: d is %d", d);
+#endif
+ while ((d = fgetc(fptr)) != EOF)
+ {
+ byte_buf[j++] = (char)(d & 0x0FF);
+#ifdef DEBUG
+ post("udpsend: byte_buf[%d] = %d", j-1, byte_buf[j-1]);
+#endif
+ if (j >= BYTE_BUF_LEN)
+ {
+ post ("udpsend: file too long, truncating at %lu", BYTE_BUF_LEN);
+ break;
+ }
+ }
+ fclose(fptr);
+ fptr = NULL;
+ post("udpsend: read \"%s\" length %d byte%s", fpath, j, ((d==1)?"":"s"));
}
else
- {
- error("udpsend_send: item %d is not a float", i);
+ {
+ error("udpsend_send: item %d is not a float or a file name", i);
return;
}
}
- length = i;
+ length = j;
if ((x->x_fd >= 0) && (length > 0))
{
for (bp = byte_buf, sent = 0; sent < length;)
@@ -195,9 +229,6 @@ static void udpsend_free(t_udpsend *x)
udpsend_disconnect(x);
}
-#ifdef MSW
-__declspec(dllexport)
-#endif
void udpsend_setup(void)
{
udpsend_class = class_new(gensym("udpsend"), (t_newmethod)udpsend_new,