ObjFW  Check-in [b4810363ea]

Overview
Comment:OFHTTPClient: Always keep the underlying socket

When there's no keep-alive and the socket is not kept, it fails when the
OFHTTPClientResponse gets removed from the kernel event observer.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b4810363eac59fd5ffc7937be92962ed9b1ea56b7f7986ca06e0364e34514697
User & Date: js on 2020-01-12 17:37:29
Other Links: manifest | tags
Context
2020-01-13
00:18
OFPollKernelEventObserver: Copy FDs check-in: 7e9f70c477 user: js tags: trunk
2020-01-12
17:37
OFHTTPClient: Always keep the underlying socket check-in: b4810363ea user: js tags: trunk
16:22
Cancel async requests in OFStreamSocket instead check-in: cea3f2133d user: js tags: trunk
Changes

Modified src/OFHTTPClient.m from [0d964b4cba] to [90f1585c87].

44
45
46
47
48
49
50


51
52
53
54
55
56
57
#import "OFNotOpenException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#import "OFUnsupportedProtocolException.h"
#import "OFUnsupportedVersionException.h"
#import "OFWriteFailedException.h"



#define REDIRECTS_DEFAULT 10

@interface OFHTTPClientRequestHandler: OFObject <OFTCPSocketDelegate>
{
@public
	OFHTTPClient *_client;







>
>







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#import "OFNotOpenException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#import "OFUnsupportedProtocolException.h"
#import "OFUnsupportedVersionException.h"
#import "OFWriteFailedException.h"

#import "socket_helpers.h"

#define REDIRECTS_DEFAULT 10

@interface OFHTTPClientRequestHandler: OFObject <OFTCPSocketDelegate>
{
@public
	OFHTTPClient *_client;
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
				       length: length];

		if (ret > length)
			@throw [OFOutOfRangeException exception];

		_toRead -= ret;

		if (_toRead == 0) {
			_atEndOfStream = true;

			if (!_keepAlive) {
				[_socket release];
				_socket = nil;
			}
		}

		return ret;
	}

	/* Chunked */
	if (_toRead > 0) {
		if (length > _toRead)
			length = (size_t)_toRead;







|


<
<
<
<
<
<







880
881
882
883
884
885
886
887
888
889






890
891
892
893
894
895
896
				       length: length];

		if (ret > length)
			@throw [OFOutOfRangeException exception];

		_toRead -= ret;

		if (_toRead == 0)
			_atEndOfStream = true;







		return ret;
	}

	/* Chunked */
	if (_toRead > 0) {
		if (length > _toRead)
			length = (size_t)_toRead;
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
					@throw [OFInvalidServerReplyException
					    exception];
				}

				if (line.length > 0)
					@throw [OFInvalidServerReplyException
					    exception];
			} else {
				[_socket release];
				_socket = nil;
			}
		}

		objc_autoreleasePoolPop(pool);

		return 0;
	}







<
<
<







943
944
945
946
947
948
949



950
951
952
953
954
955
956
					@throw [OFInvalidServerReplyException
					    exception];
				}

				if (line.length > 0)
					@throw [OFInvalidServerReplyException
					    exception];



			}
		}

		objc_autoreleasePoolPop(pool);

		return 0;
	}
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990

	return _atEndOfStream;
}

- (int)fileDescriptorForReading
{
	if (_socket == nil)
		return -1;

	return _socket.fileDescriptorForReading;
}

- (bool)hasDataInReadBuffer
{
	return (super.hasDataInReadBuffer || _socket.hasDataInReadBuffer);







|







969
970
971
972
973
974
975
976
977
978
979
980
981
982
983

	return _atEndOfStream;
}

- (int)fileDescriptorForReading
{
	if (_socket == nil)
		return INVALID_SOCKET;

	return _socket.fileDescriptorForReading;
}

- (bool)hasDataInReadBuffer
{
	return (super.hasDataInReadBuffer || _socket.hasDataInReadBuffer);