ObjFW  Diff

Differences From Artifact [5b08ee4ef4]:

To Artifact [785ede0c63]:


26
27
28
29
30
31
32
33

34
35

36
37
38


39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
26
27
28
29
30
31
32

33


34



35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51







-
+
-
-
+
-
-
-
+
+







-
+








#import "socket_helpers.h"

/* Reference for static linking */
int _OFTCPSocket_SOCKS5_reference;

static void
send_or_exception(OFTCPSocket *self, int socket, char *buffer, size_t length)
send_or_exception(OFTCPSocket *self, of_socket_t socket, char *buffer,
{
	if (length > SSIZE_MAX)
    int length)
		@throw [OFOutOfRangeException exception];

	if (send(socket, buffer, length, 0) != (ssize_t)length)
{
	if (send(socket, buffer, length, 0) != length)
		@throw [OFWriteFailedException
		    exceptionWithObject: self
			requestedLength: length
				  errNo: of_socket_errno()];
}

static void
recv_exact(OFTCPSocket *self, int socket, char *buffer, size_t length)
recv_exact(OFTCPSocket *self, of_socket_t socket, char *buffer, int length)
{
	while (length > 0) {
		ssize_t ret = recv(socket, buffer, length, 0);

		if (ret < 0)
			@throw [OFReadFailedException
			    exceptionWithObject: self
96
97
98
99
100
101
102



103
104

105
106
107
108
109
110
111
94
95
96
97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
112







+
+
+

-
+







			   count: request[0]];

	request[0] = port >> 8;
	request[1] = port & 0xFF;
	[connectRequest addItems: request
			   count: 2];

	if ([connectRequest count] > INT_MAX)
		@throw [OFOutOfRangeException exception];

	send_or_exception(self, _socket,
	    [connectRequest items], [connectRequest count]);
	    [connectRequest items], (int)[connectRequest count]);

	objc_autoreleasePoolPop(pool);

	recv_exact(self, _socket, reply, 4);

	if (reply[0] != 5 || reply[1] != 0 || reply[2] != 0) {
		[self close];