mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-02 17:41:05 +00:00
various windows networking fixes
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39455 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d3aab9bc45
commit
629e772269
2 changed files with 95 additions and 11 deletions
|
@ -8,6 +8,7 @@
|
||||||
* macosx\GNUstepBase\preface.h:
|
* macosx\GNUstepBase\preface.h:
|
||||||
Standardise on using _WIN32 and _WIN64 defines, following the
|
Standardise on using _WIN32 and _WIN64 defines, following the
|
||||||
informal convention used by all the compilers we might be compiled with.
|
informal convention used by all the compilers we might be compiled with.
|
||||||
|
* Source/win32/GSFileHandle.m: Various network/file bugfixes.
|
||||||
|
|
||||||
2016-03-01 Richard Frith-Macdonald <rfm@gnu.org>
|
2016-03-01 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
|
|
@ -300,7 +300,10 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
WSACloseEvent(event);
|
WSACloseEvent(event);
|
||||||
event = WSA_INVALID_EVENT;
|
event = WSA_INVALID_EVENT;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
close(descriptor);
|
close(descriptor);
|
||||||
|
}
|
||||||
descriptor = -1;
|
descriptor = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1288,10 +1291,11 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
|
|
||||||
// Synchronous I/O operations
|
// Synchronous I/O operations
|
||||||
|
|
||||||
|
#if 0
|
||||||
- (NSData*) availableData
|
- (NSData*) availableData
|
||||||
{
|
{
|
||||||
char buf[READ_SIZE];
|
char buf[READ_SIZE];
|
||||||
NSMutableData* d;
|
SMutableData* d;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
[self checkRead];
|
[self checkRead];
|
||||||
|
@ -1323,6 +1327,76 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
}
|
}
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
- (NSData*) availableData
|
||||||
|
{
|
||||||
|
char buf[READ_SIZE];
|
||||||
|
NSMutableData* d;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
[self checkRead];
|
||||||
|
d = [NSMutableData dataWithCapacity: 0];
|
||||||
|
if (isStandardFile)
|
||||||
|
{
|
||||||
|
if (isNonBlocking == YES)
|
||||||
|
{
|
||||||
|
[self setNonBlocking: NO];
|
||||||
|
}
|
||||||
|
while ((len = [self read: buf length: sizeof(buf)]) > 0)
|
||||||
|
{
|
||||||
|
[d appendBytes: buf length: len];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (isNonBlocking == NO)
|
||||||
|
{
|
||||||
|
[self setNonBlocking: YES];
|
||||||
|
}
|
||||||
|
len = [self read: buf length: sizeof(buf)];
|
||||||
|
|
||||||
|
if (len <= 0)
|
||||||
|
{
|
||||||
|
if (WSAGetLastError()== WSAEINTR
|
||||||
|
|| WSAGetLastError()== WSAEWOULDBLOCK)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Read would have blocked ... so try to get a single character
|
||||||
|
* in non-blocking mode (to ensure we wait until data arrives)
|
||||||
|
* and then try again.
|
||||||
|
* This ensures that we block for *some* data as we should.
|
||||||
|
*/
|
||||||
|
[self setNonBlocking: NO];
|
||||||
|
len = [self read: buf length: 1];
|
||||||
|
[self setNonBlocking: YES];
|
||||||
|
if (len == 1)
|
||||||
|
{
|
||||||
|
len = [self read: &buf[1] length: sizeof(buf) - 1];
|
||||||
|
if (len <= 0)
|
||||||
|
{
|
||||||
|
len = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
len = len + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
|
[d appendBytes: buf length: len];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (len < 0)
|
||||||
|
{
|
||||||
|
[NSException raise: NSFileHandleOperationException
|
||||||
|
format: @"unable to read from descriptor - %@",
|
||||||
|
[NSError _last]];
|
||||||
|
}
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
- (NSData*) readDataToEndOfFile
|
- (NSData*) readDataToEndOfFile
|
||||||
{
|
{
|
||||||
|
@ -2330,6 +2404,10 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
|
|
||||||
- (void) setNonBlocking: (BOOL)flag
|
- (void) setNonBlocking: (BOOL)flag
|
||||||
{
|
{
|
||||||
|
if (flag == isNonBlocking)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (descriptor < 0)
|
if (descriptor < 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -2350,7 +2428,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
{ // Not a file and not a socket, must be a pipe
|
{ // Not a file and not a socket, must be a pipe
|
||||||
DWORD mode;
|
DWORD mode;
|
||||||
|
|
||||||
if (flag)
|
if (YES == flag)
|
||||||
mode = PIPE_NOWAIT;
|
mode = PIPE_NOWAIT;
|
||||||
else
|
else
|
||||||
mode = PIPE_WAIT;
|
mode = PIPE_WAIT;
|
||||||
|
@ -2361,33 +2439,38 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NSLog(@"unable to set pipe non-blocking mode - %d",
|
NSLog(@"unable to set pipe non-blocking mode to %s - %d",
|
||||||
GetLastError());
|
(YES == flag ? "YES" : "NO"), GetLastError());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flag)
|
if (YES == flag)
|
||||||
{
|
{
|
||||||
|
WSAEventSelect((SOCKET)_get_osfhandle(descriptor), event,
|
||||||
|
FD_ALL_EVENTS);
|
||||||
dummy = 1;
|
dummy = 1;
|
||||||
if (ioctlsocket((SOCKET)_get_osfhandle(descriptor), FIONBIO, &dummy)
|
if (ioctlsocket((SOCKET)_get_osfhandle(descriptor), FIONBIO, &dummy)
|
||||||
== SOCKET_ERROR)
|
== SOCKET_ERROR)
|
||||||
{
|
{
|
||||||
NSLog(@"unable to set non-blocking mode - %@",
|
NSLog(@"unable to set non-blocking mode to YES - %@",
|
||||||
[NSError _last]);
|
[NSError _last]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
isNonBlocking = flag;
|
isNonBlocking = flag;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
WSAEventSelect((SOCKET)_get_osfhandle(descriptor), event, 0);
|
||||||
dummy = 0;
|
dummy = 0;
|
||||||
if (ioctlsocket((SOCKET)_get_osfhandle(descriptor), FIONBIO, &dummy)
|
if (ioctlsocket((SOCKET)_get_osfhandle(descriptor), FIONBIO, &dummy)
|
||||||
== SOCKET_ERROR)
|
== SOCKET_ERROR)
|
||||||
{
|
{
|
||||||
NSLog(@"unable to set blocking mode - %@", [NSError _last]);
|
NSLog(@"unable to set blocking mode to NO - %@",
|
||||||
|
[NSError _last]);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
isNonBlocking = flag;
|
isNonBlocking = flag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue