public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: "Trenton D. Adams" <tadams@extremeeng.com>
To: "'eCos Discussion'" <ecos-discuss@sourceware.cygnus.com>
Subject: [ECOS] server_test.c and SO_REUSE*
Date: Thu, 02 Aug 2001 08:30:00 -0000	[thread overview]
Message-ID: <000001c11b68$23321cc0$090110ac@TRENT> (raw)

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



             reply	other threads:[~2001-08-02  8:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-02  8:30 Trenton D. Adams [this message]
2001-08-02 13:29 ` Jonathan Larmour

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000001c11b68$23321cc0$090110ac@TRENT' \
    --to=tadams@extremeeng.com \
    --cc=ecos-discuss@sourceware.cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).