diff options
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/x_net.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/src/x_net.c | 116 |
1 files changed, 114 insertions, 2 deletions
diff --git a/apps/plugins/pdbox/PDa/src/x_net.c b/apps/plugins/pdbox/PDa/src/x_net.c index c4a004cc5c..aa19f78ec0 100644 --- a/apps/plugins/pdbox/PDa/src/x_net.c +++ b/apps/plugins/pdbox/PDa/src/x_net.c | |||
@@ -2,11 +2,17 @@ | |||
2 | * For information on usage and redistribution, and for a DISCLAIMER OF ALL | 2 | * For information on usage and redistribution, and for a DISCLAIMER OF ALL |
3 | * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ | 3 | * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ |
4 | 4 | ||
5 | #ifdef ROCKBOX | ||
6 | #include "plugin.h" | ||
7 | #include "pdbox.h" | ||
8 | #endif | ||
9 | |||
5 | /* network */ | 10 | /* network */ |
6 | 11 | ||
7 | #include "m_pd.h" | 12 | #include "m_pd.h" |
8 | #include "s_stuff.h" | 13 | #include "s_stuff.h" |
9 | 14 | ||
15 | #ifndef ROCKBOX | ||
10 | #include <sys/types.h> | 16 | #include <sys/types.h> |
11 | #include <string.h> | 17 | #include <string.h> |
12 | #ifdef UNIX | 18 | #ifdef UNIX |
@@ -19,6 +25,7 @@ | |||
19 | #else | 25 | #else |
20 | #include <winsock.h> | 26 | #include <winsock.h> |
21 | #endif | 27 | #endif |
28 | #endif /* ROCKBOX */ | ||
22 | 29 | ||
23 | static t_class *netsend_class; | 30 | static t_class *netsend_class; |
24 | 31 | ||
@@ -31,16 +38,27 @@ typedef struct _netsend | |||
31 | 38 | ||
32 | static void *netsend_new(t_floatarg udpflag) | 39 | static void *netsend_new(t_floatarg udpflag) |
33 | { | 40 | { |
41 | #ifdef ROCKBOX | ||
42 | (void) udpflag; | ||
43 | #endif | ||
44 | |||
34 | t_netsend *x = (t_netsend *)pd_new(netsend_class); | 45 | t_netsend *x = (t_netsend *)pd_new(netsend_class); |
35 | outlet_new(&x->x_obj, &s_float); | 46 | outlet_new(&x->x_obj, &s_float); |
36 | x->x_fd = -1; | 47 | x->x_fd = -1; |
48 | #ifndef ROCKBOX | ||
37 | x->x_protocol = (udpflag != 0 ? SOCK_DGRAM : SOCK_STREAM); | 49 | x->x_protocol = (udpflag != 0 ? SOCK_DGRAM : SOCK_STREAM); |
50 | #endif | ||
38 | return (x); | 51 | return (x); |
39 | } | 52 | } |
40 | 53 | ||
41 | static void netsend_connect(t_netsend *x, t_symbol *hostname, | 54 | static void netsend_connect(t_netsend *x, t_symbol *hostname, |
42 | t_floatarg fportno) | 55 | t_floatarg fportno) |
43 | { | 56 | { |
57 | #ifdef ROCKBOX | ||
58 | (void) x; | ||
59 | (void) hostname; | ||
60 | (void) fportno; | ||
61 | #else /* ROCKBOX */ | ||
44 | struct sockaddr_in server; | 62 | struct sockaddr_in server; |
45 | struct hostent *hp; | 63 | struct hostent *hp; |
46 | int sockfd; | 64 | int sockfd; |
@@ -100,13 +118,16 @@ static void netsend_connect(t_netsend *x, t_symbol *hostname, | |||
100 | } | 118 | } |
101 | x->x_fd = sockfd; | 119 | x->x_fd = sockfd; |
102 | outlet_float(x->x_obj.ob_outlet, 1); | 120 | outlet_float(x->x_obj.ob_outlet, 1); |
121 | #endif /* ROCKBOX */ | ||
103 | } | 122 | } |
104 | 123 | ||
105 | static void netsend_disconnect(t_netsend *x) | 124 | static void netsend_disconnect(t_netsend *x) |
106 | { | 125 | { |
107 | if (x->x_fd >= 0) | 126 | if (x->x_fd >= 0) |
108 | { | 127 | { |
128 | #ifndef ROCKBOX | ||
109 | sys_closesocket(x->x_fd); | 129 | sys_closesocket(x->x_fd); |
130 | #endif | ||
110 | x->x_fd = -1; | 131 | x->x_fd = -1; |
111 | outlet_float(x->x_obj.ob_outlet, 0); | 132 | outlet_float(x->x_obj.ob_outlet, 0); |
112 | } | 133 | } |
@@ -114,6 +135,12 @@ static void netsend_disconnect(t_netsend *x) | |||
114 | 135 | ||
115 | static void netsend_send(t_netsend *x, t_symbol *s, int argc, t_atom *argv) | 136 | static void netsend_send(t_netsend *x, t_symbol *s, int argc, t_atom *argv) |
116 | { | 137 | { |
138 | #ifdef ROCKBOX | ||
139 | (void) x; | ||
140 | (void) s; | ||
141 | (void) argc; | ||
142 | (void) argv; | ||
143 | #else /* ROCKBOX */ | ||
117 | if (x->x_fd >= 0) | 144 | if (x->x_fd >= 0) |
118 | { | 145 | { |
119 | t_binbuf *b = binbuf_new(); | 146 | t_binbuf *b = binbuf_new(); |
@@ -159,11 +186,16 @@ static void netsend_send(t_netsend *x, t_symbol *s, int argc, t_atom *argv) | |||
159 | binbuf_free(b); | 186 | binbuf_free(b); |
160 | } | 187 | } |
161 | else error("netsend: not connected"); | 188 | else error("netsend: not connected"); |
189 | #endif /* ROCKBOX */ | ||
162 | } | 190 | } |
163 | 191 | ||
164 | static void netsend_free(t_netsend *x) | 192 | static void netsend_free(t_netsend *x) |
165 | { | 193 | { |
194 | #ifdef ROCKBOX | ||
195 | (void) x; | ||
196 | #else | ||
166 | netsend_disconnect(x); | 197 | netsend_disconnect(x); |
198 | #endif | ||
167 | } | 199 | } |
168 | 200 | ||
169 | static void netsend_setup(void) | 201 | static void netsend_setup(void) |
@@ -193,14 +225,23 @@ typedef struct _netreceive | |||
193 | int x_udp; | 225 | int x_udp; |
194 | } t_netreceive; | 226 | } t_netreceive; |
195 | 227 | ||
228 | #ifdef ROCKBOX | ||
229 | static t_netreceive* receiver; | ||
230 | static int receiver_port; | ||
231 | #endif /* ROCKBOX */ | ||
232 | |||
233 | #ifndef ROCKBOX | ||
196 | static void netreceive_notify(t_netreceive *x) | 234 | static void netreceive_notify(t_netreceive *x) |
197 | { | 235 | { |
198 | outlet_float(x->x_connectout, --x->x_nconnections); | 236 | outlet_float(x->x_connectout, --x->x_nconnections); |
199 | } | 237 | } |
238 | #endif /* ROCKBOX */ | ||
200 | 239 | ||
201 | static void netreceive_doit(void *z, t_binbuf *b) | 240 | static void netreceive_doit(void *z, t_binbuf *b) |
202 | { | 241 | { |
242 | #ifndef ROCKBOX | ||
203 | t_atom messbuf[1024]; | 243 | t_atom messbuf[1024]; |
244 | #endif | ||
204 | t_netreceive *x = (t_netreceive *)z; | 245 | t_netreceive *x = (t_netreceive *)z; |
205 | int msg, natom = binbuf_getnatom(b); | 246 | int msg, natom = binbuf_getnatom(b); |
206 | t_atom *at = binbuf_getvec(b); | 247 | t_atom *at = binbuf_getvec(b); |
@@ -234,6 +275,7 @@ static void netreceive_doit(void *z, t_binbuf *b) | |||
234 | } | 275 | } |
235 | } | 276 | } |
236 | 277 | ||
278 | #ifndef ROCKBOX | ||
237 | static void netreceive_connectpoll(t_netreceive *x) | 279 | static void netreceive_connectpoll(t_netreceive *x) |
238 | { | 280 | { |
239 | int fd = accept(x->x_connectsocket, 0, 0); | 281 | int fd = accept(x->x_connectsocket, 0, 0); |
@@ -247,11 +289,41 @@ static void netreceive_connectpoll(t_netreceive *x) | |||
247 | outlet_float(x->x_connectout, ++x->x_nconnections); | 289 | outlet_float(x->x_connectout, ++x->x_nconnections); |
248 | } | 290 | } |
249 | } | 291 | } |
292 | #endif | ||
250 | 293 | ||
251 | static void *netreceive_new(t_symbol *compatflag, | 294 | static void *netreceive_new(t_symbol *compatflag, |
252 | t_floatarg fportno, t_floatarg udpflag) | 295 | t_floatarg fportno, t_floatarg udpflag) |
253 | { | 296 | { |
254 | t_netreceive *x; | 297 | t_netreceive *x; |
298 | |||
299 | #ifdef ROCKBOX | ||
300 | int portno = fportno, udp = (udpflag != 0); | ||
301 | |||
302 | (void) compatflag; | ||
303 | |||
304 | /* Look whether callback is already taken. */ | ||
305 | if(receiver) | ||
306 | { | ||
307 | post("Receiver callback already taken!\n"); | ||
308 | return NULL; | ||
309 | } | ||
310 | |||
311 | /* Look whether TCP sockets are thought to exist. */ | ||
312 | if(!udp) | ||
313 | { | ||
314 | post("Trying to create TCP socket!\n"); | ||
315 | return NULL; | ||
316 | } | ||
317 | |||
318 | x = (t_netreceive *) pd_new(netreceive_class); | ||
319 | x->x_msgout = outlet_new(&x->x_obj, &s_anything); | ||
320 | x->x_nconnections = 0; | ||
321 | x->x_udp = udp; | ||
322 | |||
323 | receiver = x; | ||
324 | receiver_port = portno; | ||
325 | |||
326 | #else /* ROCKBOX */ | ||
255 | struct sockaddr_in server; | 327 | struct sockaddr_in server; |
256 | int sockfd, portno = fportno, udp = (udpflag != 0); | 328 | int sockfd, portno = fportno, udp = (udpflag != 0); |
257 | int old = !strcmp(compatflag->s_name , "old"); | 329 | int old = !strcmp(compatflag->s_name , "old"); |
@@ -333,20 +405,62 @@ static void *netreceive_new(t_symbol *compatflag, | |||
333 | x->x_connectsocket = sockfd; | 405 | x->x_connectsocket = sockfd; |
334 | x->x_nconnections = 0; | 406 | x->x_nconnections = 0; |
335 | x->x_udp = udp; | 407 | x->x_udp = udp; |
408 | #endif /* ROCKBOX */ | ||
336 | 409 | ||
337 | return (x); | 410 | return (x); |
338 | } | 411 | } |
339 | 412 | ||
340 | static void netreceive_free(t_netreceive *x) | 413 | static void netreceive_free(t_netreceive *x) |
341 | { | 414 | { |
415 | #ifdef ROCKBOX | ||
416 | if(receiver && receiver == x) | ||
417 | receiver = NULL; | ||
418 | #else /* ROCKBOX */ | ||
342 | /* LATER make me clean up open connections */ | 419 | /* LATER make me clean up open connections */ |
343 | if (x->x_connectsocket >= 0) | 420 | if (x->x_connectsocket >= 0) |
344 | { | 421 | { |
345 | sys_rmpollfn(x->x_connectsocket); | 422 | sys_rmpollfn(x->x_connectsocket); |
346 | sys_closesocket(x->x_connectsocket); | 423 | sys_closesocket(x->x_connectsocket); |
347 | } | 424 | } |
425 | #endif /* ROCKBOX */ | ||
348 | } | 426 | } |
349 | 427 | ||
428 | #ifdef ROCKBOX | ||
429 | /* Basically a reimplementation of socketreceiver_getudp() | ||
430 | from s_inter.c */ | ||
431 | t_binbuf* inbinbuf; | ||
432 | void outlet_setstacklim(void); | ||
433 | |||
434 | void rockbox_receive_callback(struct datagram* dg) | ||
435 | { | ||
436 | /* Check whether there is a receiver. */ | ||
437 | if(!receiver) | ||
438 | return; | ||
439 | |||
440 | /* Limit string. */ | ||
441 | dg->data[dg->size] = '\0'; | ||
442 | |||
443 | /* If complete line... */ | ||
444 | if(dg->data[dg->size-1] == '\n') | ||
445 | { | ||
446 | char* semi = strchr(dg->data, ';'); | ||
447 | |||
448 | /* Limit message. */ | ||
449 | if(semi) | ||
450 | *semi = '\0'; | ||
451 | |||
452 | /* Create binary buffer. */ | ||
453 | binbuf_text(inbinbuf, dg->data, strlen(dg->data)); | ||
454 | |||
455 | /* Limit outlet stack. */ | ||
456 | outlet_setstacklim(); | ||
457 | |||
458 | /* Execute receive function. */ | ||
459 | netreceive_doit(receiver, inbinbuf); | ||
460 | } | ||
461 | } | ||
462 | #endif /* ROCKBOX */ | ||
463 | |||
350 | static void netreceive_setup(void) | 464 | static void netreceive_setup(void) |
351 | { | 465 | { |
352 | netreceive_class = class_new(gensym("netreceive"), | 466 | netreceive_class = class_new(gensym("netreceive"), |
@@ -360,5 +474,3 @@ void x_net_setup(void) | |||
360 | netsend_setup(); | 474 | netsend_setup(); |
361 | netreceive_setup(); | 475 | netreceive_setup(); |
362 | } | 476 | } |
363 | |||
364 | |||