x
Loading
 Loading
Hello, Guest | Login | Register

Multiplexed I/0 with poll()

In the last column, I talked about how to read and write from multiple file
descriptors seemingly simultaneously with the select() function call. Using multiplexed I/O
lets programs block while waiting for notification that some file descriptors are ready for reading
or writing.

In the last column, I talked about how to read and write from multiple file descriptors seemingly simultaneously with the select() function call. Using multiplexed I/O lets programs block while waiting for notification that some file descriptors are ready for reading or writing.

Using multiplexed I/O of this form is quite common. High-performance network servers — including mail, workgroup, and Web servers — all must handle multiple simultaneous connections, often thousands of connections. While select() looks like it would handle this kind of load just fine, it has a fatal flaw that limits its performance. Figure 1 shows the prototype of select().

Figure 1: A Prototype of the select() Function Call

int select(int numfd, fd_set * readfds, fd_set * writefds, fd_set * exceptfds, struct timeval * tv); 

Think about what happens when a program wants to use select() to block until either file descriptor 1000 or 1001 is ready to be read from. It will have to call select() with a numfd of 1002 and the appropriate value of readfds. Easy enough, right?

The Problem with select()

Now try to think about things from the kernel’s point of view. The kernel gets a request from a user-space program to monitor some file descriptors for reading. It knows that the file descriptors are smaller than 1002, but that’s all it knows. To figure out…

Please log in to view this content.

Not Yet a Member?

Register with LinuxMagazine.com and get free access to the entire archive, including:

  • Hands-on Content
  • White Papers
  • Community Features
  • And more.
Already a Member?
Log in!
Username

Password

Remember me

Forgotten your password?
Forgotten your username?
Read More
  1. Helpful Tools for Software Developers
  2. The Github Hall of Fame
  3. Book'em, Github.
  4. This Week on Github: Stupid Ruby Tricks
  5. A Veritable Scatter Shot!
Follow Linux Magazine
Rackspace