Make the Simple Things Simple
By Steve Johnson
Perl was originally created to handle complex text
manipulation in UNIX when shell scripting wouldn't do. As its popularity grew, features and platforms were added, resulting in an object-oriented, cross-platform development language (that happens to manipulate text pretty well). In spite of its rapid growth and widespread use, there are situations where Perl shows its UNIX roots. One such instance came up as I tried writing a forking HTTP server for a Windows NT application.
An HTTP server (a Web server) is an application that "listens" for connection requests from client processes (usually on other machines). Upon receiving a request, the server creates a new connection for the client, and then goes back to listening for other requests. This new connection is created in its own process on the server because the act of waiting for a connection is usually a "blocking" action during which no other processing can take place. As I'll show you later, there are some obstacles and detours when building such an application with Win32 Perl.
A lot of the pain in writing an HTTP server can be eased by using the libwww-perl library for Perl. For those of you who have used it before,
Listing 1 may look a little odd. I'm actually using the new LWPng module, which supports many HTTP 1.1 features, including persistent connections (see the sidebar titled "