networking portability for for solaris

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33951 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2011-10-08 16:29:19 +00:00
parent 5021629c2b
commit 364fb1ec98
7 changed files with 39 additions and 16 deletions

View file

@ -1,3 +1,14 @@
2011-10-08 Richard Frith-Macdonald <rfm@gnu.org>
* GSFileHandle.m:
* GSNetwork.h:
* GSSocketStream.m:
* NSMessagePort.m:
* NSSocketPort.m:
* NSURLProtocol.m:
Check for EALREADY as well as EINPROGRESS as an indicator of an
incomplete system call on a non-blocking descriptor.
2011-10-07 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSHTTPURLHandle.m:

View file

@ -910,7 +910,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
[self setNonBlocking: YES];
if (connect(net, &sin, GSPrivateSockaddrLength(&sin)) == -1)
{
if (errno != EINPROGRESS)
if (!GSWOULDBLOCK)
{
NSLog(@"unable to make connection to %@ - %@",
GSPrivateSockaddrName(&sin), [NSError _last]);

View file

@ -70,7 +70,7 @@
#define INVALID_SOCKET -1
#define BADSOCKET(X) ((X) < 0)
#define GSNETERROR errno
#define GSWOULDBLOCK (errno == EINPROGRESS)
#define GSWOULDBLOCK (errno == EINPROGRESS || errno == EALREADY)
#endif /* __MINGW__ */

View file

@ -1246,12 +1246,7 @@ socketError(int result)
static inline BOOL
socketWouldBlock()
{
#if defined(__MINGW__)
int e = WSAGetLastError();
return (e == WSAEWOULDBLOCK || e == WSAEINPROGRESS) ? YES : NO;
#else
return (errno == EWOULDBLOCK || errno == EINPROGRESS) ? YES : NO;
#endif
return GSWOULDBLOCK ? YES : NO;
}

View file

@ -381,7 +381,7 @@ static Class runLoopClass;
if (connect(desc, (struct sockaddr*)&sockAddr, SUN_LEN(&sockAddr)) < 0)
{
if (errno != EINPROGRESS)
if (!GSWOULDBLOCK)
{
NSLog(@"unable to make connection to %s - %@",
sockAddr.sun_path, [NSError _last]);

View file

@ -529,11 +529,7 @@ static Class runLoopClass;
if (connect(desc, (struct sockaddr*)&sockAddr,
GSPrivateSockaddrLength(&sockAddr)) == SOCKET_ERROR)
{
#ifdef __MINGW__
if (WSAGetLastError() != WSAEWOULDBLOCK)
#else
if (errno != EINPROGRESS)
#endif
if (!GSWOULDBLOCK)
{
NSLog(@"unable to make connection to %d - %@",
GSPrivateSockaddrName(&sockAddr), [NSError _last]);

View file

@ -77,6 +77,7 @@ zfree(void *opaque, void *mem)
}
+ (void) purge: (NSNotification*)n;
- (void) cache: (NSDate*)when;
- (void) close;
- (NSDate*) expires;
- (id) initWithHost: (NSHost*)h port: (uint16_t)p forSSL: (BOOL)s;
- (NSInputStream*) inputStream;
@ -126,13 +127,28 @@ static NSLock *pairLock = nil;
- (void) cache: (NSDate*)when
{
ASSIGN(expires, when);
NSTimeInterval ti = [when timeIntervalSinceNow];
if (ti <= 0.0)
{
[self close];
return;
}
NSAssert(ip != nil, NSGenericException);
if (ti > 120.0)
{
ASSIGN(expires, [NSDate dateWithTimeIntervalSinceNow: 120.0]);
}
else
{
ASSIGN(expires, when);
}
[pairLock lock];
[pairCache addObject: self];
[pairLock unlock];
}
- (void) dealloc
- (void) close
{
[ip setDelegate: nil];
[op setDelegate: nil];
@ -144,6 +160,11 @@ static NSLock *pairLock = nil;
[op close];
DESTROY(ip);
DESTROY(op);
}
- (void) dealloc
{
[self close];
DESTROY(host);
DESTROY(expires);
[super dealloc];