From d9c152f9f1d9f0603f581d1aab38073628309170 Mon Sep 17 00:00:00 2001 From: William Joye Date: Fri, 21 Apr 2017 16:54:44 -0400 Subject: Squashed 'tcliis/' changes from 514d5243..3cc68fd9 3cc68fd9 minor config change a4df5c46 add iis support to win port git-subtree-dir: tcliis git-subtree-split: 3cc68fd93ca8b35e43954b4cdc956b5c6090a761 --- Makefile.in | 2 +- configure | 1 + configure.ac | 1 + iis.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++------------ iistcl.h | 4 ++++ xim.C | 36 ++++++++++++++++++++++++---------- xim.h | 2 +- 7 files changed, 86 insertions(+), 24 deletions(-) diff --git a/Makefile.in b/Makefile.in index 7a704da..5c9ed8f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -158,7 +158,7 @@ PKG_CFLAGS = @PKG_CFLAGS@ DEFS = @DEFS@ $(PKG_CFLAGS) # Move pkgIndex.tcl to 'BINARIES' var if it is generated in the Makefile -CONFIG_CLEAN_FILES = Makefile pkgIndex.tcl tcliisConfig.sh +CONFIG_CLEAN_FILES = Makefile pkgIndex.tcl CLEANFILES = @CLEANFILES@ CPPFLAGS = @CPPFLAGS@ diff --git a/configure b/configure index 80d2318..912c7a2 100755 --- a/configure +++ b/configure @@ -5479,6 +5479,7 @@ done #-------------------------------------------------------------------- #CLEANFILES="$CLEANFILES pkgIndex.tcl" +CLEANFILES="$CLEANFILES tcliisConfig.sh" if test "${TEA_PLATFORM}" = "windows" ; then # Ensure no empty if clauses : diff --git a/configure.ac b/configure.ac index 9fbd92e..b25e69c 100644 --- a/configure.ac +++ b/configure.ac @@ -97,6 +97,7 @@ TEA_ADD_TCL_SOURCES([]) #-------------------------------------------------------------------- #CLEANFILES="$CLEANFILES pkgIndex.tcl" +CLEANFILES="$CLEANFILES tcliisConfig.sh" if test "${TEA_PLATFORM}" = "windows" ; then # Ensure no empty if clauses : diff --git a/iis.c b/iis.c index 18fa8f8..eb34b96 100644 --- a/iis.c +++ b/iis.c @@ -1,17 +1,21 @@ #include #include #include -#include -#include +#ifdef __WIN32 +#include +#else +#include +#include #include -#include #include +#include +#endif +#include #include #include #ifdef HAVE_SYS_UN_H #include #endif -#include #include "iis.h" #include "xim.h" @@ -98,14 +102,17 @@ static void xim_connectClient(), xim_disconnectClient(); static int chan_read(), chan_write(), decode_frameno(); static CtranPtr wcs_update(); -static IoChanPtr open_fifo(), open_inet(); +static IoChanPtr open_fifo(); +static IoChanPtr open_inet(); #ifdef HAVE_SYS_UN_H static IoChanPtr open_unix(); #endif static IoChanPtr get_iochan(); static MappingPtr xim_getMapping(XimDataPtr, float, float, int); static void print_mappings(FrameBufPtr fr); +#ifndef __WIN32 extern int errno; +#endif /* XIM_IISOPEN -- Initialize the IIS protocol module and ready the module to @@ -156,7 +163,11 @@ void xim_iisClose(XimDataPtr xim) break; case IO_INET: +#ifdef __WIN32 + closesocket(chan->datain); +#else close (chan->datain); +#endif chan->type = 0; break; @@ -178,16 +189,24 @@ void xim_iisClose(XimDataPtr xim) */ static IoChanPtr open_fifo(XimDataPtr xim) { - IoChanPtr chan; - int datain, dataout; - int keepalive; - #ifdef __DARWIN__ /* On OS X we don't use fifos. */ xim->input_fifo = "none"; return (NULL); #endif +#ifdef __WIN32 + + /* On Windows we don't use fifos. */ + xim->input_fifo = "none"; + return (NULL); + +#else + + IoChanPtr chan; + int datain, dataout; + int keepalive; + /* Setting the input fifo to "none" or the null string disables * fifo support. */ @@ -253,8 +272,9 @@ static IoChanPtr open_fifo(XimDataPtr xim) } return (chan); -} +#endif +} /* OPEN_INET -- Set up a port to be used for incoming client connections * using internet domain sockets. @@ -288,8 +308,9 @@ static IoChanPtr open_inet(XimDataPtr xim) goto err; /* make sure we close on exec */ +#ifndef __WIN32 fcntl(s, F_SETFD, FD_CLOEXEC); - +#endif /* Allocate and fill in i/o channel descriptor. */ if ((chan = get_iochan(xim))) { chan->xim = (XtPointer) xim; @@ -316,7 +337,11 @@ static IoChanPtr open_inet(XimDataPtr xim) */ xim->port = 0; if (s) +#ifdef __WIN32 + closesocket(s); +#else close (s); +#endif return (NULL); } @@ -403,7 +428,8 @@ static void xim_connectClient(IoChanPtr chan_port, int *source, XtPointer id) int s; /* Accept connection. */ - if ((s = accept ((int)*source, (struct sockaddr *)0, (socklen_t *)0)) < 0) + // if ((s = accept ((int)*source, (struct sockaddr *)0, (socklen_t *)0)) < 0) + if ((s = accept ((int)*source, (struct sockaddr *)0, NULL)) < 0) return; /* if (fcntl (s, F_SETFL, O_RDWR|O_NDELAY) < 0) { close (s); @@ -433,7 +459,11 @@ static void xim_disconnectClient(IoChanPtr chan) switch (chan->type) { case IO_INET: case IO_UNIX: +#ifdef __WIN32 + closesocket(chan->datain); +#else close (chan->datain); +#endif if (chan->id) { xim_removeInput(chan->xim, chan->id); chan->id = 0; @@ -1455,8 +1485,13 @@ static int chan_read(int fd, void* vptr, int nbytes) int nread = 0, nleft = nbytes, nb = 0; while (nleft > 0) { +#ifdef __WIN32 + if ( (nb = recv(fd, ptr, nleft, 0)) < 0) { + if (WSAGetLastError() == WSAEINTR) +#else if ( (nb = read(fd, ptr, nleft)) < 0) { if (errno == EINTR) +#endif nb = 0; /* and call read() again */ else return(-1); @@ -1479,8 +1514,13 @@ static int chan_write (int fd, void* vptr, int nbytes) int nwritten = 0, nleft = nbytes, nb = 0; while (nleft > 0) { +#ifdef __WIN32 + if ( (nb = send(fd, ptr, nleft, 0)) <= 0) { + if (WSAGetLastError() == WSAEINTR) +#else if ( (nb = write(fd, ptr, nleft)) <= 0) { if (errno == EINTR) +#endif nb = 0; /* and call write() again */ else return(-1); /* error */ diff --git a/iistcl.h b/iistcl.h index 9a09bd5..9ed8442 100644 --- a/iistcl.h +++ b/iistcl.h @@ -11,7 +11,11 @@ extern "C" { extern int IISDebug; +#ifdef __WIN32 +#define MAXCHANNEL 255 +#else #define MAXCHANNEL 40 +#endif class IIS { private: diff --git a/xim.C b/xim.C index bdbd557..ecbeeed 100644 --- a/xim.C +++ b/xim.C @@ -9,9 +9,11 @@ #include using namespace std; +#include + #include -#ifdef __WIN32__ +#ifdef __WIN32 #include #endif @@ -28,8 +30,15 @@ void iisIO(ClientData data, int mask) if (IISDebug) cerr << "iisIO() " << fd << ' ' << mask << endl; - if ((fd < MAXCHANNEL) && iis->func[fd]) { - (*iis->func[fd])(iis->chan[fd], &fd, NULL); + int idx; +#ifdef __WIN32 + idx = fmod(fd,MAXCHANNEL); +#else + idx = fd; +#endif + + if ((idx < MAXCHANNEL) && iis->func[idx]) { + (*iis->func[idx])(iis->chan[idx], &fd, NULL); } else cerr << "Error: IIS iisIO problems" << endl; @@ -41,21 +50,28 @@ int xim_addInput(XimDataPtr xim, int fd, void (*func)(IoChan*, int*, void*), IoChanPtr chan) { if (IISDebug) - cerr << "xim_addInput() " << fd << ' ' << func << ' ' << chan << endl; + cerr << "xim_addInput() " << fd << ' ' << chan << endl; + + int idx; +#ifdef __WIN32 + idx = fmod(fd,MAXCHANNEL); +#else + idx = fd; +#endif - iis->func[fd] = func; - iis->chan[fd] = chan; -#ifndef __WIN32__ + iis->func[idx] = func; + iis->chan[idx] = chan; +#ifndef __WIN32 Tcl_CreateFileHandler(fd, TCL_READABLE, (void (*)(ClientData,int))iisIO, (ClientData)long(fd)); #else Tcl_CreateEventSource(setupProc, checkProc, (ClientData)long(fd)); #endif - return fd; + return idx; } -#ifdef __WIN32__ +#ifdef __WIN32 void setupProc(void* fd, int flags) { Tcl_Time blockTime = {0,1000}; @@ -88,7 +104,7 @@ void xim_removeInput(XimDataPtr xim, int fd) if (fd < MAXCHANNEL) { iis->func[fd] = NULL; iis->chan[fd] = NULL; -#ifndef __WIN32__ +#ifndef __WIN32 Tcl_DeleteFileHandler(fd); #endif } diff --git a/xim.h b/xim.h index 168b312..bf8911c 100644 --- a/xim.h +++ b/xim.h @@ -19,7 +19,7 @@ void xim_eraseFrame(XimDataPtr, int); int xim_addInput(XimDataPtr, int, void (*func)(IoChan*, int*, void*), IoChan*); void xim_wcs(int, float, float, float, float, float, float, float, float, int); -#ifdef __WIN32__ +#ifdef __WIN32 void setupProc(void*, int); void checkProc(void*, int); #endif -- cgit v0.12