ObjFW  Check-in [0b475d18d5]

Overview
Comment:OFDNSResolver: Have one shared IPv4/IPv6 socket
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0b475d18d5522e90e8fbb043e01d34dcdc6effa5a3830d75ed9a50a0fb15b53d
User & Date: js on 2018-08-04 15:50:28
Other Links: manifest | tags
Context
2018-08-04
16:23
Support for non-blocking UDP sockets check-in: 7de9d67be9 user: js tags: trunk
15:50
OFDNSResolver: Have one shared IPv4/IPv6 socket check-in: 0b475d18d5 user: js tags: trunk
15:35
Use OF_HAVE_IPV6 instead of HAVE_IPV6 check-in: e36455441d user: js tags: trunk
Changes

Modified src/OFDNSResolver.h from [72b67bd9be] to [d1d07aeb8b].

21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42




43
44
45
46
47
48
49

OF_ASSUME_NONNULL_BEGIN

@class OFArray OF_GENERIC(ObjectType);
@class OFDictionary OF_GENERIC(KeyType, ObjectType);
@class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
@class OFNumber;


/*!
 * @class OFDNSResolver OFDNSResolver.h ObjFW/OFDNSResolver.h
 *
 * @brief A class for resolving DNS names.
 */
@interface OFDNSResolver: OFObject
{
	OFDictionary OF_GENERIC(OFString *, OFArray OF_GENERIC(OFString *) *)
	    *_staticHosts;
	OFArray OF_GENERIC(OFString *) *_nameServers;
	OFString *_Nullable _localDomain;
	OFArray OF_GENERIC(OFString *) *_searchDomains;
	size_t _minNumberOfDotsInAbsoluteName;
	bool _usesTCP;




	OFMutableDictionary OF_GENERIC(OFNumber *, id) *_queries;
}

/*!
 * @brief A dictionary of static hosts.
 *
 * This dictionary is checked before actually looking up a host.







>















>
>
>
>







21
22
23
24
25
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

OF_ASSUME_NONNULL_BEGIN

@class OFArray OF_GENERIC(ObjectType);
@class OFDictionary OF_GENERIC(KeyType, ObjectType);
@class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
@class OFNumber;
@class OFUDPSocket;

/*!
 * @class OFDNSResolver OFDNSResolver.h ObjFW/OFDNSResolver.h
 *
 * @brief A class for resolving DNS names.
 */
@interface OFDNSResolver: OFObject
{
	OFDictionary OF_GENERIC(OFString *, OFArray OF_GENERIC(OFString *) *)
	    *_staticHosts;
	OFArray OF_GENERIC(OFString *) *_nameServers;
	OFString *_Nullable _localDomain;
	OFArray OF_GENERIC(OFString *) *_searchDomains;
	size_t _minNumberOfDotsInAbsoluteName;
	bool _usesTCP;
	OFUDPSocket *_IPv4Socket;
#ifdef OF_HAVE_IPV6
	OFUDPSocket *_IPv6Socket;
#endif
	OFMutableDictionary OF_GENERIC(OFNumber *, id) *_queries;
}

/*!
 * @brief A dictionary of static hosts.
 *
 * This dictionary is checked before actually looking up a host.

Modified src/OFDNSResolver.m from [bad70f4110] to [ee463ccad3].

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

/*
 * TODO:
 *
 *  - Timeouts
 *  - Resolve with each search domain
 *  - Iterate through name servers
 *  - IPv6 for talking to the name servers
 *  - Fallback to TCP
 *  - More record types
 */

@interface OFDNSResolver_context: OFObject
{
	OFString *_host;
	OFArray OF_GENERIC(OFString *) *_nameServers, *_searchDomains;
	size_t _nameServersIndex, _searchDomainsIndex;







<

<







56
57
58
59
60
61
62

63

64
65
66
67
68
69
70

/*
 * TODO:
 *
 *  - Timeouts
 *  - Resolve with each search domain
 *  - Iterate through name servers

 *  - Fallback to TCP

 */

@interface OFDNSResolver_context: OFObject
{
	OFString *_host;
	OFArray OF_GENERIC(OFString *) *_nameServers, *_searchDomains;
	size_t _nameServersIndex, _searchDomainsIndex;
634
635
636
637
638
639
640


641
642
643
644
645




646
647
648
649
650
651
652
	}

	return self;
}

- (void)dealloc
{


	[_staticHosts release];
	[_nameServers release];
	[_localDomain release];
	[_searchDomains release];
	[_queries release];





	[super dealloc];
}

#ifdef OF_HAVE_FILES
- (void)of_parseHosts: (OFString *)path
{







>
>





>
>
>
>







632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
	}

	return self;
}

- (void)dealloc
{
	[self close];

	[_staticHosts release];
	[_nameServers release];
	[_localDomain release];
	[_searchDomains release];
	[_queries release];
	[_IPv4Socket release];
#ifdef OF_HAVE_IPV6
	[_IPv6Socket release];
#endif

	[super dealloc];
}

#ifdef OF_HAVE_FILES
- (void)of_parseHosts: (OFString *)path
{
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
	       queryData: data
		  target: target
		selector: selector
	     userContext: context] autorelease];
	[_queries setObject: DNSResolverContext
		     forKey: ID];







	sock = [OFUDPSocket socket];
	[sock bindToHost: @"0.0.0.0"
		    port: 0];

	address = of_socket_address_parse_ip(








	    [[DNSResolverContext nameServers] firstObject], 53);





	[sock asyncSendBuffer: [data items]
		       length: [data count]
		     receiver: address
		       target: self
		     selector: @selector(of_socket:didSendBuffer:bytesSent:
				   receiver:context:exception:)
		      context: nil];

	objc_autoreleasePoolPop(pool);
}















@end







>
>
>
>
>
>
|
|
|
|
|
>
>
>
>
>
>
>
>
|
>
>
>
>











>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

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
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
	       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:)
		      context: nil];

	objc_autoreleasePoolPop(pool);
}

- (void)close
{
	[_IPv4Socket cancelAsyncRequests];
	[_IPv4Socket close];
	[_IPv4Socket release];
	_IPv4Socket = nil;

#ifdef OF_HAVE_IPV6
	[_IPv6Socket cancelAsyncRequests];
	[_IPv6Socket close];
	[_IPv6Socket release];
	_IPv6Socket = nil;
#endif
}
@end