ObjFW  Diff

Differences From Artifact [a7e950a736]:

To Artifact [9ccd3888ba]:


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#endif

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

- (BOOL)lowlevelIsAtEndOfStream
{
	return _atEndOfStream;
}

- (size_t)lowlevelReadIntoBuffer: (void*)buffer
			  length: (size_t)length
{







|







61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#endif

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

- (bool)lowlevelIsAtEndOfStream
{
	return _atEndOfStream;
}

- (size_t)lowlevelReadIntoBuffer: (void*)buffer
			  length: (size_t)length
{
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

	if ((ret = recv(_socket, buffer, length, 0)) < 0)
		@throw [OFReadFailedException exceptionWithClass: [self class]
							  stream: self
						 requestedLength: length];

	if (ret == 0)
		_atEndOfStream = YES;

	return ret;
}

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







|







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

	if ((ret = recv(_socket, buffer, length, 0)) < 0)
		@throw [OFReadFailedException exceptionWithClass: [self class]
							  stream: self
						 requestedLength: length];

	if (ret == 0)
		_atEndOfStream = true;

	return ret;
}

- (void)lowlevelWriteBuffer: (const void*)buffer
		     length: (size_t)length
{
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
	if (send(_socket, buffer, length, 0) < length)
		@throw [OFWriteFailedException exceptionWithClass: [self class]
							   stream: self
						  requestedLength: length];
}

#ifdef _WIN32
- (void)setBlocking: (BOOL)enable
{
	u_long v = enable;
	_blocking = enable;

	if (ioctlsocket(_socket, FIONBIO, &v) == SOCKET_ERROR)
		@throw [OFSetOptionFailedException
		    exceptionWithClass: [self class]







|







130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
	if (send(_socket, buffer, length, 0) < length)
		@throw [OFWriteFailedException exceptionWithClass: [self class]
							   stream: self
						  requestedLength: length];
}

#ifdef _WIN32
- (void)setBlocking: (bool)enable
{
	u_long v = enable;
	_blocking = enable;

	if (ioctlsocket(_socket, FIONBIO, &v) == SOCKET_ERROR)
		@throw [OFSetOptionFailedException
		    exceptionWithClass: [self class]
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
	if (_socket == INVALID_SOCKET)
		@throw [OFNotConnectedException exceptionWithClass: [self class]
							    socket: self];

	close(_socket);
	_socket = INVALID_SOCKET;

	_atEndOfStream = NO;
}

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

	[super dealloc];
}
@end







|










161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
	if (_socket == INVALID_SOCKET)
		@throw [OFNotConnectedException exceptionWithClass: [self class]
							    socket: self];

	close(_socket);
	_socket = INVALID_SOCKET;

	_atEndOfStream = false;
}

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

	[super dealloc];
}
@end