SDSU CS 596: Client Server Programming
Concurrent Servers

[To Lecture Notes Index]
San Diego State University -- This page last updated March 8, 1995

  1. Concurrent Servers
  2. Concurrent Servers (continued)
  3. Forking (multi-process) servers
  4. Single Process Concurrency
  5. What if we have a choice?
  6. General structure
  8. RealtimeOS using interrupts
  9. Unix Signals
  10. The "Correct" way...
  11. Select()
  12. select() (continued)
  13. select() (continued)
  14. Other issues

Concurrent Servers

What is the ultimate goal of a concurrent server?

Answer: Provide concurrent service to multiple clients.

How is this done?

Two basic solutions:

Concurrent Servers (continued)

When does one choose one over the other?


DOS is not multi-tasking. Only one choice.

Forking (multi-process) servers

(This is implied with the use of inetd)



Single Process Concurrency



What if we have a choice?

Why pick one over the other if we have a choice?

Some of the advantages and/or disadvantages can influence the decision.

Another reason: Analysis of many client-server applications will show

A single process server can use this to its advantage.

General structure

Inside the server is has:


The server has to simultaneously wait for incoming connections AND deal with connected clients.

Several solutions:

Realtime OS using interrupts

Problems with this:

Unix Signals

Interupts can be simulated under Unix using signals

The fcntl() call is used to change a socket to trigger SIGIO signals when I/O events happen.

Problems with this:

The "Correct" way...

Berkeley sockets introduced the select() system call.

select() will block until "something" happens

The "something" can be one of 5 things:

  1. a file descriptor has data available for reading
  2. a file descriptor has room available for writing
  3. a file descriptor has encountered some exception
  4. the process timer timed out
  5. a signal has occurred and has been dealt with.


The usefulness of this call comes from the fact that it does so many things in parallel.


int select(int			width,
           fd_set		*readfds,
           fd_set		*writefds,
           fd_set		*exceptfds,
           struct timeval	*timeout);

related functions:

select (continued)

basic control flow when using select:

for ever
clear readfds and writefds;	
for each client	
set bits in readfds and writefds;	
set readfds bit for passive socket;	
result = select(...);	
for each client	
if bits set in readfds or writefds			
deal with it;	
if bit for passive socket is set in readfds,		
accept new connection;

select (continued)

select() return values

number of bits set
error or interrupted (check errno against EINTR)

Other issues

Important issues:

fcntl(socket, F_SETFL, FNDELAY);