diff options
author | simonmar <unknown> | 1999-09-20 10:18:30 +0000 |
---|---|---|
committer | simonmar <unknown> | 1999-09-20 10:18:30 +0000 |
commit | d82f41425562849cb77653bb690d2279e7a85586 (patch) | |
tree | 61ecaa1d28356c23c40a54d69430ea9355306250 /ghc/lib/misc/cbits | |
parent | 6b7c06e0715663168ed35ef00084e07e03cdd28b (diff) | |
download | haskell-d82f41425562849cb77653bb690d2279e7a85586.tar.gz |
[project @ 1999-09-20 10:18:29 by simonmar]
- fix bug in setSocketOption__ which meant that trying to set
SO_REUSEADDR on Linux (and possibly other OS's) didn't work.
- add rudimentary non-blocking connect support.
Diffstat (limited to 'ghc/lib/misc/cbits')
-rw-r--r-- | ghc/lib/misc/cbits/connectSocket.c | 8 | ||||
-rw-r--r-- | ghc/lib/misc/cbits/ghcSockets.h | 4 | ||||
-rw-r--r-- | ghc/lib/misc/cbits/socketOpt.c | 33 |
3 files changed, 11 insertions, 34 deletions
diff --git a/ghc/lib/misc/cbits/connectSocket.c b/ghc/lib/misc/cbits/connectSocket.c index 4874cb3bf8..961b6bbac8 100644 --- a/ghc/lib/misc/cbits/connectSocket.c +++ b/ghc/lib/misc/cbits/connectSocket.c @@ -18,7 +18,11 @@ connectSocket(I_ sockfd, A_ servaddr, I_ addrlen, I_ isUnixDomain) int rc; while ((rc = connect((int)sockfd, (struct sockaddr *)servaddr, (int)addrlen)) < 0) { - if (errno != EINTR) { + if (errno == EINPROGRESS) { + errno = 0; + return FILEOBJ_BLOCKED_WRITE; + + } else if (errno != EINTR) { cvtErrno(); switch (ghc_errno) { default: @@ -44,7 +48,6 @@ connectSocket(I_ sockfd, A_ servaddr, I_ addrlen, I_ isUnixDomain) ghc_errtype = ERR_INVALIDARGUMENT; ghc_errstr = "Address cannot be used with socket"; break; - case GHC_EINPROGRESS: case GHC_EALREADY: ghc_errtype = ERR_RESOURCEBUSY; ghc_errstr = "Non-blocking socket, previous connection attempt not completed"; @@ -65,7 +68,6 @@ connectSocket(I_ sockfd, A_ servaddr, I_ addrlen, I_ isUnixDomain) ghc_errtype = ERR_SYSTEMERROR; ghc_errstr = "Specified size of structure not equal valid address for family"; break; - break; case GHC_ENETUNREACH: ghc_errtype = ERR_PERMISSIONDENIED; ghc_errstr = "Network not reachable from host"; diff --git a/ghc/lib/misc/cbits/ghcSockets.h b/ghc/lib/misc/cbits/ghcSockets.h index f2f636a11f..7b0efd62b3 100644 --- a/ghc/lib/misc/cbits/ghcSockets.h +++ b/ghc/lib/misc/cbits/ghcSockets.h @@ -87,8 +87,8 @@ StgInt recvFrom__ (StgInt, StgAddr, StgInt, StgAddr); StgInt sendTo__ (StgInt, StgAddr, StgInt, StgAddr, StgInt); /* socketOpt.c */ -StgInt getSocketOption__ (StgInt, StgInt); -StgInt setSocketOption__ (StgInt, StgInt, StgInt); +StgInt getSocketOption__ (StgInt, StgInt, StgInt); +StgInt setSocketOption__ (StgInt, StgInt, StgInt, StgInt); /* writeDescriptor.lc */ StgInt writeDescriptor (StgInt, StgAddr, StgInt); diff --git a/ghc/lib/misc/cbits/socketOpt.c b/ghc/lib/misc/cbits/socketOpt.c index 69e1fa1214..21ce7a2d23 100644 --- a/ghc/lib/misc/cbits/socketOpt.c +++ b/ghc/lib/misc/cbits/socketOpt.c @@ -13,21 +13,9 @@ #include "stgio.h" StgInt -getSocketOption__ (fd, opt) -StgInt fd; -StgInt opt; +getSocketOption__ (StgInt fd, StgInt opt, StgInt level) { - int level,optval, sz_optval,rc; - - if ( -#ifndef _WIN32 - opt == TCP_MAXSEG || -#endif - opt == TCP_NODELAY ) { - level = IPPROTO_TCP; - } else { - level = SOL_SOCKET; - } + int optval, sz_optval, rc; sz_optval = sizeof(int); @@ -42,23 +30,10 @@ StgInt opt; } StgInt -setSocketOption__ (fd, opt, val) -StgInt fd; -StgInt opt; -StgInt val; +setSocketOption__ (StgInt fd, StgInt opt, StgInt level, StgInt val) { - int level, optval,rc; + int optval, rc; - if ( -#ifndef _WIN32 - opt == TCP_MAXSEG || -#endif - opt == TCP_NODELAY ) { - level = IPPROTO_TCP; - } else { - level = SOL_SOCKET; - } - optval = val; while ( (rc = setsockopt((int)fd, level, opt, &optval, sizeof(optval))) < 0 ) { |