Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 02 Mar 1998 10:35:42 -0500
From:      Matthew Hagerty <wpub1@net-link.net>
To:        vel@ns.kbsu.ru, questions@FreeBSD.ORG
Subject:   Re: Programming questions
Message-ID:  <3.0.3.32.19980302103542.03140e74@smtp.net-link.net>
In-Reply-To: <199802281638.TAA02990@ns.kbsu.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
>Hello people !
>
>I have some questions about programming under FreeBSD.
>
>1. When my process receives signal, what is the simplest and fastest way
>to look for PID of process who sent me this signal ?
>
>2. Is there any way to do accept() or another function like this without
>locking while waiting ? For example, my program wants to handle many
>network connections at a time without cloning via fork(). I know that
>some programs, such as ircd, do this. But how ?
>
>Pre-thanks.
>---
>Eugene L. Vorokov, Kabardino-Balkarian State University, Russia
>vel@ns.kbsu.ru
>vel@hub.kbsu.ru
>

You really need to get this book:

UNIX Network Programming, Vol 1. Second Edition
W. Richard Stevens
Prentice Hall PTR
ISBN: 0-13-490012-X
http://www.kohala.com/~rstevens

What you are trying to do is called an "Iterative Server".  An iterative
TCP server processes each client's request completely before moving on to
the next client.  The kernel will queue any client requests that arrive
while another client is being processed.  The number of clients the kernel
will queue is passed as a parameter in the listen() command, do a "man
listen".  If there are no clients to be processed, the accept command blocks.

If you want to be able to process multiple clients at the same time, then
you will have to fork() or pthread_create() to spawn a child or thread to
process the client request.  This way the parent can go back to listening
for more client requests.

See the man page for select() for implementing a non-blocking accept().
But servers that process one client at a time are very susceptible to
Denial-Of-Service attacks.  Also, non-blocking connects are different
across UNIXes and your code will not be very portable.

Matthew Hagerty




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3.0.3.32.19980302103542.03140e74>