mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +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
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue