diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-02-28 12:46:42 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-02-28 12:46:42 (GMT) |
commit | 4af90e27e5e22978b56d6cb5d0d1ecd90af0f48f (patch) | |
tree | d5db4ca8a1fecbd63d9e72730fad2f404367daff /unix/tclUnixSock.c | |
parent | 63994a73e3f641451b26f48f697b6a069863751c (diff) | |
parent | 52e543c5691a60c3ef802fecf1ae08e7efcf19b7 (diff) | |
download | tcl-4af90e27e5e22978b56d6cb5d0d1ecd90af0f48f.zip tcl-4af90e27e5e22978b56d6cb5d0d1ecd90af0f48f.tar.gz tcl-4af90e27e5e22978b56d6cb5d0d1ecd90af0f48f.tar.bz2 |
Merge 8.7
Diffstat (limited to 'unix/tclUnixSock.c')
-rw-r--r-- | unix/tclUnixSock.c | 101 |
1 files changed, 54 insertions, 47 deletions
diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c index 29defff..0fa4edf 100644 --- a/unix/tclUnixSock.c +++ b/unix/tclUnixSock.c @@ -66,7 +66,7 @@ struct TcpState { Tcl_TcpAcceptProc *acceptProc; /* Proc to call on accept. */ - ClientData acceptProcData; /* The data for the accept proc. */ + void *acceptProcData; /* The data for the accept proc. */ /* * Only needed for client sockets @@ -130,24 +130,24 @@ struct TcpState { */ static int TcpConnect(Tcl_Interp *interp, TcpState *state); -static void TcpAccept(ClientData data, int mask); -static int TcpBlockModeProc(ClientData data, int mode); -static int TcpCloseProc(ClientData instanceData, +static void TcpAccept(void *data, int mask); +static int TcpBlockModeProc(void *data, int mode); +static int TcpCloseProc(void *instanceData, Tcl_Interp *interp); -static int TcpClose2Proc(ClientData instanceData, +static int TcpClose2Proc(void *instanceData, Tcl_Interp *interp, int flags); -static int TcpGetHandleProc(ClientData instanceData, - int direction, ClientData *handlePtr); -static int TcpGetOptionProc(ClientData instanceData, +static int TcpGetHandleProc(void *instanceData, + int direction, void **handlePtr); +static int TcpGetOptionProc(void *instanceData, Tcl_Interp *interp, const char *optionName, Tcl_DString *dsPtr); -static int TcpInputProc(ClientData instanceData, char *buf, +static int TcpInputProc(void *instanceData, char *buf, int toRead, int *errorCode); -static int TcpOutputProc(ClientData instanceData, +static int TcpOutputProc(void *instanceData, const char *buf, int toWrite, int *errorCode); -static void TcpWatchProc(ClientData instanceData, int mask); +static void TcpWatchProc(void *instanceData, int mask); static int WaitForConnect(TcpState *statePtr, int *errorCodePtr); -static void WrapNotify(ClientData clientData, int mask); +static void WrapNotify(void *clientData, int mask); /* * This structure describes the channel type structure for TCP socket @@ -239,7 +239,7 @@ InitializeHostName( char *dot = strchr(u.nodename, '.'); if (dot != NULL) { - char *node = Tcl_Alloc(dot - u.nodename + 1); + char *node = (char *)Tcl_Alloc(dot - u.nodename + 1); memcpy(node, u.nodename, dot - u.nodename); node[dot - u.nodename] = '\0'; @@ -283,11 +283,11 @@ InitializeHostName( *encodingPtr = Tcl_GetEncoding(NULL, NULL); if (native) { *lengthPtr = strlen(native); - *valuePtr = Tcl_Alloc(*lengthPtr + 1); + *valuePtr = (char *)Tcl_Alloc(*lengthPtr + 1); memcpy(*valuePtr, native, *lengthPtr + 1); } else { *lengthPtr = 0; - *valuePtr = Tcl_Alloc(1); + *valuePtr = (char *)Tcl_Alloc(1); *valuePtr[0] = '\0'; } } @@ -335,8 +335,10 @@ Tcl_GetHostName(void) int TclpHasSockets( - Tcl_Interp *interp) /* Not used. */ + Tcl_Interp *dummy) /* Not used. */ { + (void)dummy; + return TCL_OK; } @@ -382,12 +384,12 @@ TclpFinalizeSockets(void) /* ARGSUSED */ static int TcpBlockModeProc( - ClientData instanceData, /* Socket state. */ + void *instanceData, /* Socket state. */ int mode) /* The mode to set. Can be one of * TCL_MODE_BLOCKING or * TCL_MODE_NONBLOCKING. */ { - TcpState *statePtr = instanceData; + TcpState *statePtr = (TcpState *)instanceData; if (mode == TCL_MODE_BLOCKING) { CLEAR_BITS(statePtr->flags, TCP_NONBLOCKING); @@ -528,13 +530,13 @@ WaitForConnect( /* ARGSUSED */ static int TcpInputProc( - ClientData instanceData, /* Socket state. */ + void *instanceData, /* Socket state. */ char *buf, /* Where to store data read. */ int bufSize, /* How much space is available in the * buffer? */ int *errorCodePtr) /* Where to store error code. */ { - TcpState *statePtr = instanceData; + TcpState *statePtr = (TcpState *)instanceData; int bytesRead; *errorCodePtr = 0; @@ -579,12 +581,12 @@ TcpInputProc( static int TcpOutputProc( - ClientData instanceData, /* Socket state. */ + void *instanceData, /* Socket state. */ const char *buf, /* The data buffer. */ int toWrite, /* How many bytes to write? */ int *errorCodePtr) /* Where to store error code. */ { - TcpState *statePtr = instanceData; + TcpState *statePtr = (TcpState *)instanceData; int written; *errorCodePtr = 0; @@ -621,12 +623,13 @@ TcpOutputProc( /* ARGSUSED */ static int TcpCloseProc( - ClientData instanceData, /* The socket to close. */ - Tcl_Interp *interp) /* For error reporting - unused. */ + void *instanceData, /* The socket to close. */ + Tcl_Interp *dummy) /* For error reporting - unused. */ { - TcpState *statePtr = instanceData; + TcpState *statePtr = (TcpState *)instanceData; int errorCode = 0; TcpFdList *fds; + (void)dummy; /* * Delete a file handler that may be active for this socket if this is a @@ -682,11 +685,11 @@ TcpCloseProc( static int TcpClose2Proc( - ClientData instanceData, /* The socket to close. */ + void *instanceData, /* The socket to close. */ Tcl_Interp *interp, /* For error reporting. */ int flags) /* Flags that indicate which side to close. */ { - TcpState *statePtr = instanceData; + TcpState *statePtr = (TcpState *)instanceData; int readError = 0; int writeError = 0; @@ -833,7 +836,7 @@ TcpHostPortList( static int TcpGetOptionProc( - ClientData instanceData, /* Socket state. */ + void *instanceData, /* Socket state. */ Tcl_Interp *interp, /* For error reporting - can be NULL. */ const char *optionName, /* Name of the option to retrieve the value * for, or NULL to get all options and their @@ -841,7 +844,7 @@ TcpGetOptionProc( Tcl_DString *dsPtr) /* Where to store the computed value; * initialized by caller. */ { - TcpState *statePtr = instanceData; + TcpState *statePtr = (TcpState *)instanceData; size_t len = 0; WaitForConnect(statePtr, NULL); @@ -999,7 +1002,7 @@ TcpGetOptionProc( static void WrapNotify( - ClientData clientData, + void *clientData, int mask) { TcpState *statePtr = (TcpState *) clientData; @@ -1028,12 +1031,12 @@ WrapNotify( static void TcpWatchProc( - ClientData instanceData, /* The socket state. */ + void *instanceData, /* The socket state. */ int mask) /* Events of interest; an OR-ed combination of * TCL_READABLE, TCL_WRITABLE and * TCL_EXCEPTION. */ { - TcpState *statePtr = instanceData; + TcpState *statePtr = (TcpState *)instanceData; if (statePtr->acceptProc != NULL) { /* @@ -1102,11 +1105,12 @@ TcpWatchProc( /* ARGSUSED */ static int TcpGetHandleProc( - ClientData instanceData, /* The socket state. */ + void *instanceData, /* The socket state. */ int direction, /* Not used. */ - ClientData *handlePtr) /* Where to store the handle. */ + void **handlePtr) /* Where to store the handle. */ { - TcpState *statePtr = instanceData; + TcpState *statePtr = (TcpState *)instanceData; + (void)direction; *handlePtr = INT2PTR(statePtr->fds.fd); return TCL_OK; @@ -1126,12 +1130,14 @@ TcpGetHandleProc( static void TcpAsyncCallback( - ClientData clientData, /* The socket state. */ + void *clientData, /* The socket state. */ int mask) /* Events of interest; an OR-ed combination of * TCL_READABLE, TCL_WRITABLE and * TCL_EXCEPTION. */ { - TcpConnect(NULL, clientData); + (void)mask; + + TcpConnect(NULL, (TcpState *)clientData); } /* @@ -1173,6 +1179,7 @@ TcpConnect( int async_callback = GOT_BITS(statePtr->flags, TCP_ASYNC_PENDING); int ret = -1, error = EHOSTUNREACH; int async = GOT_BITS(statePtr->flags, TCP_ASYNC_CONNECT); + static const int reuseaddr = 1; if (async_callback) { goto reenter; @@ -1183,7 +1190,6 @@ TcpConnect( for (statePtr->myaddr = statePtr->myaddrlist; statePtr->myaddr != NULL; statePtr->myaddr = statePtr->myaddr->ai_next) { - int reuseaddr = 1; /* * No need to try combinations of local and remote addresses of @@ -1390,7 +1396,7 @@ Tcl_OpenTcpClient( * Allocate a new TcpState for this socket. */ - statePtr = Tcl_Alloc(sizeof(TcpState)); + statePtr = (TcpState *)Tcl_Alloc(sizeof(TcpState)); memset(statePtr, 0, sizeof(TcpState)); statePtr->flags = async ? TCP_ASYNC_CONNECT : 0; statePtr->cachedBlocking = TCL_MODE_BLOCKING; @@ -1437,7 +1443,7 @@ Tcl_OpenTcpClient( Tcl_Channel Tcl_MakeTcpClientChannel( - ClientData sock) /* The socket to wrap up into a channel. */ + void *sock) /* The socket to wrap up into a channel. */ { return (Tcl_Channel) TclpMakeTcpClientChannelMode(sock, TCL_READABLE | TCL_WRITABLE); @@ -1469,7 +1475,7 @@ TclpMakeTcpClientChannelMode( TcpState *statePtr; char channelName[SOCK_CHAN_LENGTH]; - statePtr = Tcl_Alloc(sizeof(TcpState)); + statePtr = (TcpState *)Tcl_Alloc(sizeof(TcpState)); memset(statePtr, 0, sizeof(TcpState)); statePtr->fds.fd = PTR2INT(sock); statePtr->flags = 0; @@ -1512,7 +1518,7 @@ Tcl_OpenTcpServerEx( Tcl_TcpAcceptProc *acceptProc, /* Callback for accepting connections from new * clients. */ - ClientData acceptProcData) /* Data for the callback. */ + void *acceptProcData) /* Data for the callback. */ { int status = 0, sock = -1, optvalue, port, chosenport; struct addrinfo *addrlist = NULL, *addrPtr; /* socket address */ @@ -1692,14 +1698,14 @@ Tcl_OpenTcpServerEx( * Allocate a new TcpState for this socket. */ - statePtr = Tcl_Alloc(sizeof(TcpState)); + statePtr = (TcpState *)Tcl_Alloc(sizeof(TcpState)); memset(statePtr, 0, sizeof(TcpState)); statePtr->acceptProc = acceptProc; statePtr->acceptProcData = acceptProcData; sprintf(channelName, SOCK_TEMPLATE, (long) statePtr); newfds = &statePtr->fds; } else { - newfds = Tcl_Alloc(sizeof(TcpFdList)); + newfds = (TcpFdList *)Tcl_Alloc(sizeof(TcpFdList)); memset(newfds, (int) 0, sizeof(TcpFdList)); fds->next = newfds; } @@ -1760,16 +1766,17 @@ Tcl_OpenTcpServerEx( /* ARGSUSED */ static void TcpAccept( - ClientData data, /* Callback token. */ + void *data, /* Callback token. */ int mask) /* Not used. */ { - TcpFdList *fds = data; /* Client data of server socket. */ + TcpFdList *fds = (TcpFdList *)data; /* Client data of server socket. */ int newsock; /* The new client socket */ TcpState *newSockState; /* State for new socket. */ address addr; /* The remote address */ socklen_t len; /* For accept interface */ char channelName[SOCK_CHAN_LENGTH]; char host[NI_MAXHOST], port[NI_MAXSERV]; + (void)mask; len = sizeof(addr); newsock = accept(fds->fd, &addr.sa, &len); @@ -1784,7 +1791,7 @@ TcpAccept( (void) fcntl(newsock, F_SETFD, FD_CLOEXEC); - newSockState = Tcl_Alloc(sizeof(TcpState)); + newSockState = (TcpState *)Tcl_Alloc(sizeof(TcpState)); memset(newSockState, 0, sizeof(TcpState)); newSockState->flags = 0; newSockState->fds.fd = newsock; |