File handle changes built under unix

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13999 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2002-06-30 09:43:21 +00:00
parent 6fec988fe1
commit 7c3ccf4322
7 changed files with 94 additions and 53 deletions

View file

@ -3,8 +3,9 @@
* Headers/gnustep/base/GSFileHandle.h: New version of UnixFileHandle
for combined unix/windoze use.
* Source/GSFileHandle.m: New combined unix/windows implementation.
* Source/NSFileHandle.m: Use GSFileHandle under windoze.
* Source/GNUMakefile: Build GSFileHandle under windoze.
* Source/NSFileHandle.m: Use GSFileHandle.
* Source/GNUMakefile: Build GSFileHandle.
* SSL/GSUnixSSLHandle.m: Update for combined GSFileHandle
2002-06-29 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -41,6 +41,7 @@
BOOL closeOnDealloc;
BOOL isStandardFile;
BOOL isNullDevice;
BOOL isSocket;
BOOL isNonBlocking;
BOOL wasNonBlocking;
BOOL acceptOK;

View file

@ -1,4 +1,4 @@
/** Implementation for GSUnixSSLHandle for GNUStep
/** Implementation for GSSSLHandle for GNUStep
Copyright (C) 1997-1999 Free Software Foundation, Inc.
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
@ -53,7 +53,7 @@
#include <GSConfig.h>
#include <Foundation/Foundation.h>
#include <gnustep/base/UnixFileHandle.h>
#include <gnustep/base/GSFileHandle.h>
#if defined(__MINGW__)
#include <winsock2.h>
@ -89,7 +89,7 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
@interface GSUnixSSLHandle : UnixFileHandle <GCFinalization>
@interface GSSSLHandle : GSFileHandle <GCFinalization>
{
SSL_CTX *ctx;
SSL *ssl;
@ -102,10 +102,10 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
PEMpasswd: (NSString*)PEMpasswd;
@end
@implementation GSUnixSSLHandle
@implementation GSSSLHandle
+ (void) initialize
{
if (self == [GSUnixSSLHandle class])
if (self == [GSSSLHandle class])
{
SSL_library_init();
}
@ -121,14 +121,7 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
if (isNonBlocking == YES)
[self setNonBlocking: NO];
d = [NSMutableData dataWithCapacity: 0];
if (isStandardFile)
{
while ((len = read(descriptor, buf, sizeof(buf))) > 0)
{
[d appendBytes: buf length: len];
}
}
else
if (isSocket)
{
if (connected)
{
@ -139,12 +132,19 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
}
else
{
if ((len = read(descriptor, buf, sizeof(buf))) > 0)
if ((len = recv(descriptor, buf, sizeof(buf), 0)) > 0)
{
[d appendBytes: buf length: len];
}
}
}
else
{
while ((len = read(descriptor, buf, sizeof(buf))) > 0)
{
[d appendBytes: buf length: len];
}
}
if (len < 0)
{
[NSException raise: NSFileHandleOperationException
@ -201,6 +201,10 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
{
got = SSL_read(ssl, buf, chunk);
}
else if (isSocket)
{
got = recv(descriptor, buf, chunk, 0);
}
else
{
got = read(descriptor, buf, chunk);
@ -232,11 +236,21 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
if (isNonBlocking == YES)
[self setNonBlocking: NO];
d = [NSMutableData dataWithCapacity: 0];
if (connected)
if (isSocket)
{
while ((len = SSL_read(ssl, buf, sizeof(buf))) > 0)
if (connected)
{
[d appendBytes: buf length: len];
while ((len = SSL_read(ssl, buf, sizeof(buf))) > 0)
{
[d appendBytes: buf length: len];
}
}
else
{
while ((len = recv(descriptor, buf, sizeof(buf), 0)) > 0)
{
[d appendBytes: buf length: len];
}
}
}
else
@ -289,12 +303,12 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
}
else
{ // Accept attempt completed.
UnixFileHandle *h;
GSSSLHandle *h;
struct sockaddr_in sin;
int size = sizeof(sin);
h = [[UnixFileHandle alloc] initWithFileDescriptor: desc
closeOnDealloc: YES];
h = [[GSSSLHandle alloc] initWithFileDescriptor: desc
closeOnDealloc: YES];
getpeername(desc, (struct sockaddr*)&sin, &size);
[h setAddr: &sin];
[readInfo setObject: h
@ -338,9 +352,16 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
}
else
#endif
if (connected)
if (isSocket)
{
received = SSL_read(ssl, buf, length);
if (connected)
{
received = SSL_read(ssl, buf, length);
}
else
{
received = recv(descriptor, buf, length, 0);
}
}
else
{
@ -424,10 +445,18 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
}
else
#endif
if (connected)
if (isSocket)
{
written = SSL_write(ssl, (char*)ptr + writePos,
length - writePos);
if (connected)
{
written = SSL_write(ssl, (char*)ptr + writePos,
length - writePos);
}
else
{
written = send(descriptor, (char*)ptr + writePos,
length - writePos, 0);
}
}
else
{
@ -554,7 +583,7 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
str = @"SSL Error: really helpful";
break;
default:
str = @"Standard Unix Error: really helpful";
str = @"Standard system error: really helpful";
break;
}
NSLog(@"unable to make SSL connection to %@:%@ - %@",
@ -636,9 +665,16 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
{
toWrite = NETBUF_SIZE;
}
if (connected)
if (isSocket)
{
rval = SSL_write(ssl, (char*)ptr+pos, toWrite);
if (connected)
{
rval = SSL_write(ssl, (char*)ptr+pos, toWrite);
}
else
{
rval = send(descriptor, (char*)ptr+pos, toWrite, 0);
}
}
else
{

View file

@ -103,9 +103,7 @@ endif
endif
ifeq ($(GNUSTEP_TARGET_OS), mingw32)
GNU_MFILES += GSFileHandle.m libgnustep-base-entry.m
else
GNU_MFILES += UnixFileHandle.m
GNU_MFILES += libgnustep-base-entry.m
endif
GNU_CFILES = \
@ -120,12 +118,12 @@ libgnustep-base.def
GNU_HEADERS = \
DistributedObjects.h \
GSFileHandle.h \
GSLocale.h \
GSUnion.h \
GSIArray.h \
GSIMap.h \
Unicode.h \
UnixFileHandle.h \
behavior.h \
numbers.h \
objc-gnu2next.h \
@ -141,6 +139,7 @@ GSArray.m \
GSAttributedString.m \
GSCountedSet.m \
GSDictionary.m \
GSFileHandle.m \
GSFormat.m \
GSFTPURLHandle.m \
GSHTTPURLHandle.m \

View file

@ -749,6 +749,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
{
NSMutableDictionary* info;
isSocket = YES;
[self setNonBlocking: YES];
if (connect(net, (struct sockaddr*)&sin, sizeof(sin)) < 0)
{
@ -867,6 +868,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
self = [self initWithFileDescriptor: net closeOnDealloc: YES];
if (self)
{
isSocket = YES;
connectOK = NO;
acceptOK = YES;
readOK = NO;
@ -1056,6 +1058,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
{
unsigned long nbio = 0;
isSocket = YES;
/*
* This is probably a socket ... try
* using a socket specific call and see if that fails.
@ -1266,7 +1269,15 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
}
else
#endif
if ((len = recv(descriptor, buf, sizeof(buf), 0)) > 0)
if (isSocket)
{
len = recv(descriptor, buf, sizeof(buf), 0);
}
else
{
len = read(descriptor, buf, sizeof(buf));
}
if (len > 0)
{
[d appendBytes: buf length: len];
}
@ -1963,6 +1974,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
h = [[GSFileHandle alloc] initWithFileDescriptor: desc
closeOnDealloc: YES];
h->isSocket = YES;
getpeername(desc, (struct sockaddr*)&sin, &size);
[h setAddr: &sin];
[readInfo setObject: h
@ -2006,13 +2018,13 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
}
else
#endif
if (isStandardFile)
if (isSocket)
{
received = read(descriptor, buf, length);
received = recv(descriptor, buf, length, 0);
}
else
{
received = recv(descriptor, buf, length, 0);
received = read(descriptor, buf, length);
}
if (received == 0)
{ // Read up to end of file.
@ -2091,16 +2103,16 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
}
else
#endif
if (isStandardFile)
{
written = write(descriptor, (char*)ptr+writePos,
length-writePos);
}
else
if (isSocket)
{
written = send(descriptor, (char*)ptr+writePos,
length-writePos, 0);
}
else
{
written = write(descriptor, (char*)ptr+writePos,
length-writePos);
}
if (written <= 0)
{
if (written < 0 && errno != EAGAIN && errno != EINTR)

View file

@ -174,7 +174,7 @@ NSInvocation.m_FILE_FILTER_OUT_FLAGS = -O%
# XML support
#
$(GNUSTEP_OBJ_DIR)/GSXML.o \
$(GNUSTEP_OBJ_DIR)/UnixFileHandle.o \
$(GNUSTEP_OBJ_DIR)/GSFileHandle.o \
: $(GNUSTEP_TARGET_DIR)/config.h
#

View file

@ -32,11 +32,7 @@
#include <Foundation/NSFileHandle.h>
#include <Foundation/NSPathUtilities.h>
#include <Foundation/NSBundle.h>
#ifdef __MINGW__
#include <Foundation/GSFileHandle.h>
#else
#include <Foundation/UnixFileHandle.h>
#endif
// GNUstep Notification names
@ -61,11 +57,7 @@ static Class NSFileHandle_ssl_class = nil;
if (self == [NSFileHandle class])
{
NSFileHandle_abstract_class = self;
#ifdef __MINGW__
NSFileHandle_concrete_class = [GSFileHandle class];
#else
NSFileHandle_concrete_class = [UnixFileHandle class];
#endif
}
}