ObjFW  Diff

Differences From Artifact [90f1585c87]:

To Artifact [cc1af7fa6d]:

  • File src/OFHTTPClient.m — part of check-in [3b43d51006] at 2020-01-14 00:16:04 on branch trunk — More consistent -[close] behavior

    This means refusing to close twice, calling -[close] from -[dealloc] and
    not calling -[cancelAsyncRequests].

    Calling -[cancelAsyncRequests] in -[close] is too dangerous, as -[close]
    gets called by -[dealloc]: If the queue is the last reference to the
    object, at the point where -[cancelAsyncRequests] removes it from the
    queue, the object will start to deallocate and call into
    -[cancelAsyncRequests] again, which is still in the middle of removing
    it and now finds itself with an inconsistent state. (user: js, size: 28008) [annotate] [blame] [check-ins using]


729
730
731
732
733
734
735

736
737
738
739
740
741
742
743
744
745
746
	}

	return self;
}

- (void)dealloc
{

	[self close];

	[_handler release];
	[_socket release];

	[super dealloc];
}

- (size_t)lowlevelWriteBuffer: (const void *)buffer
		       length: (size_t)length
{







>
|


<







729
730
731
732
733
734
735
736
737
738
739

740
741
742
743
744
745
746
	}

	return self;
}

- (void)dealloc
{
	if (_socket != nil)
		[self close];

	[_handler release];


	[super dealloc];
}

- (size_t)lowlevelWriteBuffer: (const void *)buffer
		       length: (size_t)length
{
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801


802
803
804
805
806
807
808
{
	return _atEndOfStream;
}

- (void)close
{
	if (_socket == nil)
		return;

	if (_toWrite > 0)
		@throw [OFTruncatedDataException exception];

	_socket.delegate = _handler;
	[_socket asyncReadLine];

	[_socket release];
	_socket = nil;


}

- (int)fileDescriptorForWriting
{
	return _socket.fileDescriptorForWriting;
}
@end







|









>
>







785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
{
	return _atEndOfStream;
}

- (void)close
{
	if (_socket == nil)
		@throw [OFNotOpenException exceptionWithObject: self];

	if (_toWrite > 0)
		@throw [OFTruncatedDataException exception];

	_socket.delegate = _handler;
	[_socket asyncReadLine];

	[_socket release];
	_socket = nil;

	[super close];
}

- (int)fileDescriptorForWriting
{
	return _socket.fileDescriptorForWriting;
}
@end
817
818
819
820
821
822
823
824

825
826
827
828
829
830
831
	_socket = [sock retain];

	return self;
}

- (void)dealloc
{
	[_socket release];


	[super dealloc];
}

- (void)setHeaders: (OFDictionary *)headers
{
	OFString *contentLength;







|
>







819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
	_socket = [sock retain];

	return self;
}

- (void)dealloc
{
	if (_socket != nil)
		[self close];

	[super dealloc];
}

- (void)setHeaders: (OFDictionary *)headers
{
	OFString *contentLength;
981
982
983
984
985
986
987



988
989
990
991
992
993
994
- (bool)hasDataInReadBuffer
{
	return (super.hasDataInReadBuffer || _socket.hasDataInReadBuffer);
}

- (void)close
{



	_atEndOfStream = false;

	[_socket release];
	_socket = nil;

	[super close];
}







>
>
>







984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
- (bool)hasDataInReadBuffer
{
	return (super.hasDataInReadBuffer || _socket.hasDataInReadBuffer);
}

- (void)close
{
	if (_socket == nil)
		@throw [OFNotOpenException exceptionWithObject: self];

	_atEndOfStream = false;

	[_socket release];
	_socket = nil;

	[super close];
}