10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
*/
#import "config.h"
#import <stdlib.h>
#import <string.h>
#import <unistd.h>
#import "OFSocket.h"
@implementation OFSocketAddress
+ newWithHost: (const char*)host
andPort: (uint16_t)port
andFamily: (int)family
andType: (int)type
andProtocol: (int)protocol
|
>
>
|
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
*/
#import "config.h"
#import <stdlib.h>
#import <string.h>
#import <unistd.h>
#import <wchar.h>
#import "OFSocket.h"
#import "OFExceptions.h"
@implementation OFSocketAddress
+ newWithHost: (const char*)host
andPort: (uint16_t)port
andFamily: (int)family
andType: (int)type
andProtocol: (int)protocol
|
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
@throw exception;
}
return ret;
}
- (size_t)writeNBytes: (size_t)size
fromBuffer: (uint8_t*)buf
{
ssize_t ret;
if ((ret = send(sock, buf, size, 0)) < 0) {
/* FIXME: Throw exception */
return 0;
}
/* This is safe, as we already checked < 0 */
return ret;
}
@end
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
@throw exception;
}
return ret;
}
- (size_t)writeNBytes: (size_t)size
fromBuffer: (const uint8_t*)buf
{
ssize_t ret;
if ((ret = send(sock, buf, size, 0)) < 0) {
/* FIXME: Throw exception */
return 0;
}
/* This is safe, as we already checked < 0 */
return ret;
}
- (size_t)writeCString: (const char*)str
{
return [self writeNBytes: strlen(str)
fromBuffer: (const uint8_t*)str];
}
- (size_t)writeWideCString: (const wchar_t*)str
{
size_t len = wcslen(str);
if (len > SIZE_MAX / sizeof(wchar_t))
[[OFOutOfRangeException newWithObject: self] raise];
return [self writeNBytes: len * sizeof(wchar_t)
fromBuffer: (const uint8_t*)str];
}
@end
|