ObjFW  Diff

Differences From Artifact [1cb22455c7]:

To Artifact [536375a07c]:


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
@end

#ifdef OF_HAVE_SOCKETS
@interface OFRunLoop_QueueItem: OFObject
{
@public
	id _delegate;
	/* TODO: Remove once everything is moved to using delegates */
	id _target;
	SEL _selector;
	id _context;
}

- (bool)handleObject: (id)object;
@end

@interface OFRunLoop_ReadQueueItem: OFRunLoop_QueueItem
{







<
<
<
<







71
72
73
74
75
76
77




78
79
80
81
82
83
84
@end

#ifdef OF_HAVE_SOCKETS
@interface OFRunLoop_QueueItem: OFObject
{
@public
	id _delegate;




}

- (bool)handleObject: (id)object;
@end

@interface OFRunLoop_ReadQueueItem: OFRunLoop_QueueItem
{
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
{
	OF_UNRECOGNIZED_SELECTOR
}

- (void)dealloc
{
	[_delegate release];
	[_target release];
	[_context release];

	[super dealloc];
}
@end

@implementation OFRunLoop_ReadQueueItem
- (bool)handleObject: (id)object







<
<







295
296
297
298
299
300
301


302
303
304
305
306
307
308
{
	OF_UNRECOGNIZED_SELECTOR
}

- (void)dealloc
{
	[_delegate release];



	[super dealloc];
}
@end

@implementation OFRunLoop_ReadQueueItem
- (bool)handleObject: (id)object
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560


561
562
563
564
565
566
567
568
@end

@implementation OFRunLoop_ConnectQueueItem
- (bool)handleObject: (id)object
{
	id exception = nil;
	int errNo;
	void (*func)(id, SEL, OFTCPSocket *, id, id);

	if ((errNo = [object of_socketError]) != 0)
		exception = [OFConnectionFailedException
		    exceptionWithHost: nil
				 port: 0
			       socket: object
				errNo: errNo];

	func = (void (*)(id, SEL, OFTCPSocket *, id, id))
	    [_target methodForSelector: _selector];


	func(_target, _selector, object, _context, exception);

	return false;
}
@end

@implementation OFRunLoop_AcceptQueueItem
- (bool)handleObject: (id)object







<








<
|
>
>
|







537
538
539
540
541
542
543

544
545
546
547
548
549
550
551

552
553
554
555
556
557
558
559
560
561
562
@end

@implementation OFRunLoop_ConnectQueueItem
- (bool)handleObject: (id)object
{
	id exception = nil;
	int errNo;


	if ((errNo = [object of_socketError]) != 0)
		exception = [OFConnectionFailedException
		    exceptionWithHost: nil
				 port: 0
			       socket: object
				errNo: errNo];


	if ([_delegate respondsToSelector:
	    @selector(of_socketDidConnect:exception:)])
		[_delegate of_socketDidConnect: object
				     exception: exception];

	return false;
}
@end

@implementation OFRunLoop_AcceptQueueItem
- (bool)handleObject: (id)object
629
630
631
632
633
634
635
636
637


638



639

640



641
642
643

644
645
646
647
648
649
650
	}

# ifdef OF_HAVE_BLOCKS
	if (_block != NULL)
		return _block(object, _buffer, length, address, exception);
	else {
# endif
		bool (*func)(id, SEL, OFUDPSocket *, void *, size_t,
		    of_socket_address_t, id, id) =


		    (bool (*)(id, SEL, OFUDPSocket *, void *, size_t,



		    of_socket_address_t, id, id))

		    [_target methodForSelector: _selector];




		return func(_target, _selector, object, _buffer, length,
		    address, _context, exception);

# ifdef OF_HAVE_BLOCKS
	}
# endif
}

# ifdef OF_HAVE_BLOCKS
- (void)dealloc







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

|
<
>







623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645

646
647
648
649
650
651
652
653
	}

# ifdef OF_HAVE_BLOCKS
	if (_block != NULL)
		return _block(object, _buffer, length, address, exception);
	else {
# endif
		if (exception == nil) {
			if (![_delegate respondsToSelector: @selector(socket:
			    didReceiveIntoBuffer:length:sender:)])
				return false;

			return [_delegate socket: object
			    didReceiveIntoBuffer: _buffer
					  length: length
					  sender: address];
		} else {
			if ([_delegate respondsToSelector:
			    @selector(socket:didFailToReceiveWithException:)])
				[_delegate		   socket: object
				    didFailToReceiveWithException: exception];

			return false;

		}
# ifdef OF_HAVE_BLOCKS
	}
# endif
}

# ifdef OF_HAVE_BLOCKS
- (void)dealloc
673
674
675
676
677
678
679
680

681

682
683

684

685
686


687

688
689
690

691
692
693
694
695
696
697
	if (_block != NULL) {
		_length = _block(object, &_buffer,
		    (exception == nil ? _length : 0), &_receiver, exception);

		return (_length > 0);
	} else {
# endif
		size_t (*func)(id, SEL, OFUDPSocket *, const void *, size_t,

		    of_socket_address_t *, id, id) =

		    (size_t (*)(id, SEL, OFUDPSocket *, const void *, size_t,
		    of_socket_address_t *, id, id))

		    [_target methodForSelector: _selector];


		_length = func(_target, _selector, object, &_buffer,


		    (exception == nil ? _length : 0), &_receiver, _context,

		    exception);

		return (_length > 0);

# ifdef OF_HAVE_BLOCKS
	}
