From ec732779f1e6caddd2dcc3bf6bf084ad2202bfd1 Mon Sep 17 00:00:00 2001 From: ian Date: Sat, 7 Sep 2002 01:12:30 +0000 Subject: [PATCH] dgram sock references fixed. can close --- base/tables-examples.tct | 2 ++ dgram/dgram.c | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) 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; } -- 2.30.2