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
|
{
void *pool = objc_autoreleasePoolPush();
OFString *path;
OFUNIXDatagramSocket *sock;
OFSocketAddress address1, address2;
char buffer[5];
path = [[OFSystemInfo temporaryDirectoryPath]
stringByAppendingPathComponent: [[OFUUID UUID] UUIDString]];
@try {
TEST(@"+[socket]", (sock = [OFUNIXDatagramSocket socket]))
TEST(@"-[bindToPath:]", R(address1 = [sock bindToPath: path]))
TEST(@"-[sendBuffer:length:receiver:]",
R([sock sendBuffer: "Hello" length: 5 receiver: &address1]))
TEST(@"-[receiveIntoBuffer:length:sender:]",
[sock receiveIntoBuffer: buffer
length: 5
sender: &address2] == 5 &&
memcmp(buffer, "Hello", 5) == 0 &&
OFSocketAddressEqual(&address1, &address2) &&
OFSocketAddressHash(&address1) ==
OFSocketAddressHash(&address2))
} @finally {
[[OFFileManager defaultManager] removeItemAtPath: path];
}
objc_autoreleasePoolPop(pool);
}
@end
|
>
>
>
>
>
>
>
>
>
>
>
|
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
|
{
void *pool = objc_autoreleasePoolPush();
OFString *path;
OFUNIXDatagramSocket *sock;
OFSocketAddress address1, address2;
char buffer[5];
#ifdef OF_HAVE_FILES
path = [[OFSystemInfo temporaryDirectoryPath]
stringByAppendingPathComponent: [[OFUUID UUID] UUIDString]];
#else
/*
* We can have sockets, including UNIX sockets, while file support is
* disabled.
*/
path = [OFString stringWithFormat: @"/tmp/%@",
[[OFUUID UUID] UUIDString]];
#endif
@try {
TEST(@"+[socket]", (sock = [OFUNIXDatagramSocket socket]))
TEST(@"-[bindToPath:]", R(address1 = [sock bindToPath: path]))
TEST(@"-[sendBuffer:length:receiver:]",
R([sock sendBuffer: "Hello" length: 5 receiver: &address1]))
TEST(@"-[receiveIntoBuffer:length:sender:]",
[sock receiveIntoBuffer: buffer
length: 5
sender: &address2] == 5 &&
memcmp(buffer, "Hello", 5) == 0 &&
OFSocketAddressEqual(&address1, &address2) &&
OFSocketAddressHash(&address1) ==
OFSocketAddressHash(&address2))
} @finally {
#ifdef OF_HAVE_FILES
[[OFFileManager defaultManager] removeItemAtPath: path];
#endif
}
objc_autoreleasePoolPop(pool);
}
@end
|