<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7651.59">
<TITLE>How does the pollreactor work?</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->

<P><FONT SIZE=2 FACE="Arial">Hi, there.</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">I have been trying to figure out how to use the twisted.internet.pollreactor so that I can use it to monitor a Linux named PIPE (i.e. a FIFO created using mkfifo()).&nbsp; I tried without success to Google some examples but I couldn't find anything.</FONT></P>

<P><FONT SIZE=2 FACE="Arial">Now, for a simple TCP server, the setup looks something like this (i.e. like the QOTD example in the documentation):</FONT>
</P>
<UL>
<P><FONT SIZE=2 FACE="Courier New">from twisted.internet.protocol import Protocol, Factory<BR>
from twisted.internet import reactor<BR>
<BR>
class QOTD(Protocol):<BR>
<BR>
&nbsp;&nbsp;&nbsp; def connectionMade(self):<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.transport.write(&quot;An apple a day keeps the doctor away\r\n&quot;)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.transport.loseConnection()<BR>
<BR>
# Next lines are magic:<BR>
factory = Factory()<BR>
factory.protocol = QOTD<BR>
<BR>
# 8007 is the port you want to run under. Choose something &gt;1024<BR>
reactor.listenTCP(8007, factory)<BR>
reactor.run()</FONT>
</P>
</UL>
<P><FONT SIZE=2 FACE="Arial">So, the TCP type of reactor has something that tells it to listen to port 8007 and use some form of factory or object to take care of things when a connection occurs.&nbsp; As far as I can guess, I would need to do some steps like this (NOTE: using mixture of real and pseudo code):</FONT></P>
<UL>
<P><FONT SIZE=2 FACE="Courier New">from twisted.internet import pollreactor</FONT>

<BR><FONT SIZE=2 FACE="Courier New">pollreactor.install()</FONT>
</P>

<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">&lt;create a FileDescriptor object using /tmp/myfifo, maybe a class?&gt;</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">&lt;use the reactor.addReader() call to register the FileDescriptor object with the reactor&gt;</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">&lt;call reactor.run() (no loop) or call reactor.doPoll() (in a loop, processing returned events)?&gt;</FONT></SPAN><SPAN LANG="en-ca"></SPAN>
</P>
</UL>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">Anyways, if anyone can give me some direction on how this reactor works.&nbsp; Ideally, I would assume that the relationships would be somewhat like this:</FONT></SPAN></P>
<UL>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">Protocol analogous to FileDescriptor</FONT></SPAN>

<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">reactor.listenTCP analogous to reactor.addReader()</FONT></SPAN>

<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">reactor.run() would invoke the appropriate call in my FileDescriptor-based class to handle any read events on /tmp/myfifo</FONT></SPAN></P>
</UL>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">Thanks in advance.</FONT></SPAN>
</P>

<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">-Rodney</FONT></SPAN>
</P>

</BODY>
</HTML>