commit 0db44d2642e1314a9d5423b2731a1f94d84cc186
parent 523872ca3d8554fa1b8698339e0728e281385df3
Author: Anselm R. Garbe <garbeam@wmii.de>
Date: Sun, 12 Feb 2006 00:49:38 +0100
simplified asynchroneous responds
Diffstat:
3 files changed, 16 insertions(+), 47 deletions(-)
diff --git a/cmd/wm/fs.c b/cmd/wm/fs.c
@@ -776,7 +776,8 @@ xread(IXPConn *c, Fcall *fcall)
}
break;
case Fevent:
- ixp_server_enqueue_fcall(c, fcall);
+ memcpy(&c->pending, fcall, sizeof(Fcall));
+ c->is_pending = 1;
return nil;
break;
default:
@@ -912,7 +913,8 @@ xread(IXPConn *c, Fcall *fcall)
return Enoperm;
break;
case Fevent:
- ixp_server_enqueue_fcall(c, fcall);
+ memcpy(&c->pending, fcall, sizeof(Fcall));
+ c->is_pending = 1;
return nil;
break;
case Fborder:
@@ -1263,26 +1265,24 @@ void
broadcast_event(char *event)
{
size_t i;
- Fcall *fcall;
+ fprintf(stderr, "broadcasting: %s", event);
for(i = 0; (i < srv.connsz) && srv.conn[i]; i++) {
IXPConn *c = srv.conn[i];
- /* all pending TREADs are on /event, so no qid checking necessary */
- while((fcall = ixp_server_dequeue_fcall_id(c, TREAD))) {
- IXPMap *m = ixp_server_fid2map(c, fcall->fid);
- unsigned char *p = fcall->data;
-
+ if(c->is_pending) {
+ /* pending reads on /event only, no qid checking */
+ IXPMap *m = ixp_server_fid2map(c, c->pending.fid);
+ unsigned char *p = c->pending.data;
if(!m) {
- if(ixp_server_respond_error(c, fcall, Enofid))
+ if(ixp_server_respond_error(c, &c->pending, Enofid))
break;
}
else if(qpath_type(m->qid.path) == Fevent) {
- fcall->count = strlen(event);
- memcpy(p, event, fcall->count);
- fcall->id = RREAD;
- if(ixp_server_respond_fcall(c, fcall))
+ c->pending.count = strlen(event);
+ memcpy(p, event, c->pending.count);
+ c->pending.id = RREAD;
+ if(ixp_server_respond_fcall(c, &c->pending))
break;
}
- free(fcall);
}
}
}
diff --git a/libixp/ixp.h b/libixp/ixp.h
@@ -210,8 +210,8 @@ struct IXPConn {
void (*close) (IXPConn *);
IXPMap **map;
size_t mapsz;
- Fcall **pend;
- size_t pendsz;
+ Fcall pending;
+ int is_pending;
};
struct IXPServer {
@@ -284,11 +284,9 @@ IXPConn *ixp_server_open_conn(IXPServer *s, int fd,
void ixp_server_close_conn(IXPConn *c);
char *ixp_server_loop(IXPServer *s);
IXPMap *ixp_server_fid2map(IXPConn *c, unsigned int fid);
-void ixp_server_enqueue_fcall(IXPConn *c, Fcall *fcall);
unsigned int ixp_server_receive_fcall(IXPConn *c, Fcall *fcall);
int ixp_server_respond_fcall(IXPConn *c, Fcall *fcall);
int ixp_server_respond_error(IXPConn *c, Fcall *fcall, char *errstr);
-Fcall *ixp_server_dequeue_fcall_id(IXPConn *c, unsigned char id);
void ixp_server_close(IXPServer *s);
/* socket.c */
diff --git a/libixp/server.c b/libixp/server.c
@@ -43,11 +43,6 @@ ixp_server_close_conn(IXPConn *c)
free(c->map[i]);
free(c->map);
}
- if(c->pend) {
- for(i = 0; (i < c->pendsz) && c->pend[i]; i++)
- free(c->pend[i]);
- free(c->pend);
- }
shutdown(c->fd, SHUT_RDWR);
close(c->fd);
free(c);
@@ -108,30 +103,6 @@ ixp_server_fid2map(IXPConn *c, unsigned int fid)
return nil;
}
-void
-ixp_server_enqueue_fcall(IXPConn *c, Fcall *fcall)
-{
- Fcall *new = cext_emallocz(sizeof(Fcall));
- memcpy(new, fcall, sizeof(Fcall));
- c->pend = (Fcall **)cext_array_attach((void **)c->pend,
- new, sizeof(Fcall *), &c->pendsz);
-}
-
-Fcall *
-ixp_server_dequeue_fcall_id(IXPConn *c, unsigned char id)
-{
- Fcall *fcall = nil;
- size_t i;
- for(i = 0; (i < c->pendsz) && c->pend[i]; i++)
- if(c->pend[i]->id == id) {
- fcall = c->pend[i];
- cext_array_detach((void **)c->pend, fcall, &c->pendsz);
- break;
- }
- /* free it */
- return fcall;
-}
-
unsigned int
ixp_server_receive_fcall(IXPConn *c, Fcall *fcall)
{