ObjFW  Diff

Differences From Artifact [c248fb563e]:

  • File src/OFStreamSocket.m — part of check-in [b4cd87cd81] at 2017-05-21 23:57:34 on branch trunk — Use closesocket() instead of close()

    Previously, socket_helpers.h would just define close() to whatever is
    needed to close a socket. However, this makes it possible to
    accidentally call a socket-specific close on something that is not a
    socket. Having to explicitly call closesocket() (and defining it to
    close() on platforms where it's the same) prevents this. (user: js, size: 3980) [annotate] [blame] [check-ins using]

To Artifact [eec652ecb7]:


46
47
48
49
50
51
52



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66





67
68
69
70
71
72
73







+
+
+











-
-
-
-
-







+ (instancetype)socket
{
	return [[[self alloc] init] autorelease];
}

- (bool)lowlevelIsAtEndOfStream
{
	if (_socket == INVALID_SOCKET)
		@throw [OFNotOpenException exceptionWithObject: self];

	return _atEndOfStream;
}

- (size_t)lowlevelReadIntoBuffer: (void *)buffer
			  length: (size_t)length
{
	ssize_t ret;

	if (_socket == INVALID_SOCKET)
		@throw [OFNotOpenException exceptionWithObject: self];

	if (_atEndOfStream)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: length
							    errNo: ENOTCONN];

#ifndef OF_WINDOWS
	if ((ret = recv(_socket, buffer, length, 0)) < 0)
		@throw [OFReadFailedException
		    exceptionWithObject: self
			requestedLength: length
				  errNo: of_socket_errno()];
#else
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
89
90
91
92
93
94
95





96
97
98
99
100
101
102







-
-
-
-
-








- (void)lowlevelWriteBuffer: (const void *)buffer
		     length: (size_t)length
{
	if (_socket == INVALID_SOCKET)
		@throw [OFNotOpenException exceptionWithObject: self];

	if (_atEndOfStream)
		@throw [OFWriteFailedException exceptionWithObject: self
						   requestedLength: length
							     errNo: ENOTCONN];

#ifndef OF_WINDOWS
	if (length > SSIZE_MAX)
		@throw [OFOutOfRangeException exception];

	if (send(_socket, buffer, length, 0) != (ssize_t)length)
		@throw [OFWriteFailedException
		    exceptionWithObject: self