faio_winio.hpp

00001 #line 1201 "./lpsrc/flx_faio.pak"
00002 #ifndef __DWINIO__
00003 #define __DWINIO__
00004 #include <flx_faio_config.hpp>
00005 
00006 // visual studio is quite sensitve about how you do these includes.
00007 // THIS is the way (WinSock2.h must include Windows.h).
00008 #include <WinSock2.h>
00009 #include <MSWSock.h>        // AcceptEx, TF_REUSE_SOCKET, etc
00010 
00011 #include "faio_asyncio.hpp" // flx driver requests
00012 #include "demux_overlapped.hpp"   // nicely wrapped async windows calls
00013 
00014 namespace flx { namespace faio {
00015 
00016 // interestingly, because in windows the async objects are associated
00017 // with an IOCP before their use, we don't actually need a demuxer here
00018 // at all. That's kind of nice. (actually iocp_associator uses it now)
00019 
00020 // a flx driver request to the add socket s to the drivers iocp
00021 // this is currently the only windows driver request that uses the demuxer.
00022 class FAIO_EXTERN iocp_associator : public flx_driver_request_base {
00023   SOCKET  s;
00024 public:
00025   // should have result & errcode
00026   iocp_associator() {}
00027   iocp_associator(SOCKET associatee) : s(associatee) {}
00028 
00029   virtual bool start_async_op(demux::demuxer& demux, flx_drv* drv, void* f);
00030 };
00031 
00032 // flx <-> c++ stuff for async io (well, it was)
00033 
00034 // transition to new windows async control block
00035 class FAIO_EXTERN waio_base : public flx_driver_request_base {
00036 protected:
00037   thread_wakeup fw;
00038 public:
00039   bool  success;          // eh?
00040 
00041   waio_base() : success(false) {}
00042 
00043   // actually wakes up thread
00044   virtual void iocp_op_finished( DWORD nbytes, ULONG_PTR udat,
00045     LPOVERLAPPED olp, int err);
00046 };
00047 
00048 
00049 // listener socket must be already associated with an IOCP
00050 // in doing an AcceptEx, it might succeed immediately - do you still
00051 // get the IOCP wakeup?
00052 class FAIO_EXTERN wasync_accept
00053   : public waio_base, public demux::acceptex_control_block
00054 {
00055 public:
00056   wasync_accept() {}  // felix linkage demands it
00057 
00058   wasync_accept(SOCKET l, SOCKET a) { listener = l; acceptor = a; }
00059 
00060   virtual bool start_async_op(demux::demuxer& demux, flx_drv* drv, void* f);
00061 
00062   virtual void iocp_op_finished( DWORD nbytes, ULONG_PTR udat,
00063     LPOVERLAPPED olp, int err);
00064 };
00065 
00066 class FAIO_EXTERN connect_ex
00067   : public waio_base, public demux::connectex_control_block
00068 {
00069 public:
00070 
00071   connect_ex() {}     // flx linkage
00072 
00073   connect_ex(SOCKET soc, const char* addr, int port)
00074     { s = soc; addy = addr; p = port; }
00075 
00076   virtual bool start_async_op(demux::demuxer& demux, flx_drv* drv, void* f);
00077 
00078   virtual void iocp_op_finished( DWORD nbytes, ULONG_PTR udat,
00079     LPOVERLAPPED olp, int err);
00080 };
00081 
00082 // TransmitFile here (requires file handle)
00083 class FAIO_EXTERN wasync_transmit_file
00084   : public waio_base, public demux::transmitfile_control_block
00085 {
00086 public:
00087   wasync_transmit_file()
00088     : transmitfile_control_block(INVALID_SOCKET, NULL) {}   // flx linkage
00089 
00090   wasync_transmit_file(SOCKET dst)      // for reuse of socket
00091     : transmitfile_control_block(dst) {}
00092 
00093   wasync_transmit_file(SOCKET dst, HANDLE src)  // actual transmitfile
00094     : transmitfile_control_block(dst, src) {}
00095 
00096   // from flx_request_base
00097   virtual bool start_async_op(demux::demuxer& demux, flx_drv* drv, void* f);
00098 
00099   virtual void iocp_op_finished(DWORD nbytes, ULONG_PTR udat,
00100     LPOVERLAPPED olp, int err);
00101 };
00102 
00103 // handles both WSASend & WSARecv
00104 class FAIO_EXTERN wsa_socketio
00105   : public waio_base, public demux::wsasocketio_control_block
00106 {
00107 public:
00108   wsa_socketio()
00109     : wsasocketio_control_block(INVALID_SOCKET, NULL, false) {}
00110 
00111   wsa_socketio(SOCKET src, demux::sel_param* ppb, bool read)
00112     : wsasocketio_control_block(src, ppb, read) {}
00113 
00114   virtual bool start_async_op(demux::demuxer& demux, flx_drv* drv, void* f);
00115 
00116   virtual void iocp_op_finished( DWORD nbytes, ULONG_PTR udat,
00117     LPOVERLAPPED olp, int err);
00118 };
00119 
00120 // looks a bit like wsa_socketio (bad name, sends too)
00121 class FAIO_EXTERN winfile_io
00122   : public waio_base, public demux::winfileio_control_block
00123 {
00124 public:
00125   winfile_io()      // flx linkage
00126     : winfileio_control_block(NULL, NULL, 0, false){}
00127 
00128   // offset?
00129   winfile_io(HANDLE f, void* buf, int len, bool read)
00130     : winfileio_control_block(f, buf, len, read) {}
00131 
00132   virtual bool start_async_op(demux::demuxer& demux, flx_drv* drv, void* f);
00133 
00134   virtual void iocp_op_finished( DWORD nbytes, ULONG_PTR udat,
00135     LPOVERLAPPED olp, int err);
00136 };
00137 
00138 
00139 }}
00140 #endif  // __DWINIO__
00141 

Generated on Mon Dec 11 17:08:15 2006 for Felix by  doxygen 1.5.1