demux_wself_piper.hpp

00001 #line 4016 "./lpsrc/flx_demux.pak"
00002 #ifndef __DEMUX_WSELF_PIPER__
00003 #define __DEMUX_WSELF_PIPER__
00004 
00005 #include <flx_demux_config.hpp>
00006 #include "demux_overlapped.hpp"  // I use readfile control block
00007 #include "demux_wself_piper.hpp"
00008 
00009 namespace flx { namespace demux {
00010 
00011 class DEMUX_EXTERN auto_handle {
00012 public:
00013   HANDLE h;
00014 
00015   auto_handle();
00016   ~auto_handle();
00017 };
00018 
00019 // win32 self pipe trick (what a pain!)
00020 class DEMUX_EXTERN wpipe_pair {
00021   enum { READ_END, WRITE_END };
00022   // HANDLE pipe[2];  // 0 = read end, 1 = write end
00023   auto_handle pipe[2];
00024 public:
00025   wpipe_pair();
00026 
00027   void write_byte();
00028   HANDLE get_read_end() { return pipe[READ_END].h; }
00029 };
00030 
00031 // use a winfileio_control_block to install a nonblocking ReadFile on the
00032 // read end of the pipe pair. when we get a byte we can execute whatever
00033 // the user wanted which for win32 which seems to be naturally responsive
00034 // to new sockets/handles. demux quit will probably be the only operation
00035 // needed.
00036 class DEMUX_EXTERN wself_piper_wakeup : public winfileio_control_block
00037 {
00038   char the_byte;
00039 
00040 public:
00041   // possibly null, if not, called on iocp_op_finished
00042   demux_callback* cb;
00043 
00044   // the demuxer. doesn't actually get passed by iocp_op_finished
00045   iocp_demuxer* d;
00046 
00047 
00048   wself_piper_wakeup();
00049 
00050   // detect when single byte read has finished and exec callback,
00051   // re-arming.
00052   virtual void iocp_op_finished(DWORD nbytes, ULONG_PTR udat,
00053     LPOVERLAPPED olp, int err);
00054 
00055   void arm();
00056 };
00057 
00058 // at the very least, the read end must be nonblocking and associated
00059 // with the iocp.
00060 class DEMUX_EXTERN wself_piper {
00061   wpipe_pair pp;
00062   wself_piper_wakeup spw;
00063 public:
00064   void install(demuxer* demux, demux_callback* cb = 0);
00065   void wake(); // wakes demuxer which calls callback
00066 };
00067 
00068 } } // demux, flx
00069 
00070 #endif
00071 

Generated on Mon Dec 11 18:08:29 2006 for Felix by  doxygen 1.5.1