mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-17 03:02:04 +00:00
simplify memory usage
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28127 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3cfdb02718
commit
346052f64d
3 changed files with 35 additions and 30 deletions
|
@ -1,4 +1,11 @@
|
||||||
|
2009-03-24 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/GSSocketStream.h:
|
||||||
|
* Source/GSSocketStream.m:
|
||||||
|
Avoid unnecessary memory allocation.
|
||||||
|
|
||||||
2009-03-21 Richard Frith-Macdonald <rfm@gnu.org>
|
2009-03-21 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* configure.ac:
|
* configure.ac:
|
||||||
* configure:
|
* configure:
|
||||||
* Headers/Additions/GNUstepBase/config.h.in:
|
* Headers/Additions/GNUstepBase/config.h.in:
|
||||||
|
|
|
@ -32,6 +32,17 @@
|
||||||
unsigned
|
unsigned
|
||||||
GSPrivateSockaddrLength(struct sockaddr *addr) GS_ATTRIB_PRIVATE;
|
GSPrivateSockaddrLength(struct sockaddr *addr) GS_ATTRIB_PRIVATE;
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
struct sockaddr s;
|
||||||
|
struct sockaddr_in i4;
|
||||||
|
#ifdef AF_INET6
|
||||||
|
struct sockaddr_in i6;
|
||||||
|
#endif
|
||||||
|
#ifndef __MINGW__
|
||||||
|
struct sockaddr_un u;
|
||||||
|
#endif
|
||||||
|
} sockaddr_any;
|
||||||
|
|
||||||
#define SOCKIVARS \
|
#define SOCKIVARS \
|
||||||
{ \
|
{ \
|
||||||
id _sibling; /* For bidirectional traffic. */\
|
id _sibling; /* For bidirectional traffic. */\
|
||||||
|
@ -39,7 +50,7 @@ GSPrivateSockaddrLength(struct sockaddr *addr) GS_ATTRIB_PRIVATE;
|
||||||
BOOL _closing; /* Must close on next failure. */\
|
BOOL _closing; /* Must close on next failure. */\
|
||||||
SOCKET _sock; /* Needed for ms-windows. */\
|
SOCKET _sock; /* Needed for ms-windows. */\
|
||||||
id _handler; /* TLS/SOCKS handler. */\
|
id _handler; /* TLS/SOCKS handler. */\
|
||||||
struct sockaddr *_address; /* Socket address info. */\
|
sockaddr_any _address; /* Socket address info. */\
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The semi-abstract GSSocketStream class is not intended to be subclassed
|
/* The semi-abstract GSSocketStream class is not intended to be subclassed
|
||||||
|
|
|
@ -1264,10 +1264,6 @@ setNonBlocking(SOCKET fd)
|
||||||
[_sibling _setSibling: nil];
|
[_sibling _setSibling: nil];
|
||||||
_sibling = nil;
|
_sibling = nil;
|
||||||
DESTROY(_handler);
|
DESTROY(_handler);
|
||||||
if (_address != 0)
|
|
||||||
{
|
|
||||||
NSZoneFree(0, _address);
|
|
||||||
}
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1286,24 +1282,25 @@ setNonBlocking(SOCKET fd)
|
||||||
#endif
|
#endif
|
||||||
_sock = INVALID_SOCKET;
|
_sock = INVALID_SOCKET;
|
||||||
_handler = nil;
|
_handler = nil;
|
||||||
|
_address.s.sa_family = AF_UNSPEC;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (struct sockaddr*) _address
|
- (struct sockaddr*) _address
|
||||||
{
|
{
|
||||||
return (struct sockaddr*)_address;
|
return &_address.s;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) propertyForKey: (NSString *)key
|
- (id) propertyForKey: (NSString *)key
|
||||||
{
|
{
|
||||||
id result = [super propertyForKey: key];
|
id result = [super propertyForKey: key];
|
||||||
|
|
||||||
if (result == nil && _address != 0)
|
if (result == nil && _address.s.sa_family != AF_UNSPEC)
|
||||||
{
|
{
|
||||||
SOCKET s = [self _sock];
|
SOCKET s = [self _sock];
|
||||||
|
|
||||||
switch (_address->sa_family)
|
switch (_address.s.sa_family)
|
||||||
{
|
{
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
{
|
{
|
||||||
|
@ -1514,18 +1511,7 @@ setNonBlocking(SOCKET fd)
|
||||||
|
|
||||||
- (void) _setAddress: (struct sockaddr*)address
|
- (void) _setAddress: (struct sockaddr*)address
|
||||||
{
|
{
|
||||||
if (_address != 0
|
memcpy(&_address.s, address, GSPrivateSockaddrLength(address));
|
||||||
&& GSPrivateSockaddrLength(_address) != GSPrivateSockaddrLength(address))
|
|
||||||
{
|
|
||||||
NSZoneFree(0, _address);
|
|
||||||
_address = 0;
|
|
||||||
}
|
|
||||||
if (_address == 0)
|
|
||||||
{
|
|
||||||
_address = (struct sockaddr*)
|
|
||||||
NSAllocateCollectable(GSPrivateSockaddrLength(address), 0);
|
|
||||||
}
|
|
||||||
memcpy(_address, address, GSPrivateSockaddrLength(address));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) _setLoopID: (void *)ref
|
- (void) _setLoopID: (void *)ref
|
||||||
|
@ -1622,7 +1608,7 @@ setNonBlocking(SOCKET fd)
|
||||||
{
|
{
|
||||||
[GSSOCKS tryInput: self output: _sibling];
|
[GSSOCKS tryInput: self output: _sibling];
|
||||||
}
|
}
|
||||||
s = socket(_address->sa_family, SOCK_STREAM, 0);
|
s = socket(_address.s.sa_family, SOCK_STREAM, 0);
|
||||||
if (BADSOCKET(s))
|
if (BADSOCKET(s))
|
||||||
{
|
{
|
||||||
[self _recordError];
|
[self _recordError];
|
||||||
|
@ -1639,8 +1625,8 @@ setNonBlocking(SOCKET fd)
|
||||||
{
|
{
|
||||||
[GSTLS tryInput: self output: _sibling];
|
[GSTLS tryInput: self output: _sibling];
|
||||||
}
|
}
|
||||||
result = connect([self _sock], _address,
|
result = connect([self _sock], &_address.s,
|
||||||
GSPrivateSockaddrLength(_address));
|
GSPrivateSockaddrLength(&_address.s));
|
||||||
if (socketError(result))
|
if (socketError(result))
|
||||||
{
|
{
|
||||||
if (!socketWouldBlock())
|
if (!socketWouldBlock())
|
||||||
|
@ -2092,7 +2078,7 @@ setNonBlocking(SOCKET fd)
|
||||||
{
|
{
|
||||||
[GSSOCKS tryInput: _sibling output: self];
|
[GSSOCKS tryInput: _sibling output: self];
|
||||||
}
|
}
|
||||||
s = socket(_address->sa_family, SOCK_STREAM, 0);
|
s = socket(_address.s.sa_family, SOCK_STREAM, 0);
|
||||||
if (BADSOCKET(s))
|
if (BADSOCKET(s))
|
||||||
{
|
{
|
||||||
[self _recordError];
|
[self _recordError];
|
||||||
|
@ -2110,8 +2096,8 @@ setNonBlocking(SOCKET fd)
|
||||||
[GSTLS tryInput: _sibling output: self];
|
[GSTLS tryInput: _sibling output: self];
|
||||||
}
|
}
|
||||||
|
|
||||||
result = connect([self _sock], _address,
|
result = connect([self _sock], &_address.s,
|
||||||
GSPrivateSockaddrLength(_address));
|
GSPrivateSockaddrLength(&_address.s));
|
||||||
if (socketError(result))
|
if (socketError(result))
|
||||||
{
|
{
|
||||||
if (!socketWouldBlock())
|
if (!socketWouldBlock())
|
||||||
|
@ -2447,7 +2433,7 @@ setNonBlocking(SOCKET fd)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = socket(_address->sa_family, SOCK_STREAM, 0);
|
s = socket(_address.s.sa_family, SOCK_STREAM, 0);
|
||||||
if (BADSOCKET(s))
|
if (BADSOCKET(s))
|
||||||
{
|
{
|
||||||
[self _recordError];
|
[self _recordError];
|
||||||
|
@ -2460,9 +2446,9 @@ setNonBlocking(SOCKET fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef BROKEN_SO_REUSEADDR
|
#ifndef BROKEN_SO_REUSEADDR
|
||||||
if (_address->sa_family == AF_INET
|
if (_address.s.sa_family == AF_INET
|
||||||
#ifdef AF_INET6
|
#ifdef AF_INET6
|
||||||
|| _address->sa_family == AF_INET6
|
|| _address.s.sa_family == AF_INET6
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -2479,7 +2465,8 @@ setNonBlocking(SOCKET fd)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bindReturn = bind([self _sock], _address, GSPrivateSockaddrLength(_address));
|
bindReturn = bind([self _sock],
|
||||||
|
&_address.s, GSPrivateSockaddrLength(&_address.s));
|
||||||
if (socketError(bindReturn))
|
if (socketError(bindReturn))
|
||||||
{
|
{
|
||||||
[self _recordError];
|
[self _recordError];
|
||||||
|
|
Loading…
Reference in a new issue