ObjFW  Check-in [054a38e82d]

Overview
Comment:Add -[isListening] to OFTCPSocket.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 054a38e82d0042910c8a4f3986659d27a6b7b8805811f20ed9ac71691c20c30d
User & Date: js on 2011-04-08 07:05:26
Other Links: manifest | tags
Context
2011-04-09
12:30
Also test comments in -[stringValue]. check-in: 91d438b5d2 user: js tags: trunk
2011-04-08
07:05
Add -[isListening] to OFTCPSocket. check-in: 054a38e82d user: js tags: trunk
2011-04-06
20:07
Port recent OFStreamObserver changes to Win32. check-in: a10390bfd6 user: js tags: trunk
Changes

Modified src/OFTCPSocket.h from [2a976521af] to [98f00d6f79].

32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46







-
+







 * \brief A class which provides functions to create and use TCP sockets.
 *
 * To connect to a server, create a socket and connect it.
 * To create a server, create a socket, bind it and listen on it.
 */
@interface OFTCPSocket: OFStreamSocket
{
	BOOL		listening;
	BOOL		isListening;
	struct sockaddr	*sockAddr;
	socklen_t	sockAddrLen;
}

/**
 * Connect the OFTCPSocket to the specified destination.
 *
84
85
86
87
88
89
90
91

92
93





94
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98
99







-
+


+
+
+
+
+

 * Enable or disable keep alives for the connection.
 */
- (void)setKeepAlivesEnabled: (BOOL)enable;

/**
 * Returns the remote address of the socket. Only works with accepted sockets!
 *
 * \return The remote address as a string.
 * \return The remote address as a string
 */
- (OFString*)remoteAddress;

/**
 * \return Whether the socket is a listening socket
 */
- (BOOL)isListening;
@end

Modified src/OFTCPSocket.m from [1a33b199d0] to [ea3cfe401f].

324
325
326
327
328
329
330
331

332
333
334
335
336
337
338
339
340
341
342
343
344
345

346
347
348
349
350
351
352
324
325
326
327
328
329
330

331
332
333
334
335
336
337
338
339
340
341
342
343
344

345
346
347
348
349
350
351
352







-
+













-
+







						      socket: self];

	if (listen(sock, backlog) == -1)
		@throw [OFListenFailedException newWithClass: isa
						      socket: self
						     backLog: backlog];

	listening = YES;
	isListening = YES;
}

- (void)listen
{
	if (sock == INVALID_SOCKET)
		@throw [OFNotConnectedException newWithClass: isa
						      socket: self];

	if (listen(sock, 5) == -1)
		@throw [OFListenFailedException newWithClass: isa
						      socket: self
						     backLog: 5];

	listening = YES;
	isListening = YES;
}

- (OFTCPSocket*)accept
{
	OFTCPSocket *newsock;
	struct sockaddr *addr;
	socklen_t addrlen;
424
425
426
427
428
429
430





431
432
433
434
435
436

437
438
439
440
441
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440

441
442
443
444
445
446







+
+
+
+
+





-
+





	}
# endif
#endif

	/* Get rid of a warning, never reached anyway */
	assert(0);
}

- (BOOL)isListening
{
	return isListening;
}

- (void)close
{
	[super close];

	listening = NO;
	isListening = NO;
	[self freeMemory: sockAddr];
	sockAddr = NULL;
	sockAddrLen = 0;
}
@end