From: ian Date: Sat, 7 Sep 2002 01:12:30 +0000 (+0000) Subject: dgram sock references fixed. can close X-Git-Tag: debian/1.1.1~163 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=ec732779f1e6caddd2dcc3bf6bf084ad2202bfd1;p=chiark-tcl.git dgram sock references fixed. can close --- diff --git a/base/tables-examples.tct b/base/tables-examples.tct index 5814334..6f8755a 100644 --- a/base/tables-examples.tct +++ b/base/tables-examples.tct @@ -89,5 +89,7 @@ Table dgram_socket DgramSocket_SubCommand create local sockaddr => sockid + close + sock sockid # transmit # diff --git a/dgram/dgram.c b/dgram/dgram.c index ecdd2f7..e6df127 100644 --- a/dgram/dgram.c +++ b/dgram/dgram.c @@ -11,6 +11,13 @@ #include "tables.h" #include "hbytes.h" +typedef struct DgramSocket { + int fd; +} DgramSocket; + +static int n_socks; +static DgramSocket *socks; + static int sockfail(Tcl_Interp *ip, int fd, const char *m) { int e; e= errno; @@ -19,10 +26,19 @@ static int sockfail(Tcl_Interp *ip, int fd, const char *m) { } int do_dgram_socket_create(ClientData cd, Tcl_Interp *ip, - SockAddr_Value local, int *result) { - int fd, al, r; + SockAddr_Value local, int *sock_r) { + int fd, al, r, sock; const struct sockaddr *sa; + for (sock=0; sock=0; sock++); + if (sock>=n_socks) { + n_socks += 2; + n_socks *= 2; + socks= (void*)Tcl_Realloc((void*)socks, n_socks*sizeof(*socks)); + while (sockinternalRep.longValue; + sock= o->internalRep.longValue; + if (sock >= n_socks || socks[sock].fd==-1) + return staticerr(ip,"dgram socket not open"); + + *val= sock; return TCL_OK; }