ObjFW  Diff

Differences From Artifact [014fa32cf3]:

To Artifact [7656e7376a]:


11
12
13
14
15
16
17

18
19
20
21
22
23
24

#import "config.h"

#import <stdio.h>
#import <stdlib.h>
#import <string.h>
#import <unistd.h>


#import "OFTCPSocket.h"
#import "OFExceptions.h"

#ifndef _WIN32	/* FIXME */
@implementation OFTCPSocket
- init







>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

#import "config.h"

#import <stdio.h>
#import <stdlib.h>
#import <string.h>
#import <unistd.h>
#import <fcntl.h>

#import "OFTCPSocket.h"
#import "OFExceptions.h"

#ifndef _WIN32	/* FIXME */
@implementation OFTCPSocket
- init
257
258
259
260
261
262
263



























264
265
266
267
268
269
270
{
	if (sock < 0) 
		@throw [OFNotConnectedException newWithObject: self];

	return [self writeNBytes: strlen(str)
		      fromBuffer: (const uint8_t*)str];
}




























- close
{
	if (sock < 0) 
		@throw [OFNotConnectedException newWithObject: self];

	sock = -1;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
{
	if (sock < 0) 
		@throw [OFNotConnectedException newWithObject: self];

	return [self writeNBytes: strlen(str)
		      fromBuffer: (const uint8_t*)str];
}

- setBlocking: (BOOL)enable
{
	int flags;

	if ((flags = fcntl(sock, F_GETFL)) < 0)
		@throw [OFSetOptionFailedException newWithObject: self];

	if (enable)
		flags &= ~O_NONBLOCK;
	else
		flags |= O_NONBLOCK;

	if (fcntl(sock, F_SETFL, flags) < 0)
		@throw [OFSetOptionFailedException newWithObject: self];

	return self;
}

- enableKeepAlives: (BOOL)enable
{
	if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &enable,
	    sizeof(enable)) != 0)
		@throw [OFSetOptionFailedException newWithObject: self];

	return self;
}

- close
{
	if (sock < 0) 
		@throw [OFNotConnectedException newWithObject: self];

	sock = -1;