Overview
Comment: | OFDNSResolver: Set UDP sockets to non-blocking |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
2b72aa8c86258f7b581e1e6ed6638ab6 |
User & Date: | js on 2018-08-04 16:49:15 |
Other Links: | manifest | tags |
Context
2018-08-04
| ||
23:43 | OFDNSResolver: Improve error reporting check-in: 647ec47eda user: js tags: trunk | |
16:49 | OFDNSResolver: Set UDP sockets to non-blocking check-in: 2b72aa8c86 user: js tags: trunk | |
16:23 | Support for non-blocking UDP sockets check-in: 7de9d67be9 user: js tags: trunk | |
Changes
Modified src/OFDNSResolver.m from [ee463ccad3] to [bce70b2657].
︙ | ︙ | |||
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 | */ @interface OFDNSResolver_context: OFObject { OFString *_host; OFArray OF_GENERIC(OFString *) *_nameServers, *_searchDomains; size_t _nameServersIndex, _searchDomainsIndex; OFMutableData *_queryData; id _target; SEL _selector; id _userContext; } @property (readonly, nonatomic) OFString *host; @property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *nameServers; @property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *searchDomains; @property (nonatomic) size_t nameServersIndex; @property (nonatomic) size_t searchDomainsIndex; @property (readonly, nonatomic) OFMutableData *queryData; @property (readonly, nonatomic) id target; @property (readonly, nonatomic) SEL selector; @property (readonly, nonatomic) id userContext; - (instancetype)initWithHost: (OFString *)host nameServers: (OFArray OF_GENERIC(OFString *) *)nameServers searchDomains: (OFArray OF_GENERIC(OFString *) *)searchDomains queryData: (OFMutableData *)queryData target: (id)target selector: (SEL)selector userContext: (id)userContext; @end @interface OFDNSResolver () | > > > | 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 OFDNSResolver_context: OFObject { OFString *_host; OFArray OF_GENERIC(OFString *) *_nameServers, *_searchDomains; size_t _nameServersIndex, _searchDomainsIndex; OFNumber *_ID; OFMutableData *_queryData; id _target; SEL _selector; id _userContext; } @property (readonly, nonatomic) OFString *host; @property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *nameServers; @property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *searchDomains; @property (nonatomic) size_t nameServersIndex; @property (nonatomic) size_t searchDomainsIndex; @property (readonly, nonatomic) OFNumber *ID; @property (readonly, nonatomic) OFMutableData *queryData; @property (readonly, nonatomic) id target; @property (readonly, nonatomic) SEL selector; @property (readonly, nonatomic) id userContext; - (instancetype)initWithHost: (OFString *)host nameServers: (OFArray OF_GENERIC(OFString *) *)nameServers searchDomains: (OFArray OF_GENERIC(OFString *) *)searchDomains ID: (OFNumber *)ID queryData: (OFMutableData *)queryData target: (id)target selector: (SEL)selector userContext: (id)userContext; @end @interface OFDNSResolver () |
︙ | ︙ | |||
486 487 488 489 490 491 492 | TTL: TTL] autorelease]; } @implementation OFDNSResolver_context @synthesize host = _host, nameServers = _nameServers; @synthesize searchDomains = _searchDomains; @synthesize nameServersIndex = _nameServersIndex; | | > | > > > | 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 | TTL: TTL] autorelease]; } @implementation OFDNSResolver_context @synthesize host = _host, nameServers = _nameServers; @synthesize searchDomains = _searchDomains; @synthesize nameServersIndex = _nameServersIndex; @synthesize searchDomainsIndex = _searchDomainsIndex, ID = _ID; @synthesize queryData = _queryData, target = _target, selector = _selector; @synthesize userContext = _userContext; - (instancetype)initWithHost: (OFString *)host nameServers: (OFArray OF_GENERIC(OFString *) *)nameServers searchDomains: (OFArray OF_GENERIC(OFString *) *)searchDomains ID: (OFNumber *)ID queryData: (OFMutableData *)queryData target: (id)target selector: (SEL)selector userContext: (id)userContext { self = [super init]; @try { _host = [host copy]; _nameServers = [nameServers copy]; _searchDomains = [searchDomains copy]; _ID = [ID retain]; _queryData = [queryData retain]; _target = [target retain]; _selector = selector; _userContext = [userContext retain]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_host release]; [_nameServers release]; [_searchDomains release]; [_ID release]; [_queryData release]; [_target release]; [_userContext release]; [super dealloc]; } @end |
︙ | ︙ | |||
995 996 997 998 999 1000 1001 | return false; } - (size_t)of_socket: (OFUDPSocket *)sock didSendBuffer: (void **)buffer bytesSent: (size_t)bytesSent receiver: (of_socket_address_t *)receiver | | | > > > > > > > > > > > > | 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 | return false; } - (size_t)of_socket: (OFUDPSocket *)sock didSendBuffer: (void **)buffer bytesSent: (size_t)bytesSent receiver: (of_socket_address_t *)receiver context: (id)DNSResolverContext exception: (id)exception { if (exception != nil) { id target = [[[DNSResolverContext target] retain] autorelease]; SEL selector = [DNSResolverContext selector]; void (*callback)(id, SEL, OFArray *, id, id) = (void (*)(id, SEL, OFArray *, id, id)) [target methodForSelector: selector]; [_queries removeObjectForKey: [DNSResolverContext ID]]; callback(target, selector, nil, [DNSResolverContext userContext], exception); return 0; } [sock asyncReceiveIntoBuffer: [self allocMemoryWithSize: 512] length: 512 target: self selector: @selector(of_socket:didReceiveIntoBuffer: length:sender:context:exception:) context: nil]; |
︙ | ︙ | |||
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 | [data addItems: &tmp count: 2]; DNSResolverContext = [[[OFDNSResolver_context alloc] initWithHost: host nameServers: _nameServers searchDomains: _searchDomains queryData: data target: target selector: selector userContext: context] autorelease]; [_queries setObject: DNSResolverContext forKey: ID]; address = of_socket_address_parse_ip( [[DNSResolverContext nameServers] firstObject], 53); #ifdef OF_HAVE_IPV6 if (address.address.ss_family == AF_INET6) { if (_IPv6Socket == nil) { _IPv6Socket = [[OFUDPSocket alloc] init]; [_IPv6Socket bindToHost: @"::" port: 0]; } sock = _IPv6Socket; } else { #endif if (_IPv4Socket == nil) { _IPv4Socket = [[OFUDPSocket alloc] init]; [_IPv4Socket bindToHost: @"0.0.0.0" port: 0]; } sock = _IPv4Socket; #ifdef OF_HAVE_IPV6 } #endif [sock asyncSendBuffer: [data items] length: [data count] receiver: address target: self selector: @selector(of_socket:didSendBuffer:bytesSent: receiver:context:exception:) | > > > | | 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 | [data addItems: &tmp count: 2]; DNSResolverContext = [[[OFDNSResolver_context alloc] initWithHost: host nameServers: _nameServers searchDomains: _searchDomains ID: ID queryData: data target: target selector: selector userContext: context] autorelease]; [_queries setObject: DNSResolverContext forKey: ID]; address = of_socket_address_parse_ip( [[DNSResolverContext nameServers] firstObject], 53); #ifdef OF_HAVE_IPV6 if (address.address.ss_family == AF_INET6) { if (_IPv6Socket == nil) { _IPv6Socket = [[OFUDPSocket alloc] init]; [_IPv6Socket bindToHost: @"::" port: 0]; [_IPv6Socket setBlocking: false]; } sock = _IPv6Socket; } else { #endif if (_IPv4Socket == nil) { _IPv4Socket = [[OFUDPSocket alloc] init]; [_IPv4Socket bindToHost: @"0.0.0.0" port: 0]; [_IPv4Socket setBlocking: false]; } sock = _IPv4Socket; #ifdef OF_HAVE_IPV6 } #endif [sock asyncSendBuffer: [data items] length: [data count] receiver: address target: self selector: @selector(of_socket:didSendBuffer:bytesSent: receiver:context:exception:) context: DNSResolverContext]; objc_autoreleasePoolPop(pool); } - (void)close { [_IPv4Socket cancelAsyncRequests]; |
︙ | ︙ |