aboutsummaryrefslogtreecommitdiff
path: root/net/tcpsend.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/tcpsend.c')
-rwxr-xr-xnet/tcpsend.c58
1 files changed, 44 insertions, 14 deletions
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,