This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
server_test.c and SO_REUSE*
- To: "'eCos Discussion'" <ecos-discuss at sourceware dot cygnus dot com>
- Subject: [ECOS] server_test.c and SO_REUSE*
- From: "Trenton D. Adams" <tadams at extremeeng dot com>
- Date: Thu, 2 Aug 2001 09:31:01 -0600
- Organization: Extreme Engineering
I found something in server_test.c that I think is wrong. It doesn't
affect the functionality of the actual test.
The following function calls are in the wrong order.
if(bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
pexit("bind error");
}
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) {
pexit("setsockopt SO_REUSEADDR");
}
if (setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one))) {
pexit("setsockopt SO_REUSEPORT");
}
They should be like so
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) {
pexit("setsockopt SO_REUSEADDR");
}
if (setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one))) {
pexit("setsockopt SO_REUSEPORT");
}
if(bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
pexit("bind error");
}
If the two socket options aren't set before the bind, they have no
affect, and you cannot reuse the port or address if you want to.
Since the listening socket is never closed, it doesn't affect the actual
test.
Is this correct? My program wouldn't work without the setsockopt ()
calls before bind.
Trenton D. Adams
Embedded Developer
Windows Developer
Extreme Engineering Ltd.
Calgary Alberta
Phone: 403 640 9494 ext 208
Fax: 403 640 9599