22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#import "OFUNIXStreamSocket.h"
#import "OFSocket.h"
#import "OFSocket+Private.h"
#import "OFString.h"
#import "OFAlreadyConnectedException.h"
#import "OFBindUNIXSocketFailedException.h"
#import "OFConnectionFailedException.h"
@implementation OFUNIXStreamSocket
@dynamic delegate;
- (void)connectToPath: (OFString *)path
{
OFSocketAddress address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != OFInvalidSocketHandle)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
address = OFSocketAddressMakeUNIX(path);
if ((_socket = socket(address.sockaddr.un.sun_family,
SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle)
@throw [OFConnectionFailedException
exceptionWithPath: path
socket: self
errNo: OFSocketErrNo()];
_canBlock = true;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
if (connect(_socket, (struct sockaddr *)&address.sockaddr,
address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFConnectionFailedException exceptionWithPath: path
socket: self
errNo: errNo];
}
}
- (void)bindToPath: (OFString *)path
{
OFSocketAddress address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
|
|
|
>
|
|
|
|
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#import "OFUNIXStreamSocket.h"
#import "OFSocket.h"
#import "OFSocket+Private.h"
#import "OFString.h"
#import "OFAlreadyConnectedException.h"
#import "OFBindUNIXSocketFailedException.h"
#import "OFConnectSocketFailedException.h"
@implementation OFUNIXStreamSocket
@dynamic delegate;
- (void)connectToPath: (OFString *)path
{
OFSocketAddress address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != OFInvalidSocketHandle)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
address = OFSocketAddressMakeUNIX(path);
if ((_socket = socket(address.sockaddr.un.sun_family,
SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle)
@throw [OFConnectSocketFailedException
exceptionWithPath: path
socket: self
errNo: OFSocketErrNo()];
_canBlock = true;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
if (connect(_socket, (struct sockaddr *)&address.sockaddr,
address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFConnectSocketFailedException
exceptionWithPath: path
socket: self
errNo: errNo];
}
}
- (void)bindToPath: (OFString *)path
{
OFSocketAddress address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
|