From: "Steve Graegert" <graegerts@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: Re: my server is blocking...
Date: Thu, 27 Jul 2006 21:37:55 +0200 [thread overview]
Message-ID: <6a00c8d50607271237s611cc14ao47c877fb9715bd02@mail.gmail.com> (raw)
In-Reply-To: <78031e5e0607271217u2f60d430n42cacef776a26e2@mail.gmail.com>
On 7/27/06, Norbert François <norbertlike@gmail.com> wrote:
> Hi list,
Norbert,
> I'm a beginner in C (sockets) programming, so please, excuse my stupid question.
>
> I'm trying to do a servent (server+client) for a p2p connexion. When I
> dissociate the client and the server, everything's all right. The
> Server is waiting for (pending) a connexion and when I connect on it,
> I've the behaviour I want.
>
> But now, I tried to merge the server & client together. When I start
> my program, the server is pending and the other part of my program
> isn't executed :( (the server is pending in an "accept" state). I
> tried to do some fork(), but it was useless (in fact, a new server is
> restarted and I get a bind error). How can I solve this problem
> (easily, if possible) ?
1. A process always blocks in a call to accept() waiting for socket
descriptors to be fetched from the queue of incomplete connection
requests. Usually, when accept() returns, another process is forked
or some thread created to serve the client.
2. The bind() error you're probably observing is the famous "address
already in use" thing. You can solve the issue by setting the
SO_REUSEADDR socket:
int on = 1;
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
with s being the socket descriptor to set the option for. The socket
option must be set before the call to bind().
There are some good documents on the Internet dealing design of
concurrent servers and I'd highly recommend to get your hands on W. R.
Stevens' classic "Unix Network Programming" which is considered to be
one of the most comprehensive guides on network programming with the
sockets API. It's worth every penny.
\Steve
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2006-07-27 19:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-27 19:17 my server is blocking Norbert François
2006-07-27 19:37 ` Steve Graegert [this message]
2006-07-27 21:19 ` Glynn Clements
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=6a00c8d50607271237s611cc14ao47c877fb9715bd02@mail.gmail.com \
--to=graegerts@gmail.com \
--cc=linux-c-programming@vger.kernel.org \
/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 NNTP newsgroup(s).