Further preparatory work for MDP. Next stop is actually checking

for inbound MDP connection requests on the unix domain sockets.
This commit is contained in:
gardners 2012-03-17 13:02:09 +10:30
parent c59318cbab
commit f384e6ea79
3 changed files with 83 additions and 37 deletions

View File

@ -133,6 +133,7 @@ int overlayServerMode()
fdcount=1; fdcount=1;
rhizome_server_get_fds(fds,&fdcount,128); rhizome_server_get_fds(fds,&fdcount,128);
rhizome_fetching_get_fds(fds,&fdcount,128); rhizome_fetching_get_fds(fds,&fdcount,128);
overlay_mdp_get_fds(fds,&fdcount,128);
for(i=0;i<overlay_interface_count;i++) for(i=0;i<overlay_interface_count;i++)
{ {
@ -197,6 +198,7 @@ int overlayServerMode()
if (rhizome_datastore_path) { if (rhizome_datastore_path) {
rhizome_server_poll(); rhizome_server_poll();
rhizome_fetch_poll(); rhizome_fetch_poll();
overlay_mdp_poll();
} }
} else { } else {
/* No data before tick occurred, so do nothing. /* No data before tick occurred, so do nothing.

View File

@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "serval.h" #include "serval.h"
int mdp_abstract_socket=-1; int mdp_abstract_socket=-1;
int mdp_named_socket=-1; int mdp_named_socket=-1;
int overlay_mdp_setup_sockets() int overlay_mdp_setup_sockets()
@ -27,6 +28,12 @@ int overlay_mdp_setup_sockets()
name.sun_family = AF_UNIX; name.sun_family = AF_UNIX;
#ifndef HAVE_LINUX_IF_H
/* Abstrack name space (i.e., non-file represented) unix domain sockets are a
linux-only thing. */
mdp_abstract_socket = -1;
#else
if (mdp_abstract_socket==-1) {
/* Abstract name space unix sockets is a special Linux thing, which is /* 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 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 writable path that is on a UFS partition, so we cannot use traditional
@ -38,11 +45,6 @@ int overlay_mdp_setup_sockets()
snprintf(&name.sun_path[1],100,"org.servalproject.mesh.overlay.mdp"); snprintf(&name.sun_path[1],100,"org.servalproject.mesh.overlay.mdp");
len = 1+strlen(&name.sun_path[1]) + sizeof(name.sun_family); len = 1+strlen(&name.sun_path[1]) + sizeof(name.sun_family);
#ifndef HAVE_LINUX_IF_H
/* Abstrack name space (i.e., non-file represented) unix domain sockets are a
linux-only thing. */
mdp_abstract_socket = -1;
#else
mdp_abstract_socket = socket(AF_UNIX, SOCK_STREAM, 0); mdp_abstract_socket = socket(AF_UNIX, SOCK_STREAM, 0);
if (mdp_abstract_socket>-1) { if (mdp_abstract_socket>-1) {
int dud=0; int dud=0;
@ -56,9 +58,10 @@ int overlay_mdp_setup_sockets()
WHY("Could not open abstract name-space socket (only a problem on Linux)."); WHY("Could not open abstract name-space socket (only a problem on Linux).");
} }
} }
}
#endif #endif
if (mdp_named_socket==-1) {
char *instancepath=serval_instancepath(); char *instancepath=serval_instancepath();
snprintf(&name.sun_path[0],100,"%s/mdp.socket",instancepath); snprintf(&name.sun_path[0],100,"%s/mdp.socket",instancepath);
len = 0+strlen(&name.sun_path[0]) + sizeof(name.sun_family); len = 0+strlen(&name.sun_path[0]) + sizeof(name.sun_family);
mdp_named_socket = socket(AF_UNIX, SOCK_STREAM, 0); mdp_named_socket = socket(AF_UNIX, SOCK_STREAM, 0);
@ -74,12 +77,50 @@ int overlay_mdp_setup_sockets()
WHY("Could not open named unix domain socket."); WHY("Could not open named unix domain socket.");
} }
} }
}
return 0; return 0;
} }
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) int overlay_saw_mdp_frame(int interface,overlay_frame *f,long long now)
{ {
return WHY("Not implemented"); return WHY("Not implemented");
} }
int overlay_mdp_poll()
{
return WHY("Not implemented");
}

View File

@ -981,3 +981,6 @@ int _memabuseCheck(const char *func,const char *file,const int line);
char *thisinstancepath; char *thisinstancepath;
char *serval_instancepath(); char *serval_instancepath();
int overlay_mdp_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
int overlay_mdp_poll();