# endif
}

# ifdef OF_HAVE_BLOCKS
- (void)dealloc







|
>
|
>
|
|
>
|
>

|
>
>
|
>
|

|
>







676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
	if (_block != NULL) {
		_length = _block(object, &_buffer,
		    (exception == nil ? _length : 0), &_receiver, exception);

		return (_length > 0);
	} else {
# endif
		if (exception == nil) {
			if (![_delegate respondsToSelector:
			    @selector(socket:didSendBuffer:length:receiver:)])
				return false;

			_length = [_delegate socket: object
				      didSendBuffer: &_buffer
					     length: _length
					   receiver: &_receiver];

			return (_length > 0);
		} else {
			if ([_delegate respondsToSelector:
			    @selector(socket:didFailToSendWithException:)])
				[_delegate		socket: object
				    didFailToSendWithException: exception];

			return false;
		}
# ifdef OF_HAVE_BLOCKS
	}
# endif
}

# ifdef OF_HAVE_BLOCKS
- (void)dealloc
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
		queueItem->_buffer = buffer;
		queueItem->_length = length;
	})
}

+ (void)of_addAsyncConnectForTCPSocket: (OFTCPSocket *)stream
				  mode: (of_run_loop_mode_t)mode
				target: (id)target
			      selector: (SEL)selector
{
	ADD_WRITE(OFRunLoop_ConnectQueueItem, stream, mode, {
		queueItem->_target = [target retain];
		queueItem->_selector = selector;
	})
}

+ (void)of_addAsyncAcceptForTCPSocket: (OFTCPSocket *)stream
				 mode: (of_run_loop_mode_t)mode
			     delegate: (id <OFTCPSocketDelegate>)delegate
{
	ADD_READ(OFRunLoop_AcceptQueueItem, stream, mode, {
		queueItem->_delegate = [delegate retain];
	})
}

+ (void)of_addAsyncReceiveForUDPSocket: (OFUDPSocket *)sock
				buffer: (void *)buffer
				length: (size_t)length
				  mode: (of_run_loop_mode_t)mode
				target: (id)target
			      selector: (SEL)selector
			       context: (id)context
{
	ADD_READ(OFRunLoop_UDPReceiveQueueItem, sock, mode, {
		queueItem->_target = [target retain];
		queueItem->_selector = selector;
		queueItem->_context = [context retain];
		queueItem->_buffer = buffer;
		queueItem->_length = length;
	})
}

+ (void)of_addAsyncSendForUDPSocket: (OFUDPSocket *)sock
			     buffer: (const void *)buffer
			     length: (size_t)length
			   receiver: (of_socket_address_t)receiver
			       mode: (of_run_loop_mode_t)mode
			     target: (id)target
			   selector: (SEL)selector
			    context: (id)context
{
	ADD_WRITE(OFRunLoop_UDPSendQueueItem, sock, mode, {
		queueItem->_target = [target retain];
		queueItem->_selector = selector;
		queueItem->_context = [context retain];
		queueItem->_buffer = buffer;
		queueItem->_length = length;
		queueItem->_receiver = receiver;
	})
}

# ifdef OF_HAVE_BLOCKS







|
|


<
|
















|
<
<


<
|
<










|
<
<


<
|
<







837
838
839
840
841
842
843
844
845
846
847

848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865


866
867

868

869
870
871
872
873
874
875
876
877
878
879


880
881

882

883
884
885
886
887
888
889
		queueItem->_buffer = buffer;
		queueItem->_length = length;
	})
}

+ (void)of_addAsyncConnectForTCPSocket: (OFTCPSocket *)stream
				  mode: (of_run_loop_mode_t)mode
			      delegate: (id <OFTCPSocketDelegate_Private>)
					    delegate
{
	ADD_WRITE(OFRunLoop_ConnectQueueItem, stream, mode, {

		queueItem->_delegate = [delegate retain];
	})
}

+ (void)of_addAsyncAcceptForTCPSocket: (OFTCPSocket *)stream
				 mode: (of_run_loop_mode_t)mode
			     delegate: (id <OFTCPSocketDelegate>)delegate
{
	ADD_READ(OFRunLoop_AcceptQueueItem, stream, mode, {
		queueItem->_delegate = [delegate retain];
	})
}

+ (void)of_addAsyncReceiveForUDPSocket: (OFUDPSocket *)sock
				buffer: (void *)buffer
				length: (size_t)length
				  mode: (of_run_loop_mode_t)mode
			      delegate: (id <OFUDPSocketDelegate>)delegate


{
	ADD_READ(OFRunLoop_UDPReceiveQueueItem, sock, mode, {

		queueItem->_delegate = [delegate retain];

		queueItem->_buffer = buffer;
		queueItem->_length = length;
	})
}

+ (void)of_addAsyncSendForUDPSocket: (OFUDPSocket *)sock
			     buffer: (const void *)buffer
			     length: (size_t)length
			   receiver: (of_socket_address_t)receiver
			       mode: (of_run_loop_mode_t)mode
			   delegate: (id <OFUDPSocketDelegate>)delegate


{
	ADD_WRITE(OFRunLoop_UDPSendQueueItem, sock, mode, {

		queueItem->_delegate = [delegate retain];

		queueItem->_buffer = buffer;
		queueItem->_length = length;
		queueItem->_receiver = receiver;
	})
}

# ifdef OF_HAVE_BLOCKS