several changes, next is removing IXPTFunc, instead adding init_conn callback (connection is separated to server implementation)

This commit is contained in:
Anselm R. Garbe 2006-01-28 20:03:33 +02:00
parent 82f65e067a
commit 7d2a96b989
3 changed files with 17 additions and 36 deletions

View File

@ -257,6 +257,18 @@ mkqid(Qid *dir, char *wname, Qid *new)
return 0;
}
static int
xversion(IXPServer *s, IXPConn * c)
{
if(strncmp(s->fcall.version, IXP_VERSION, strlen(IXP_VERSION))) {
s->errstr = "9P versions differ";
return -1;
} else if(s->fcall.maxmsg > IXP_MAX_MSG)
s->fcall.maxmsg = IXP_MAX_MSG;
s->fcall.id = RVERSION;
return 0;
}
static int
xattach(IXPServer *s, IXPConn *c)
{
@ -619,7 +631,7 @@ freeconn(IXPServer *s, IXPConn *c)
}
static IXPTFunc funcs[] = {
{TVERSION, ixp_server_tversion},
{TVERSION, xversion},
{TATTACH, xattach},
{TWALK, xwalk},
{TREMOVE, xremove},

View File

@ -202,7 +202,6 @@ typedef struct {
struct IXPConn {
int fd;
int dont_close;
void *retry;
unsigned int size;
void (*read) (IXPServer *, IXPConn *);
void *aux;
@ -279,7 +278,6 @@ unsigned int ixp_msg_to_fcall(void *msg, unsigned int msglen,
/* server.c */
IXPConn *ixp_server_add_conn(IXPServer * s, int fd, int dont_close,
void (*read) (IXPServer *, IXPConn *));
int ixp_server_tversion(IXPServer *, IXPConn * c);
void ixp_server_rm_conn(IXPServer * s, IXPConn * c);
void ixp_server_loop(IXPServer * s);
int ixp_server_init(IXPServer * s, char *address, IXPTFunc * funcs,

View File

@ -63,7 +63,6 @@ init_conn(IXPConn * c, int fd, int dont_close,
{
*c = zero_conn;
c->fd = fd;
c->retry = nil;
c->dont_close = dont_close;
c->read = read;
return c;
@ -85,7 +84,7 @@ handle_conns(IXPServer * s)
int i;
for(i = 0; i < IXP_MAX_CONN; i++) {
if(s->conn[i].fd >= 0) {
if((s->conn[i].retry || FD_ISSET(s->conn[i].fd, &s->rd)) && s->conn[i].read)
if(FD_ISSET(s->conn[i].fd, &s->rd) && s->conn[i].read)
/* call back read handler */
s->conn[i].read(s, &s->conn[i]);
}
@ -98,15 +97,10 @@ server_client_read(IXPServer * s, IXPConn * c)
unsigned int i, msize;
int ret;
s->errstr = 0;
if(!c->retry) {
if(!(msize = ixp_recv_message(c->fd, msg, IXP_MAX_MSG, &s->errstr))) {
ixp_server_rm_conn(s, c);
return;
}
if(!(msize = ixp_recv_message(c->fd, msg, IXP_MAX_MSG, &s->errstr))) {
ixp_server_rm_conn(s, c);
return;
}
else
memcpy(msg, c->retry, c->size);
/*fprintf(stderr, "msize=%d\n", msize);*/
if((msize = ixp_msg_to_fcall(msg, IXP_MAX_MSG, &s->fcall))) {
for(i = 0; s->funcs && s->funcs[i].id; i++) {
@ -114,15 +108,6 @@ server_client_read(IXPServer * s, IXPConn * c)
ret = s->funcs[i].tfunc(s, c);
if(ret == -1)
break;
else if(ret == -2) {
c->size = msize;
c->retry = cext_emallocz(msize);
memcpy(c->retry, msg, msize);
return;
}
if(c->retry)
free(c->retry);
c->retry = nil;
msize = ixp_fcall_to_msg(&s->fcall, msg, s->fcall.maxmsg);
/*fprintf(stderr, "msize=%d\n", msize);*/
if(ixp_send_message(c->fd, msg, msize, &s->errstr) != msize)
@ -173,20 +158,6 @@ ixp_server_loop(IXPServer * s)
}
}
int
ixp_server_tversion(IXPServer * s, IXPConn * c)
{
/*fprintf(stderr, "got version %s (%s) %d (%d)\n", s->fcall.version,
IXP_VERSION, s->fcall.maxmsg, IXP_MAX_MSG);*/
if(strncmp(s->fcall.version, IXP_VERSION, strlen(IXP_VERSION))) {
s->errstr = "9P versions differ";
return -1;
} else if(s->fcall.maxmsg > IXP_MAX_MSG)
s->fcall.maxmsg = IXP_MAX_MSG;
s->fcall.id = RVERSION;
return 0;
}
int
ixp_server_init(IXPServer * s, char *address, IXPTFunc * funcs,
void (*freeconn) (IXPServer *, IXPConn *))