ObjFW  Check-in [b8517c63ca]

Overview
Comment:Rename -[bindToPort:onHost:] to -[bindToHost:port:].
This way it's consistent with -[connectToHost:port].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b8517c63ca0bc869bf55ca76b3f04114efa12e58c76168aaa4edd6ebff461c1b
User & Date: js on 2011-09-19 13:07:19
Other Links: manifest | tags
Context
2011-09-19
16:22
Make using -[tryReadLine] + OFStreamObserver safe. check-in: 535c2d5d9b user: js tags: trunk
13:07
Rename -[bindToPort:onHost:] to -[bindToHost:port:].
This way it's consistent with -[connectToHost:port].
check-in: b8517c63ca user: js tags: trunk
12:44
Nicer OFStreamObserver API. check-in: c279948fb8 user: js tags: trunk
Changes

Modified src/OFTCPSocket.h from [d3fc0d3305] to [83294d47e8].

53
54
55
56
57
58
59
60
61
62
63


64
65
66
67

68
69
70
71
72
73
74
 */
- (void)connectToHost: (OFString*)host
		 port: (uint16_t)port;

/**
 * \brief Bind the socket on the specified port and host.
 *
 * \param port The port to bind to. If the port is 0, an unused port will be
 *	       chosen, which can be obtained using the return value.
 * \param host The host to bind to. Use @"0.0.0.0" for IPv4 or @"::" for IPv6
 *	       to bind to all.


 * \return The port the socket was bound to
 */
- (uint16_t)bindToPort: (uint16_t)port
		onHost: (OFString*)host;


/**
 * \brief Listen on the socket.
 *
 * \param backlog Maximum length for the queue of pending connections.
 */
- (void)listenWithBackLog: (int)backLog;







<
<


>
>


<
|
>







53
54
55
56
57
58
59


60
61
62
63
64
65

66
67
68
69
70
71
72
73
74
 */
- (void)connectToHost: (OFString*)host
		 port: (uint16_t)port;

/**
 * \brief Bind the socket on the specified port and host.
 *


 * \param host The host to bind to. Use @"0.0.0.0" for IPv4 or @"::" for IPv6
 *	       to bind to all.
 * \param port The port to bind to. If the port is 0, an unused port will be
 *	       chosen, which can be obtained using the return value.
 * \return The port the socket was bound to
 */

- (uint16_t)bindToHost: (OFString*)host
		  port: (uint16_t)port;

/**
 * \brief Listen on the socket.
 *
 * \param backlog Maximum length for the queue of pending connections.
 */
- (void)listenWithBackLog: (int)backLog;

Modified src/OFTCPSocket.m from [ad3ac403d1] to [37dbaea5b8].

197
198
199
200
201
202
203
204
205

206
207
208
209
210
211
212
	if (sock == INVALID_SOCKET)
		@throw [OFConnectionFailedException newWithClass: isa
							  socket: self
							    host: host
							    port: port];
}

- (uint16_t)bindToPort: (uint16_t)port
		onHost: (OFString*)host

{
	union {
		struct sockaddr_storage storage;
		struct sockaddr_in in;
		struct sockaddr_in6 in6;
	} addr;
	socklen_t addrLen;







<
|
>







197
198
199
200
201
202
203

204
205
206
207
208
209
210
211
212
	if (sock == INVALID_SOCKET)
		@throw [OFConnectionFailedException newWithClass: isa
							  socket: self
							    host: host
							    port: port];
}


- (uint16_t)bindToHost: (OFString*)host
		  port: (uint16_t)port
{
	union {
		struct sockaddr_storage storage;
		struct sockaddr_in in;
		struct sockaddr_in6 in6;
	} addr;
	socklen_t addrLen;

Modified tests/OFHTTPRequestTests.m from [53041a12f7] to [270eb19232].

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
- main
{
	OFTCPSocket *listener, *client;

	[cond lock];

	listener = [OFTCPSocket socket];
	port = [listener bindToPort: 0
			     onHost: @"127.0.0.1"];
	[listener listen];

	[cond signal];
	[cond unlock];

	client = [listener accept];








|
|







46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
- main
{
	OFTCPSocket *listener, *client;

	[cond lock];

	listener = [OFTCPSocket socket];
	port = [listener bindToHost: @"127.0.0.1"
			       port: 0];
	[listener listen];

	[cond signal];
	[cond unlock];

	client = [listener accept];

Modified tests/OFTCPSocketTests.m from [2ddc4ec324] to [a1882e4cc9].

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
	OFTCPSocket *server, *client = nil, *accepted;
	uint16_t port;
	char buf[6];

	TEST(@"+[socket]", (server = [OFTCPSocket socket]) &&
	    (client = [OFTCPSocket socket]))

	TEST(@"-[bindToPort:onHost:]",
	    (port = [server bindToPort: 0
				onHost: @"127.0.0.1"]))

	TEST(@"-[listen]", R([server listen]))

	TEST(@"-[connectToHost:port:]",
	    R([client connectToHost: @"127.0.0.1"
			       port: port]))








|
|
|







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
	OFTCPSocket *server, *client = nil, *accepted;
	uint16_t port;
	char buf[6];

	TEST(@"+[socket]", (server = [OFTCPSocket socket]) &&
	    (client = [OFTCPSocket socket]))

	TEST(@"-[bindToHost:port:]",
	    (port = [server bindToHost: @"127.0.0.1"
				  port: 0]))

	TEST(@"-[listen]", R([server listen]))

	TEST(@"-[connectToHost:port:]",
	    R([client connectToHost: @"127.0.0.1"
			       port: port]))