ObjFW  Check-in [c8990ecd12]

Overview
Comment:Don't allow connecting/binding on an already opened socket.
Also, free mem on accepted sockets when close is called.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c8990ecd12c64974d256fa3de1e99d8a7762da8f73323724df693813c6e977c3
User & Date: js on 2008-12-08 16:51:16
Other Links: manifest | tags
Context
2008-12-09
17:36
Don't use - raise anymore, but @throw.
- raise was only because at first, exceptions were self-raising, but
this was later changed so they had to be risen manually. - rise was
introduced for that, but it would've been better to use @throw
directly. Thus, this change now.
check-in: d88aec8e95 user: js tags: trunk
2008-12-08
16:51
Don't allow connecting/binding on an already opened socket.
Also, free mem on accepted sockets when close is called.
check-in: c8990ecd12 user: js tags: trunk
16:47
Use random port for test. check-in: b54cffa9db user: js tags: trunk
Changes

Modified src/OFTCPSocket.m from [d316d7c59d] to [5f52ffb737].

61
62
63
64
65
66
67





68
69
70
71
72
73
74
	struct addrinfo hints, *res, *res0;
	char portstr[6];

	if (!port) {
		/* FIXME: Throw exception */
		return nil;
	}






	memset(&hints, 0, sizeof(struct addrinfo));
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;

	snprintf(portstr, 6, "%d", port);








>
>
>
>
>







61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
	struct addrinfo hints, *res, *res0;
	char portstr[6];

	if (!port) {
		/* FIXME: Throw exception */
		return nil;
	}

	if (sock >= 0) {
		/* FIXME: Throw exception */
		return nil;
	}

	memset(&hints, 0, sizeof(struct addrinfo));
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;

	snprintf(portstr, 6, "%d", port);

108
109
110
111
112
113
114





115
116
117
118
119
120
121
	struct addrinfo hints, *res;
	char portstr[6];

	if (!port) {
		/* FIXME: Throw exception */
		return nil;
	}






	if ((sock = socket(family, SOCK_STREAM, 0)) < 0) {
		/* FIXME: Throw exception */
		return nil;
	}

	memset(&hints, 0, sizeof(struct addrinfo));







>
>
>
>
>







113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
	struct addrinfo hints, *res;
	char portstr[6];

	if (!port) {
		/* FIXME: Throw exception */
		return nil;
	}

	if (sock >= 0) {
		/* FIXME: Throw exception */
		return nil;
	}

	if ((sock = socket(family, SOCK_STREAM, 0)) < 0) {
		/* FIXME: Throw exception */
		return nil;
	}

	memset(&hints, 0, sizeof(struct addrinfo));
272
273
274
275
276
277
278




279
280
281
282

- close
{
	if (sock < 0) {
		/* FIXME: Throw exception */
		return nil;
	}





	return self;
}
@end







>
>
>
>




282
283
284
285
286
287
288
289
290
291
292
293
294
295
296

- close
{
	if (sock < 0) {
		/* FIXME: Throw exception */
		return nil;
	}

	if (saddr != NULL)
		[self freeMem: saddr];
	saddr_len = 0;

	return self;
}
@end