O'Reilly logo

Mastering Perl/Tk by Nancy Walsh, Stephen Lidie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The IPADM Daemon, ipadmd

The daemon’s duties consist of:

  • Creating the well-known server socket, then looping forever, accepting client connect requests and forking a copy of itself to handle them

  • Processing IPADM messages for the duration of the session

  • Employing advisory file locking so only one client has write access to an SDB at any point in time, thus ensuring the integrity of the SDB files

  • Keeping the DHCP and DNS configuration files current by periodically checking for modified SDB files, and running the filter as required

We’ll look briefly at how these functions are handled, but only briefly; we’re beginning to stray far from the topic of choice.

The Forking Server

We want a forking server, because each connect typically takes many minutes to service; after all, there’s a human on the other end of the socket, slowly clicking and typing away at the Tk client. With Perl and IO::Socket, writing such a server is a piece of cake. First, ipadmd creates its socket endpoint. The Listen parameter specifies the maximum number of simultaneous open sockets and indicates that this socket listens for connect attempts rather than attempting a connect itself.

The daemon main loop simply accepts connects as they arrive, storing the network socket handle in $ns, which the child inherits after the fork. While the child handles the current request, the parent closes its copy of $ns and resumes listening for network activity.

my $server = IO::Socket::INET->new Proto => 'tcp', LocalHost ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required