Differences From Artifact [c8e3c83553]:
- File
src/OFUDPSocket.m
— part of check-in
[2ae01218ef]
at
2017-06-12 22:29:41
on branch trunk
— OFWriteFailedException: Add -[bytesWritten]
This allows retrieving the number of bytes already written before the
write failed, allowing to retry without writing data that has already
been written. (user: js, size: 14860) [annotate] [blame] [check-ins using]
To Artifact [c1cf4f8ea1]:
- File src/OFUDPSocket.m — part of check-in [958da109d3] at 2017-09-23 22:07:34 on branch trunk — Support for passing a context to async IO handlers (user: js, size: 15111) [annotate] [blame] [check-ins using]
| ︙ | ︙ | |||
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
@interface OFUDPSocket_ResolveThread: OFThread
{
OFThread *_sourceThread;
OFString *_host;
uint16_t _port;
id _target;
SEL _selector;
# ifdef OF_HAVE_BLOCKS
of_udp_socket_async_resolve_block_t _block;
# endif
of_udp_socket_address_t _address;
OFException *_exception;
}
- initWithSourceThread: (OFThread *)sourceThread
host: (OFString *)host
port: (uint16_t)port
target: (id)target
| > | > > > | 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
@interface OFUDPSocket_ResolveThread: OFThread
{
OFThread *_sourceThread;
OFString *_host;
uint16_t _port;
id _target;
SEL _selector;
id _context;
# ifdef OF_HAVE_BLOCKS
of_udp_socket_async_resolve_block_t _block;
# endif
of_udp_socket_address_t _address;
OFException *_exception;
}
- initWithSourceThread: (OFThread *)sourceThread
host: (OFString *)host
port: (uint16_t)port
target: (id)target
selector: (SEL)selector
context: (id)context;
# ifdef OF_HAVE_BLOCKS
- initWithSourceThread: (OFThread *)sourceThread
host: (OFString *)host
port: (uint16_t)port
block: (of_udp_socket_async_resolve_block_t)block;
# endif
@end
@implementation OFUDPSocket_ResolveThread
- initWithSourceThread: (OFThread *)sourceThread
host: (OFString *)host
port: (uint16_t)port
target: (id)target
selector: (SEL)selector
context: (id)context
{
self = [super init];
@try {
_sourceThread = [sourceThread retain];
_host = [host retain];
_port = port;
_target = [target retain];
_selector = selector;
_context = [context retain];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
|
| ︙ | ︙ | |||
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# endif
- (void)dealloc
{
[_sourceThread release];
[_host release];
[_target release];
# ifdef OF_HAVE_BLOCKS
[_block release];
# endif
[_exception release];
[super dealloc];
}
- (void)didResolve
{
[self join];
# ifdef OF_HAVE_BLOCKS
if (_block != NULL)
_block(_host, _port, _address, _exception);
else {
# endif
void (*func)(id, SEL, OFString *, uint16_t,
| > | | | | > | 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# endif
- (void)dealloc
{
[_sourceThread release];
[_host release];
[_target release];
[_context release];
# ifdef OF_HAVE_BLOCKS
[_block release];
# endif
[_exception release];
[super dealloc];
}
- (void)didResolve
{
[self join];
# ifdef OF_HAVE_BLOCKS
if (_block != NULL)
_block(_host, _port, _address, _exception);
else {
# endif
void (*func)(id, SEL, OFString *, uint16_t,
of_udp_socket_address_t, id, OFException *) =
(void (*)(id, SEL, OFString *, uint16_t,
of_udp_socket_address_t, id, OFException *))
[_target methodForSelector: _selector];
func(_target, _selector, _host, _port, _address, _context,
_exception);
# ifdef OF_HAVE_BLOCKS
}
# endif
}
- (id)main
{
|
| ︙ | ︙ | |||
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
}
#ifdef OF_HAVE_THREADS
+ (void)asyncResolveAddressForHost: (OFString *)host
port: (uint16_t)port
target: (id)target
selector: (SEL)selector
{
void *pool = objc_autoreleasePoolPush();
[[[[OFUDPSocket_ResolveThread alloc]
initWithSourceThread: [OFThread currentThread]
host: host
port: port
target: target
| > | > | 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
}
#ifdef OF_HAVE_THREADS
+ (void)asyncResolveAddressForHost: (OFString *)host
port: (uint16_t)port
target: (id)target
selector: (SEL)selector
context: (id)context
{
void *pool = objc_autoreleasePoolPush();
[[[[OFUDPSocket_ResolveThread alloc]
initWithSourceThread: [OFThread currentThread]
host: host
port: port
target: target
selector: selector
context: context] autorelease] start];
objc_autoreleasePoolPop(pool);
}
# ifdef OF_HAVE_BLOCKS
+ (void)asyncResolveAddressForHost: (OFString *)host
port: (uint16_t)port
|
| ︙ | ︙ | |||
556 557 558 559 560 561 562 563 564 565 566 567 |
return ret;
}
- (void)asyncReceiveIntoBuffer: (void *)buffer
length: (size_t)length
target: (id)target
selector: (SEL)selector
{
[OFRunLoop of_addAsyncReceiveForUDPSocket: self
buffer: buffer
length: length
target: target
| > | > | 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 |
return ret;
}
- (void)asyncReceiveIntoBuffer: (void *)buffer
length: (size_t)length
target: (id)target
selector: (SEL)selector
context: (id)context
{
[OFRunLoop of_addAsyncReceiveForUDPSocket: self
buffer: buffer
length: length
target: target
selector: selector
context: context];
}
#ifdef OF_HAVE_BLOCKS
- (void)asyncReceiveIntoBuffer: (void *)buffer
length: (size_t)length
block: (of_udp_socket_async_receive_block_t)block
{
|
| ︙ | ︙ |