[PD-dev] problem compiling external
Martin Peach
martinrp at vax2.concordia.ca
Mon May 8 18:11:01 CEST 2006
michael gross wrote:
>hello
>
>i am new to writing pd externals and have some general questions.
>i am trying to write an external which establishes a socket connection to
>an other programm. when I try to compile the fallowing source it does not
>seem to work because of unlink, bind and accept. i create the socket in
>the constructor and try to write to it in the function connect_to. when i
>compile the source i get only warnings and no errors but it still fails to
>compile.
>
>
So what warnings do you get?
There should be at least one error too if it doesn't compile.
What is unlink(ADDRESS) doing in connect_to?
Martin
>i am using the makefile provided in
>/usr/lib/pd/doc/6.externs and gcc-3.4 for compilation.
>
>without the method connect compilation works fine.
>
>
>
>#include <sys/types.h>
>#include <sys/socket.h>
>#include <sys/un.h>
>#include <stdio.h>
>#include <sys/time.h>
>#define NSTRS 3 /* no. of strings */
>#define ADDRESS "myso" /* addr to connect */
>#include "m_pd.h"
>
>
>char c;
>FILE *fp;
>int fromlen;
>char *strs;
>int time;
>char string[50];
>int i, s, ns, len;
>struct sockaddr_un saun, fsaun;
>
>
>typedef struct obj1
>{
> t_object x_ob;
>} t_obj1;
>
>
>t_class *obj1_class;
>
>void *obj1_new(void)
>{
> if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
> post("no socket");
>
> }
>
> t_obj1 *x = (t_obj1 *)pd_new(obj1_class);
> post("obj1_new");
> return (void *)x;
>
>}
>
>void connect_to(t_obj1 *x)
>{
> saun.sun_family = AF_UNIX;
> strcpy(saun.sun_path, ADDRESS);
>
> unlink(ADDRESS);
>
> len = sizeof(saun.sun_family) + strlen(saun.sun_path);
>
>
> if (bind(s, &saun, len) < 0) {
>
> }
>
> if (listen(s, 5) < 0) {
> }
>
> if ((ns = accept(s, &fsaun, &fromlen)) < 0) {
> }
>
> fp = fdopen(ns, "r");
>
> send(ns, string, strlen(string), 0);
>
> close(s);
>
>}
>
>
>
>void obj1_setup(void)
>{
> post("obj1_setup");
> obj1_class = class_new(gensym("obj1"), (t_newmethod)obj1_new, 0,
> sizeof(t_obj1), 0, 0);
>
> class_addmethod(obj1_class, (t_method)connect_to,
>gensym("connect_to"), 0);
>}
>
>thank you for any help
>
>michael
>
>
>
>_______________________________________________
>PD-dev mailing list
>PD-dev at iem.at
>http://lists.puredata.info/listinfo/pd-dev
>
>
>
More information about the Pd-dev
mailing list