diff --git a/overlay.c b/overlay.c index 6bdfb589..119c3ea2 100644 --- a/overlay.c +++ b/overlay.c @@ -133,6 +133,7 @@ int overlayServerMode() fdcount=1; rhizome_server_get_fds(fds,&fdcount,128); rhizome_fetching_get_fds(fds,&fdcount,128); + overlay_mdp_get_fds(fds,&fdcount,128); for(i=0;i-1) { - int dud=0; - int r=bind(mdp_abstract_socket, (struct sockaddr *)&name, len); - if (r) { dud=1; r=0; WHY("bind() of abstract name space socket failed (not an error on non-linux systems"); } - r=listen(mdp_abstract_socket,100); // allow a lot of queued up MDP frames - if (r) { dud++; WHY("listen() failed"); } - if (dud) { - close(mdp_abstract_socket); - mdp_abstract_socket=-1; - WHY("Could not open abstract name-space socket (only a problem on Linux)."); + if (mdp_abstract_socket==-1) { + /* Abstract name space unix sockets is a special Linux thing, which is + convenient for us because Android is Linux, but does not have a shared + writable path that is on a UFS partition, so we cannot use traditional + named unix domain sockets. So the abstract name space gives us a solution. */ + name.sun_path[0]=0; + /* XXX The 100 should be replaced with the actual maximum allowed. + Apparently POSIX requires it to be at least 100, but I would still feel + more comfortable with using the appropriate constant. */ + snprintf(&name.sun_path[1],100,"org.servalproject.mesh.overlay.mdp"); + len = 1+strlen(&name.sun_path[1]) + sizeof(name.sun_family); + + mdp_abstract_socket = socket(AF_UNIX, SOCK_STREAM, 0); + if (mdp_abstract_socket>-1) { + int dud=0; + int r=bind(mdp_abstract_socket, (struct sockaddr *)&name, len); + if (r) { dud=1; r=0; WHY("bind() of abstract name space socket failed (not an error on non-linux systems"); } + r=listen(mdp_abstract_socket,100); // allow a lot of queued up MDP frames + if (r) { dud++; WHY("listen() failed"); } + if (dud) { + close(mdp_abstract_socket); + mdp_abstract_socket=-1; + WHY("Could not open abstract name-space socket (only a problem on Linux)."); + } } } #endif - char *instancepath=serval_instancepath(); - - snprintf(&name.sun_path[0],100,"%s/mdp.socket",instancepath); - len = 0+strlen(&name.sun_path[0]) + sizeof(name.sun_family); - mdp_named_socket = socket(AF_UNIX, SOCK_STREAM, 0); - if (mdp_named_socket>-1) { - int dud=0; - int r=bind(mdp_named_socket, (struct sockaddr *)&name, len); - if (r) { dud=1; r=0; WHY("bind() of named unix domain socket failed"); } - r=listen(mdp_named_socket,100); // allow a lot of queued up MDP frames - if (r) { dud++; WHY("listen() failed"); } - if (dud) { - close(mdp_named_socket); - mdp_named_socket=-1; - WHY("Could not open named unix domain socket."); + if (mdp_named_socket==-1) { + char *instancepath=serval_instancepath(); + snprintf(&name.sun_path[0],100,"%s/mdp.socket",instancepath); + len = 0+strlen(&name.sun_path[0]) + sizeof(name.sun_family); + mdp_named_socket = socket(AF_UNIX, SOCK_STREAM, 0); + if (mdp_named_socket>-1) { + int dud=0; + int r=bind(mdp_named_socket, (struct sockaddr *)&name, len); + if (r) { dud=1; r=0; WHY("bind() of named unix domain socket failed"); } + r=listen(mdp_named_socket,100); // allow a lot of queued up MDP frames + if (r) { dud++; WHY("listen() failed"); } + if (dud) { + close(mdp_named_socket); + mdp_named_socket=-1; + WHY("Could not open named unix domain socket."); + } } } @@ -79,7 +83,44 @@ int overlay_mdp_setup_sockets() } +int overlay_mdp_get_fds(struct pollfd *fds,int *fdcount,int fdmax) +{ + /* Make sure sockets are open */ + overlay_mdp_setup_sockets(); + + if ((*fdcount)>=fdmax) return -1; + if (mdp_abstract_socket>-1) + { + if (debug&DEBUG_IO) { + fprintf(stderr,"MDP abstract name space socket is poll() slot #%d (fd %d)\n", + *fdcount,mdp_abstract_socket); + } + fds[*fdcount].fd=mdp_abstract_socket; + fds[*fdcount].events=POLLIN; + (*fdcount)++; + } + if ((*fdcount)>=fdmax) return -1; + if (mdp_named_socket>-1) + { + if (debug&DEBUG_IO) { + fprintf(stderr,"MDP named unix domain socket is poll() slot #%d (fd %d)\n", + *fdcount,mdp_named_socket); + } + fds[*fdcount].fd=mdp_named_socket; + fds[*fdcount].events=POLLIN; + (*fdcount)++; + } + + + return 0; +} + int overlay_saw_mdp_frame(int interface,overlay_frame *f,long long now) { return WHY("Not implemented"); } + +int overlay_mdp_poll() +{ + return WHY("Not implemented"); +} diff --git a/serval.h b/serval.h index 14088f04..6d966f54 100644 --- a/serval.h +++ b/serval.h @@ -981,3 +981,6 @@ int _memabuseCheck(const char *func,const char *file,const int line); char *thisinstancepath; char *serval_instancepath(); + +int overlay_mdp_get_fds(struct pollfd *fds,int *fdcount,int fdmax); +int overlay_mdp_poll();