mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
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:
parent
3d601e745a
commit
baa2f9424e
7 changed files with 94 additions and 53 deletions
|
@ -3,8 +3,9 @@
|
||||||
* Headers/gnustep/base/GSFileHandle.h: New version of UnixFileHandle
|
* Headers/gnustep/base/GSFileHandle.h: New version of UnixFileHandle
|
||||||
for combined unix/windoze use.
|
for combined unix/windoze use.
|
||||||
* Source/GSFileHandle.m: New combined unix/windows implementation.
|
* Source/GSFileHandle.m: New combined unix/windows implementation.
|
||||||
* Source/NSFileHandle.m: Use GSFileHandle under windoze.
|
* Source/NSFileHandle.m: Use GSFileHandle.
|
||||||
* Source/GNUMakefile: Build GSFileHandle under windoze.
|
* Source/GNUMakefile: Build GSFileHandle.
|
||||||
|
* SSL/GSUnixSSLHandle.m: Update for combined GSFileHandle
|
||||||
|
|
||||||
2002-06-29 Richard Frith-Macdonald <rfm@gnu.org>
|
2002-06-29 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
BOOL closeOnDealloc;
|
BOOL closeOnDealloc;
|
||||||
BOOL isStandardFile;
|
BOOL isStandardFile;
|
||||||
BOOL isNullDevice;
|
BOOL isNullDevice;
|
||||||
|
BOOL isSocket;
|
||||||
BOOL isNonBlocking;
|
BOOL isNonBlocking;
|
||||||
BOOL wasNonBlocking;
|
BOOL wasNonBlocking;
|
||||||
BOOL acceptOK;
|
BOOL acceptOK;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/** Implementation for GSUnixSSLHandle for GNUStep
|
/** Implementation for GSSSLHandle for GNUStep
|
||||||
Copyright (C) 1997-1999 Free Software Foundation, Inc.
|
Copyright (C) 1997-1999 Free Software Foundation, Inc.
|
||||||
|
|
||||||
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
#include <GSConfig.h>
|
#include <GSConfig.h>
|
||||||
#include <Foundation/Foundation.h>
|
#include <Foundation/Foundation.h>
|
||||||
|
|
||||||
#include <gnustep/base/UnixFileHandle.h>
|
#include <gnustep/base/GSFileHandle.h>
|
||||||
|
|
||||||
#if defined(__MINGW__)
|
#if defined(__MINGW__)
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
|
@ -89,7 +89,7 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@interface GSUnixSSLHandle : UnixFileHandle <GCFinalization>
|
@interface GSSSLHandle : GSFileHandle <GCFinalization>
|
||||||
{
|
{
|
||||||
SSL_CTX *ctx;
|
SSL_CTX *ctx;
|
||||||
SSL *ssl;
|
SSL *ssl;
|
||||||
|
@ -102,10 +102,10 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
|
||||||
PEMpasswd: (NSString*)PEMpasswd;
|
PEMpasswd: (NSString*)PEMpasswd;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation GSUnixSSLHandle
|
@implementation GSSSLHandle
|
||||||
+ (void) initialize
|
+ (void) initialize
|
||||||
{
|
{
|
||||||
if (self == [GSUnixSSLHandle class])
|
if (self == [GSSSLHandle class])
|
||||||
{
|
{
|
||||||
SSL_library_init();
|
SSL_library_init();
|
||||||
}
|
}
|
||||||
|
@ -121,14 +121,7 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
|
||||||
if (isNonBlocking == YES)
|
if (isNonBlocking == YES)
|
||||||
[self setNonBlocking: NO];
|
[self setNonBlocking: NO];
|
||||||
d = [NSMutableData dataWithCapacity: 0];
|
d = [NSMutableData dataWithCapacity: 0];
|
||||||
if (isStandardFile)
|
if (isSocket)
|
||||||
{
|
|
||||||
while ((len = read(descriptor, buf, sizeof(buf))) > 0)
|
|
||||||
{
|
|
||||||
[d appendBytes: buf length: len];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (connected)
|
if (connected)
|
||||||
{
|
{
|
||||||
|
@ -139,12 +132,19 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((len = read(descriptor, buf, sizeof(buf))) > 0)
|
if ((len = recv(descriptor, buf, sizeof(buf), 0)) > 0)
|
||||||
{
|
{
|
||||||
[d appendBytes: buf length: len];
|
[d appendBytes: buf length: len];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while ((len = read(descriptor, buf, sizeof(buf))) > 0)
|
||||||
|
{
|
||||||
|
[d appendBytes: buf length: len];
|
||||||
|
}
|
||||||
|
}
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
{
|
{
|
||||||
[NSException raise: NSFileHandleOperationException
|
[NSException raise: NSFileHandleOperationException
|
||||||
|
@ -201,6 +201,10 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
|
||||||
{
|
{
|
||||||
got = SSL_read(ssl, buf, chunk);
|
got = SSL_read(ssl, buf, chunk);
|
||||||
}
|
}
|
||||||
|
else if (isSocket)
|
||||||
|
{
|
||||||
|
got = recv(descriptor, buf, chunk, 0);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
got = read(descriptor, buf, chunk);
|
got = read(descriptor, buf, chunk);
|
||||||
|
@ -232,11 +236,21 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
|
||||||
if (isNonBlocking == YES)
|
if (isNonBlocking == YES)
|
||||||
[self setNonBlocking: NO];
|
[self setNonBlocking: NO];
|
||||||
d = [NSMutableData dataWithCapacity: 0];
|
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
|
else
|
||||||
|
@ -289,12 +303,12 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // Accept attempt completed.
|
{ // Accept attempt completed.
|
||||||
UnixFileHandle *h;
|
GSSSLHandle *h;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
int size = sizeof(sin);
|
int size = sizeof(sin);
|
||||||
|
|
||||||
h = [[UnixFileHandle alloc] initWithFileDescriptor: desc
|
h = [[GSSSLHandle alloc] initWithFileDescriptor: desc
|
||||||
closeOnDealloc: YES];
|
closeOnDealloc: YES];
|
||||||
getpeername(desc, (struct sockaddr*)&sin, &size);
|
getpeername(desc, (struct sockaddr*)&sin, &size);
|
||||||
[h setAddr: &sin];
|
[h setAddr: &sin];
|
||||||
[readInfo setObject: h
|
[readInfo setObject: h
|
||||||
|
@ -338,9 +352,16 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#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
|
else
|
||||||
{
|
{
|
||||||
|
@ -424,10 +445,18 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
if (connected)
|
if (isSocket)
|
||||||
{
|
{
|
||||||
written = SSL_write(ssl, (char*)ptr + writePos,
|
if (connected)
|
||||||
length - writePos);
|
{
|
||||||
|
written = SSL_write(ssl, (char*)ptr + writePos,
|
||||||
|
length - writePos);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
written = send(descriptor, (char*)ptr + writePos,
|
||||||
|
length - writePos, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -554,7 +583,7 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
|
||||||
str = @"SSL Error: really helpful";
|
str = @"SSL Error: really helpful";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
str = @"Standard Unix Error: really helpful";
|
str = @"Standard system error: really helpful";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
NSLog(@"unable to make SSL connection to %@:%@ - %@",
|
NSLog(@"unable to make SSL connection to %@:%@ - %@",
|
||||||
|
@ -636,9 +665,16 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
|
||||||
{
|
{
|
||||||
toWrite = NETBUF_SIZE;
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -103,9 +103,7 @@ endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(GNUSTEP_TARGET_OS), mingw32)
|
ifeq ($(GNUSTEP_TARGET_OS), mingw32)
|
||||||
GNU_MFILES += GSFileHandle.m libgnustep-base-entry.m
|
GNU_MFILES += libgnustep-base-entry.m
|
||||||
else
|
|
||||||
GNU_MFILES += UnixFileHandle.m
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
GNU_CFILES = \
|
GNU_CFILES = \
|
||||||
|
@ -120,12 +118,12 @@ libgnustep-base.def
|
||||||
|
|
||||||
GNU_HEADERS = \
|
GNU_HEADERS = \
|
||||||
DistributedObjects.h \
|
DistributedObjects.h \
|
||||||
|
GSFileHandle.h \
|
||||||
GSLocale.h \
|
GSLocale.h \
|
||||||
GSUnion.h \
|
GSUnion.h \
|
||||||
GSIArray.h \
|
GSIArray.h \
|
||||||
GSIMap.h \
|
GSIMap.h \
|
||||||
Unicode.h \
|
Unicode.h \
|
||||||
UnixFileHandle.h \
|
|
||||||
behavior.h \
|
behavior.h \
|
||||||
numbers.h \
|
numbers.h \
|
||||||
objc-gnu2next.h \
|
objc-gnu2next.h \
|
||||||
|
@ -141,6 +139,7 @@ GSArray.m \
|
||||||
GSAttributedString.m \
|
GSAttributedString.m \
|
||||||
GSCountedSet.m \
|
GSCountedSet.m \
|
||||||
GSDictionary.m \
|
GSDictionary.m \
|
||||||
|
GSFileHandle.m \
|
||||||
GSFormat.m \
|
GSFormat.m \
|
||||||
GSFTPURLHandle.m \
|
GSFTPURLHandle.m \
|
||||||
GSHTTPURLHandle.m \
|
GSHTTPURLHandle.m \
|
||||||
|
|
|
@ -749,6 +749,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
{
|
{
|
||||||
NSMutableDictionary* info;
|
NSMutableDictionary* info;
|
||||||
|
|
||||||
|
isSocket = YES;
|
||||||
[self setNonBlocking: YES];
|
[self setNonBlocking: YES];
|
||||||
if (connect(net, (struct sockaddr*)&sin, sizeof(sin)) < 0)
|
if (connect(net, (struct sockaddr*)&sin, sizeof(sin)) < 0)
|
||||||
{
|
{
|
||||||
|
@ -867,6 +868,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
self = [self initWithFileDescriptor: net closeOnDealloc: YES];
|
self = [self initWithFileDescriptor: net closeOnDealloc: YES];
|
||||||
if (self)
|
if (self)
|
||||||
{
|
{
|
||||||
|
isSocket = YES;
|
||||||
connectOK = NO;
|
connectOK = NO;
|
||||||
acceptOK = YES;
|
acceptOK = YES;
|
||||||
readOK = NO;
|
readOK = NO;
|
||||||
|
@ -1056,6 +1058,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
{
|
{
|
||||||
unsigned long nbio = 0;
|
unsigned long nbio = 0;
|
||||||
|
|
||||||
|
isSocket = YES;
|
||||||
/*
|
/*
|
||||||
* This is probably a socket ... try
|
* This is probably a socket ... try
|
||||||
* using a socket specific call and see if that fails.
|
* using a socket specific call and see if that fails.
|
||||||
|
@ -1266,7 +1269,15 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#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];
|
[d appendBytes: buf length: len];
|
||||||
}
|
}
|
||||||
|
@ -1963,6 +1974,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
|
|
||||||
h = [[GSFileHandle alloc] initWithFileDescriptor: desc
|
h = [[GSFileHandle alloc] initWithFileDescriptor: desc
|
||||||
closeOnDealloc: YES];
|
closeOnDealloc: YES];
|
||||||
|
h->isSocket = YES;
|
||||||
getpeername(desc, (struct sockaddr*)&sin, &size);
|
getpeername(desc, (struct sockaddr*)&sin, &size);
|
||||||
[h setAddr: &sin];
|
[h setAddr: &sin];
|
||||||
[readInfo setObject: h
|
[readInfo setObject: h
|
||||||
|
@ -2006,13 +2018,13 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
if (isStandardFile)
|
if (isSocket)
|
||||||
{
|
{
|
||||||
received = read(descriptor, buf, length);
|
received = recv(descriptor, buf, length, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
received = recv(descriptor, buf, length, 0);
|
received = read(descriptor, buf, length);
|
||||||
}
|
}
|
||||||
if (received == 0)
|
if (received == 0)
|
||||||
{ // Read up to end of file.
|
{ // Read up to end of file.
|
||||||
|
@ -2091,16 +2103,16 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
if (isStandardFile)
|
if (isSocket)
|
||||||
{
|
|
||||||
written = write(descriptor, (char*)ptr+writePos,
|
|
||||||
length-writePos);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
written = send(descriptor, (char*)ptr+writePos,
|
written = send(descriptor, (char*)ptr+writePos,
|
||||||
length-writePos, 0);
|
length-writePos, 0);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
written = write(descriptor, (char*)ptr+writePos,
|
||||||
|
length-writePos);
|
||||||
|
}
|
||||||
if (written <= 0)
|
if (written <= 0)
|
||||||
{
|
{
|
||||||
if (written < 0 && errno != EAGAIN && errno != EINTR)
|
if (written < 0 && errno != EAGAIN && errno != EINTR)
|
||||||
|
|
|
@ -174,7 +174,7 @@ NSInvocation.m_FILE_FILTER_OUT_FLAGS = -O%
|
||||||
# XML support
|
# XML support
|
||||||
#
|
#
|
||||||
$(GNUSTEP_OBJ_DIR)/GSXML.o \
|
$(GNUSTEP_OBJ_DIR)/GSXML.o \
|
||||||
$(GNUSTEP_OBJ_DIR)/UnixFileHandle.o \
|
$(GNUSTEP_OBJ_DIR)/GSFileHandle.o \
|
||||||
: $(GNUSTEP_TARGET_DIR)/config.h
|
: $(GNUSTEP_TARGET_DIR)/config.h
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -32,11 +32,7 @@
|
||||||
#include <Foundation/NSFileHandle.h>
|
#include <Foundation/NSFileHandle.h>
|
||||||
#include <Foundation/NSPathUtilities.h>
|
#include <Foundation/NSPathUtilities.h>
|
||||||
#include <Foundation/NSBundle.h>
|
#include <Foundation/NSBundle.h>
|
||||||
#ifdef __MINGW__
|
|
||||||
#include <Foundation/GSFileHandle.h>
|
#include <Foundation/GSFileHandle.h>
|
||||||
#else
|
|
||||||
#include <Foundation/UnixFileHandle.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// GNUstep Notification names
|
// GNUstep Notification names
|
||||||
|
|
||||||
|
@ -61,11 +57,7 @@ static Class NSFileHandle_ssl_class = nil;
|
||||||
if (self == [NSFileHandle class])
|
if (self == [NSFileHandle class])
|
||||||
{
|
{
|
||||||
NSFileHandle_abstract_class = self;
|
NSFileHandle_abstract_class = self;
|
||||||
#ifdef __MINGW__
|
|
||||||
NSFileHandle_concrete_class = [GSFileHandle class];
|
NSFileHandle_concrete_class = [GSFileHandle class];
|
||||||
#else
|
|
||||||
NSFileHandle_concrete_class = [UnixFileHandle class];
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue