This chapter completes our survey of all three of the major techniques for handling concurrent stream-oriented connections. Each has advantages and disadvantages. Multitasking using fork() is currently available only on UNIX and Win32 platforms (using Perl 5.6 or higher). It has more overhead than the other methods due to the necessity of launching a new process to deal with each connection, but programs written using the technique tend to be simple and reliable. Multithreading is available on Win32 and many UNIX platforms and requires a version of Perl that is built with threading support. Threaded applications must be careful to lock and release shared variables and other resources, adding to the complexity of the code. We were able to get away without using locking in the examples so far, but most real network applications have to deal with this issue. Unfortunately, threading is not stable in current versions of Perl, and its API is likely to change. Multiplexing is available on all platforms on which Perl runs, including the Macintosh. Its drawback is that it makes the program logic more difficult to follow due to the necessity of interleaving the I/O from multiple sessions. Furthermore, it isn't bulletproof unless combined with nonblocking I/O, which adds significant complexity to the code. |