ObjFW  Diff

Differences From Artifact [cfb0eab86c]:

To Artifact [1dc603e93a]:

  • File utils/ofdns/OFDNS.m — part of check-in [0afb04d93c] at 2018-12-22 00:29:42 on branch trunk — OFDNSResolver: Use a delegate for async operations

    Because there is usually only one resolver per thread, having the
    delegate as a property on the resolver would not work. It is therefore
    passed as an argument.

    This only changes the public API so far. Internally, the old target /
    selector / context pattern is still being used. This will be changed
    later. (user: js, size: 2870) [annotate] [blame] [check-ins using]


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

#import "OFApplication.h"
#import "OFArray.h"
#import "OFDNSResolver.h"
#import "OFSandbox.h"
#import "OFStdIOStream.h"

@interface OFDNS: OFObject <OFApplicationDelegate>
@end

OF_APPLICATION_DELEGATE(OFDNS)

@implementation OFDNS
-    (void)DNSResolver: (OFDNSResolver *)resolver
  didResolveDomainName: (OFString *)domainName
	 answerRecords: (OFArray *)answerRecords
      authorityRecords: (OFArray *)authorityRecords
     additionalRecords: (OFArray *)additionalRecords
	       context: (id)context
	     exception: (id)exception
{
	if (exception != nil) {
		[of_stderr writeFormat: @"Failed to resolve: %@\n", exception];
		[OFApplication terminateWithStatus: 1];
	}








|





|




<







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43

#import "OFApplication.h"
#import "OFArray.h"
#import "OFDNSResolver.h"
#import "OFSandbox.h"
#import "OFStdIOStream.h"

@interface OFDNS: OFObject <OFApplicationDelegate, OFDNSResolverDelegate>
@end

OF_APPLICATION_DELEGATE(OFDNS)

@implementation OFDNS
-	(void)resolver: (OFDNSResolver *)resolver
  didResolveDomainName: (OFString *)domainName
	 answerRecords: (OFArray *)answerRecords
      authorityRecords: (OFArray *)authorityRecords
     additionalRecords: (OFArray *)additionalRecords

	     exception: (id)exception
{
	if (exception != nil) {
		[of_stderr writeFormat: @"Failed to resolve: %@\n", exception];
		[OFApplication terminateWithStatus: 1];
	}

95
96
97
98
99
100
101
102
103
104
105
106
107
108
		[resolver setNameServers:
		    [OFArray arrayWithObject: [arguments objectAtIndex: 3]]];
	}

	[resolver asyncResolveHost: [arguments objectAtIndex: 0]
		       recordClass: recordClass
			recordType: recordType
			    target: self
			  selector: @selector(DNSResolver:didResolveDomainName:
					answerRecords:authorityRecords:
					additionalRecords:context:exception:)
			   context: nil];
}
@end







|
<
<
<
<


94
95
96
97
98
99
100
101




102
103
		[resolver setNameServers:
		    [OFArray arrayWithObject: [arguments objectAtIndex: 3]]];
	}

	[resolver asyncResolveHost: [arguments objectAtIndex: 0]
		       recordClass: recordClass
			recordType: recordType
			  delegate: self];




}
@end