From 7d2a96b9894c982b4ca07fef29638997e7bb1bdd Mon Sep 17 00:00:00 2001 From: "Anselm R. Garbe" Date: Sat, 28 Jan 2006 20:03:33 +0200 Subject: [PATCH] several changes, next is removing IXPTFunc, instead adding init_conn callback (connection is separated to server implementation) --- cmd/wmiibar2.c | 14 +++++++++++++- libixp2/ixp.h | 2 -- libixp2/server.c | 37 ++++--------------------------------- 3 files changed, 17 insertions(+), 36 deletions(-) diff --git a/cmd/wmiibar2.c b/cmd/wmiibar2.c index b33b9618..b096bdb4 100644 --- a/cmd/wmiibar2.c +++ b/cmd/wmiibar2.c @@ -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}, diff --git a/libixp2/ixp.h b/libixp2/ixp.h index 3ac328c5..40935153 100644 --- a/libixp2/ixp.h +++ b/libixp2/ixp.h @@ -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, diff --git a/libixp2/server.c b/libixp2/server.c index 8acbef40..2c4a7085 100644 --- a/libixp2/server.c +++ b/libixp2/server.c @@ -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 *))