This was a boon considering that most of my POE code started as cut and paste from other examples.įor the remainder of this section, I would like to simply go through each of the classes used in the program and give some brief notes. Using separate classes meant that, for example, I could have the same event name across several different sessions/classes without needing to worry about whether they would interfere with each other. Besides being a reasonable approach in general, it also turned out that this was a good practical fit with the POE way of doing things since I could use a separate POE session for each class. POINTS OF INTERESTįrom the outset, I had decided that I would modularise the code and use different objects (classes) for each functional part of the overall program. Based on this experience, I would definitely recommend other Perl programmers to consider POE for programs of this sort (network daemons) as well as for any other task where the an event-based approach is suitable. Since I had already read up sufficiently on POE (and the examples in the cookbook) and knew in general how I wanted my daemon to work, selecting the relevant recipes and reworking them was a pretty straightforward process. Rather, it boiled down to just one factor: almost all of the POE code I have here was based, in one way or another, on example code hosted on the POE Cookbook site. Despite this being my first time writing any program using POE, the speed of development was not down to amazing programming skill on my part. The reason for both the small size and quick development time can be attributed to the combination of Perl and POE. In all, it took about an evening's work to code and eliminate most of the major bugs. Using POE to develop a non-trivial program with a focus on asynchronous, event-based operationĪs I write this, the size of the program is significantly less than 1,000 lines (not including this documentation), while still managing to implement a reasonably complex network daemon. Daemons and method of communicating with them 3. Multicast (and peer-to-peer) networking 2. The reason for writing this program was to explore three key areas: 1. More commands could be added quite easily. Currently the only useful command that is implemented is 'list', which prints a list of all the disks that the daemon knows about. The client conencts via a local unix domain socket and, providing the connection succeeds, it will then be able to pass commands to the daemon. The diskd program can also be run in client mode on any machine that has a running diskd daemon. Thus the primary function of the program is to be able to locate disks, no matter which machine they are currently attached to. As a result of this, each daemon will be able to build up a full list of which disks are available in the peer network and to which machine they are attached. It also listens to the channel for incoming multicast messages from another peer and uses them to update its list of which disks are attached to that peer. It also sets up a periodic event that will send the details of the disks attached to the machine to other peers that have joined the multicast channel. The daemon then collects the list of disks attached to the system and schedules the collection to trigger again periodically. The first thing that it does is join a pre-defined multicast channel. It reports on all disks attached, regardless of whether the disk (or partition) is currently mounted or not.Ī copy of diskd should be run on each of the peer machines. The "blkid" program is used to gather this information. The information shared between peers in this example is the list of disks that are currently attached to each system. encapsulating a data structure that can be accessed and updated by the above using POE to periodically run an external program without blocking 5. using POE to achieve both of the above 4. communicating with local clients via a Unix domain socket 3. using multicast to send and receive data among several peers 2. This program is intended as an example of: 1. => list # show information about known disks
0 Comments
Leave a Reply. |