Discussion:
Problem with tame and aprc
edouard funke
2006-07-15 14:20:42 UTC
Permalink
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
edouard funke
2006-07-15 16:10:51 UTC
Permalink
If i declare ptr<asrv> srv inside the class it will work ...
or
If I put getRPC's code instead of BLOCK { getRPC ... and i declare the
two variables inside the VARS of init, it will also work.

Do you have an explanation ? I would like to keep doRPC and avoid
declaring the srv variable in my class
Post by edouard funke
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
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
// 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
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
Loading...