ObjFW  Diff

Differences From Artifact [c453a27f56]:

To Artifact [bb02552c53]:


84
85
86
87
88
89
90

91
92
93
94
95
96
97
98
99

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

116
117
118
119
120
121
122
123
124
125

126
127
128
129
130
131
132
	OFString *host;
	uint16_t port;
	id target;
	SEL selector;
#ifdef OF_HAVE_BLOCKS
	of_tcpsocket_async_connect_block_t connectBlock;
#endif

	OFException *exception;
}

- initWithSourceThread: (OFThread*)sourceThread
		socket: (OFTCPSocket*)socket
		  host: (OFString*)host
		  port: (uint16_t)port
		target: (id)target
	      selector: (SEL)selector;

#ifdef OF_HAVE_BLOCKS
- initWithSourceThread: (OFThread*)sourceThread
		socket: (OFTCPSocket*)socket
		  host: (OFString*)host
		  port: (uint16_t)port
		 block: (of_tcpsocket_async_connect_block_t)block;
#endif
@end

@implementation OFTCPSocket_ConnectThread
- initWithSourceThread: (OFThread*)sourceThread_
		socket: (OFTCPSocket*)sock_
		  host: (OFString*)host_
		  port: (uint16_t)port_
		target: (id)target_
	      selector: (SEL)selector_

{
	self = [super init];

	@try {
		sourceThread = [sourceThread_ retain];
		sock = [sock_ retain];
		host = [host_ copy];
		port = port_;
		target = [target_ retain];
		selector = selector_;

	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}







>








|
>
















>










>







84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
	OFString *host;
	uint16_t port;
	id target;
	SEL selector;
#ifdef OF_HAVE_BLOCKS
	of_tcpsocket_async_connect_block_t connectBlock;
#endif
	id context;
	OFException *exception;
}

- initWithSourceThread: (OFThread*)sourceThread
		socket: (OFTCPSocket*)socket
		  host: (OFString*)host
		  port: (uint16_t)port
		target: (id)target
	      selector: (SEL)selector
	       context: (id)context;
#ifdef OF_HAVE_BLOCKS
- initWithSourceThread: (OFThread*)sourceThread
		socket: (OFTCPSocket*)socket
		  host: (OFString*)host
		  port: (uint16_t)port
		 block: (of_tcpsocket_async_connect_block_t)block;
#endif
@end

@implementation OFTCPSocket_ConnectThread
- initWithSourceThread: (OFThread*)sourceThread_
		socket: (OFTCPSocket*)sock_
		  host: (OFString*)host_
		  port: (uint16_t)port_
		target: (id)target_
	      selector: (SEL)selector_
	       context: (id)context_
{
	self = [super init];

	@try {
		sourceThread = [sourceThread_ retain];
		sock = [sock_ retain];
		host = [host_ copy];
		port = port_;
		target = [target_ retain];
		selector = selector_;
		context = [context_ retain];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
	[sourceThread release];
	[sock release];
	[host release];
	[target release];
#ifdef OF_HAVE_BLOCKS
	[connectBlock release];
#endif

	[exception release];

	[super dealloc];
}

- (void)didConnect
{
	[self join];

#ifdef OF_HAVE_BLOCKS
	if (connectBlock != NULL)
		connectBlock(sock, exception);
	else {
#endif
		void (*func)(id, SEL, OFTCPSocket*, OFException*) =
		    (void(*)(id, SEL, OFTCPSocket*, OFException*))[target
		    methodForSelector: selector];

		func(target, selector, sock, exception);
#ifdef OF_HAVE_BLOCKS
	}
#endif
}

- (id)main
{







>














|
|


|







164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
	[sourceThread release];
	[sock release];
	[host release];
	[target release];
#ifdef OF_HAVE_BLOCKS
	[connectBlock release];
#endif
	[context release];
	[exception release];

	[super dealloc];
}

- (void)didConnect
{
	[self join];

#ifdef OF_HAVE_BLOCKS
	if (connectBlock != NULL)
		connectBlock(sock, exception);
	else {
#endif
		void (*func)(id, SEL, OFTCPSocket*, id, OFException*) =
		    (void(*)(id, SEL, OFTCPSocket*, id, OFException*))[target
		    methodForSelector: selector];

		func(target, selector, sock, context, exception);
#ifdef OF_HAVE_BLOCKS
	}
#endif
}

- (id)main
{
422
423
424
425
426
427
428

429
430
431
432
433
434
435
436
437
438

439
440
441
442
443
444
445
					port: destinationPort];
}

- (void)asyncConnectToHost: (OFString*)host
		      port: (uint16_t)port
		    target: (id)target
		  selector: (SEL)selector

{
	void *pool = objc_autoreleasePoolPush();

	[[[[OFTCPSocket_ConnectThread alloc]
	    initWithSourceThread: [OFThread currentThread]
			  socket: self
			    host: host
			    port: port
			  target: target
			selector: selector] autorelease] start];


	objc_autoreleasePoolPop(pool);
}

#ifdef OF_HAVE_BLOCKS
- (void)asyncConnectToHost: (OFString*)host
		      port: (uint16_t)port







>









|
>







427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
					port: destinationPort];
}

- (void)asyncConnectToHost: (OFString*)host
		      port: (uint16_t)port
		    target: (id)target
		  selector: (SEL)selector
		   context: (id)context
{
	void *pool = objc_autoreleasePoolPush();

	[[[[OFTCPSocket_ConnectThread alloc]
	    initWithSourceThread: [OFThread currentThread]
			  socket: self
			    host: host
			    port: port
			  target: target
			selector: selector
			 context: context] autorelease] start];

	objc_autoreleasePoolPop(pool);
}

#ifdef OF_HAVE_BLOCKS
- (void)asyncConnectToHost: (OFString*)host
		      port: (uint16_t)port
647
648
649
650
651
652
653

654
655
656
657

658
659
660
661
662
663
664
	newSocket->sockAddrLen = addrLen;

	return newSocket;
}

- (void)asyncAcceptWithTarget: (id)target
		     selector: (SEL)selector

{
	[OFRunLoop OF_addAsyncAcceptForTCPSocket: self
					  target: target
					selector: selector];

}

#ifdef OF_HAVE_BLOCKS
- (void)asyncAcceptWithBlock: (of_tcpsocket_async_accept_block_t)block
{
	[OFRunLoop OF_addAsyncAcceptForTCPSocket: self
					   block: block];







>



|
>







654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
	newSocket->sockAddrLen = addrLen;

	return newSocket;
}

- (void)asyncAcceptWithTarget: (id)target
		     selector: (SEL)selector
		      context: (id)context
{
	[OFRunLoop OF_addAsyncAcceptForTCPSocket: self
					  target: target
					selector: selector
					 context: context];
}

#ifdef OF_HAVE_BLOCKS
- (void)asyncAcceptWithBlock: (of_tcpsocket_async_accept_block_t)block
{
	[OFRunLoop OF_addAsyncAcceptForTCPSocket: self
					   block: block];