edouard funke
2006-07-15 14:20:42 UTC
Hi,
I'm a student from Oxford Brookes University in Msc High Speed
Networks and Computer Science.
I'm actually writing a simple "tamed" version of chord. I faced this
problem that you could probably resolve :
i have a function init that create a "server" socket and blocks until
it receives an incoming connection, accept it and send the new fd to a
getRPC function
:
TAMED int node::init ()
{
// stack variables for tame
VARS
{
int fd;
int lfd;
int result;
sockaddr_in sin;
socklen_t len;
coordgroup_t<> read;
}
DEFAULT_RETURN { return SUCCESS; }
warn << "init !\n";
// create server socket
if((fd = inetsocket (SOCK_STREAM, me->port)) < 0)
{
warn << "node::init: cannot allocate TCP port: "
<< me->port << " on " << ntohl(inet_addr(me->addr)) << "\n";
return FAILURE;
}
close_on_exec(fd);
// listen to the incoming connection
if (listen (fd, BACKLOG) < 0)
{
warn << "listen : " << strerror(errno) << "\n";
return FAILURE;
}
// Call 'fdcb' to select on a file descriptor,
// Once the socket is readable, we'll be callback
fdcb (fd, selread, @[read]());
// fd ready to be read after wait
while (true)
{
WAIT(read);
len = sizeof (sin);
bzero (&sin, len);
// accepting connection
if ((lfd = accept (fd, reinterpret_cast<sockaddr *> (&sin), &len)) < 0)
{
perror ("accept");
return FAILURE;
}
warn << "accepting connection from " << inet_ntoa (sin.sin_addr) << "\n";
// call rpc manager and set callback
BLOCK { getRPC(lfd, @(result)); }
if (result < 0)
{
warn << "RPC received failed !\n";
continue;
}
}
}
void node::getRPC (int fd, cbi_t result)
{
// standard libasync class that wraps a TCP connection
ptr<axprt_stream> x = axprt_stream::alloc (fd);
// bind the rpc handler to the dispatch function
ptr<asrv> srv = asrv::alloc (x, node_prog_1, wrap(this,
&node::dispatch, result));
}
The dispatch function will of course send back the response.
The problem is that it never enters the dispatch function, why ?
Thanks for your time.
Edouard FUNKE
I'm a student from Oxford Brookes University in Msc High Speed
Networks and Computer Science.
I'm actually writing a simple "tamed" version of chord. I faced this
problem that you could probably resolve :
i have a function init that create a "server" socket and blocks until
it receives an incoming connection, accept it and send the new fd to a
getRPC function
:
TAMED int node::init ()
{
// stack variables for tame
VARS
{
int fd;
int lfd;
int result;
sockaddr_in sin;
socklen_t len;
coordgroup_t<> read;
}
DEFAULT_RETURN { return SUCCESS; }
warn << "init !\n";
// create server socket
if((fd = inetsocket (SOCK_STREAM, me->port)) < 0)
{
warn << "node::init: cannot allocate TCP port: "
<< me->port << " on " << ntohl(inet_addr(me->addr)) << "\n";
return FAILURE;
}
close_on_exec(fd);
// listen to the incoming connection
if (listen (fd, BACKLOG) < 0)
{
warn << "listen : " << strerror(errno) << "\n";
return FAILURE;
}
// Call 'fdcb' to select on a file descriptor,
// Once the socket is readable, we'll be callback
fdcb (fd, selread, @[read]());
// fd ready to be read after wait
while (true)
{
WAIT(read);
len = sizeof (sin);
bzero (&sin, len);
// accepting connection
if ((lfd = accept (fd, reinterpret_cast<sockaddr *> (&sin), &len)) < 0)
{
perror ("accept");
return FAILURE;
}
warn << "accepting connection from " << inet_ntoa (sin.sin_addr) << "\n";
// call rpc manager and set callback
BLOCK { getRPC(lfd, @(result)); }
if (result < 0)
{
warn << "RPC received failed !\n";
continue;
}
}
}
void node::getRPC (int fd, cbi_t result)
{
// standard libasync class that wraps a TCP connection
ptr<axprt_stream> x = axprt_stream::alloc (fd);
// bind the rpc handler to the dispatch function
ptr<asrv> srv = asrv::alloc (x, node_prog_1, wrap(this,
&node::dispatch, result));
}
The dispatch function will of course send back the response.
The problem is that it never enters the dispatch function, why ?
Thanks for your time.
Edouard FUNKE