public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] server_test.c and SO_REUSE*
@ 2001-08-02  8:30 Trenton D. Adams
  2001-08-02 13:29 ` Jonathan Larmour
  0 siblings, 1 reply; 2+ messages in thread
From: Trenton D. Adams @ 2001-08-02  8:30 UTC (permalink / raw)
  To: 'eCos Discussion'

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [ECOS] server_test.c and SO_REUSE*
  2001-08-02  8:30 [ECOS] server_test.c and SO_REUSE* Trenton D. Adams
@ 2001-08-02 13:29 ` Jonathan Larmour
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Larmour @ 2001-08-02 13:29 UTC (permalink / raw)
  To: Trenton D. Adams; +Cc: 'eCos Discussion'

"Trenton D. Adams" wrote:
> 
> I found something in server_test.c that I think is wrong.  It doesn't
> affect the functionality of the actual test.
[snip]
> 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.

Yes, that's right, I'll "fix" the test.

Jifl
-- 
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-08-02 13:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-02  8:30 [ECOS] server_test.c and SO_REUSE* Trenton D. Adams
2001-08-02 13:29 ` Jonathan Larmour

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).