libixp

git clone git://oldgit.suckless.org/libixp/
Log | Files | Refs | LICENSE

commit c55907b91da31e111c2b793053b3d0a4d01ecf1f
parent b6269ce13493be6da9da415fe00d0ac7561874f3
Author: Kris Maglione <jg@suckless.org>
Date:   Fri,  1 Jun 2007 14:38:08 -0400

Free the Fid freelist on unmount.

Diffstat:
Makefile | 1+
config.mk | 1+
include/ixp.h | 4++--
libixp/client.c | 23+++++++++++++----------
libixp/server.c | 10+++++-----
5 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/Makefile b/Makefile @@ -7,3 +7,4 @@ DIRS = libixp \ man include ${ROOT}/mk/dir.mk + diff --git a/config.mk b/config.mk @@ -13,6 +13,7 @@ INCS = -I. -I${ROOT}/include -I${INCLUDE} -I/usr/include LIBS = -L/usr/lib -lc # Flags +include ${ROOT}/mk/gcc.mk CFLAGS = -g -Wall ${INCS} -DVERSION=\"${VERSION}\" LDFLAGS = -g ${LIBS} diff --git a/include/ixp.h b/include/ixp.h @@ -30,10 +30,10 @@ char *errstr; #define nil ((void*)0) #define IXP_VERSION "9P2000" -#define IXP_NOTAG ((ushort)~0) /*Dummy tag */ +#define IXP_NOTAG ((ushort)~0) /* Dummy tag */ +#define IXP_NOFID (~0U) enum { - IXP_NOFID = ~0U, IXP_MAX_VERSION = 32, IXP_MAX_MSG = 65535, IXP_MAX_ERROR = 128, diff --git a/libixp/client.c b/libixp/client.c @@ -30,18 +30,14 @@ getfid(IxpClient *c) { IxpCFid *temp; uint i; - if(!c->freefid) { - i = 15; + temp = c->freefid; + if(temp != nil) + c->freefid = temp->next; + else { temp = ixp_emallocz(sizeof(IxpCFid) * i); - while(i--) { - temp->client = c; - temp->fid = ++c->lastfid; - temp->next = c->freefid; - c->freefid = temp++; - } + temp->client = c; + temp->fid = ++c->lastfid; } - temp = c->freefid; - c->freefid = temp->next; temp->next = nil; temp->open = 0; return temp; @@ -89,8 +85,15 @@ dofcall(IxpClient *c, Fcall *fcall) { void ixp_unmount(IxpClient *c) { + IxpCFid *f; + shutdown(c->fd, SHUT_RDWR); close(c->fd); + + while((f = c->freefid)) { + c->freefid = f->next; + free(f); + } free(c->msg.data); free(c); } diff --git a/libixp/server.c b/libixp/server.c @@ -52,12 +52,12 @@ prepare_select(IxpServer *s) { IxpConn *c; FD_ZERO(&s->rd); - for(c = s->conn; c; c = c->next) { - if(s->maxfd < c->fd) - s->maxfd = c->fd; - if(c->read) + for(c = s->conn; c; c = c->next) + if(c->read) { + if(s->maxfd < c->fd) + s->maxfd = c->fd; FD_SET(c->fd, &s->rd); - } + } } static void