90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
close(sock);
sock = -1;
continue;
}
break;
}
freeaddrinfo(res0);
if (sock < 0)
@throw [OFConnectionFailedException newWithObject: self
andHost: host
andPort: port];
|
|
|
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
close(sock);
sock = -1;
continue;
}
break;
}
freeaddrinfo(res0);
if (sock < 0)
@throw [OFConnectionFailedException newWithObject: self
andHost: host
andPort: port];
|
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
}
- (size_t)readNBytes: (size_t)size
intoBuffer: (uint8_t*)buf
{
ssize_t ret;
if (sock < 0)
@throw [OFNotConnectedException newWithObject: self];
if ((ret = recv(sock, buf, size, 0)) < 0)
@throw [OFReadFailedException newWithObject: self
andSize: size];
/* This is safe, as we already checked < 0 */
return ret;
}
- (uint8_t*)readNBytes: (size_t)size
{
uint8_t *ret;
if (sock < 0)
@throw [OFNotConnectedException newWithObject: self];
ret = [self getMemWithSize: size];
@try {
[self readNBytes: size
intoBuffer: ret];
} @catch (id exception) {
[self freeMem: ret];
@throw exception;
}
return ret;
}
- (size_t)writeNBytes: (size_t)size
fromBuffer: (const uint8_t*)buf
{
ssize_t ret;
if (sock < 0)
@throw [OFNotConnectedException newWithObject: self];
if ((ret = send(sock, buf, size, 0)) < 0)
@throw [OFWriteFailedException newWithObject: self
andSize: size];
/* This is safe, as we already checked < 0 */
return ret;
}
- (size_t)writeCString: (const char*)str
{
if (sock < 0)
@throw [OFNotConnectedException newWithObject: self];
return [self writeNBytes: strlen(str)
fromBuffer: (const uint8_t*)str];
}
- setBlocking: (BOOL)enable
|
|
|
|
|
|
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
}
- (size_t)readNBytes: (size_t)size
intoBuffer: (uint8_t*)buf
{
ssize_t ret;
if (sock < 0)
@throw [OFNotConnectedException newWithObject: self];
if ((ret = recv(sock, buf, size, 0)) < 0)
@throw [OFReadFailedException newWithObject: self
andSize: size];
/* This is safe, as we already checked < 0 */
return ret;
}
- (uint8_t*)readNBytes: (size_t)size
{
uint8_t *ret;
if (sock < 0)
@throw [OFNotConnectedException newWithObject: self];
ret = [self getMemWithSize: size];
@try {
[self readNBytes: size
intoBuffer: ret];
} @catch (id exception) {
[self freeMem: ret];
@throw exception;
}
return ret;
}
- (size_t)writeNBytes: (size_t)size
fromBuffer: (const uint8_t*)buf
{
ssize_t ret;
if (sock < 0)
@throw [OFNotConnectedException newWithObject: self];
if ((ret = send(sock, buf, size, 0)) < 0)
@throw [OFWriteFailedException newWithObject: self
andSize: size];
/* This is safe, as we already checked < 0 */
return ret;
}
- (size_t)writeCString: (const char*)str
{
if (sock < 0)
@throw [OFNotConnectedException newWithObject: self];
return [self writeNBytes: strlen(str)
fromBuffer: (const uint8_t*)str];
}
- setBlocking: (BOOL)enable
|
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
@throw [OFSetOptionFailedException newWithObject: self];
return self;
}
- close
{
if (sock < 0)
@throw [OFNotConnectedException newWithObject: self];
sock = -1;
if (saddr != NULL)
[self freeMem: saddr];
saddr_len = 0;
return self;
}
@end
#endif
|
|
|
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
@throw [OFSetOptionFailedException newWithObject: self];
return self;
}
- close
{
if (sock < 0)
@throw [OFNotConnectedException newWithObject: self];
sock = -1;
if (saddr != NULL)
[self freeMem: saddr];
saddr_len = 0;
return self;
}
@end
#endif
|