demux_overlapped.hpp

00001 #line 2687 "./lpsrc/flx_demux.pak"
00002 #ifndef __DEMUX_OVERLAPPED__
00003 #define __DEMUX_OVERLAPPED__
00004 #include "flx_demux_config.hpp"
00005 
00006 // visual studio is quite sensitve about how you do these includes.
00007 #include <WinSock2.h>              // Winsock2 (WSABufs, etc) must come before Windows.h
00008 #include "demux_iocp_demuxer.hpp"  // this header file include Windows.h
00009 #include <MSWSock.h>  // AcceptEx, TF_REUSE_SOCKET, etc
00010 
00011 namespace flx { namespace demux {
00012 
00013 // rename these to control block something or other
00014 // get rid of default constructors - faio can worry about that.
00015 
00016 // WARNING: in some "immediate completion" cases I have to call
00017 // the finished function myself - in these cases I set the udat to 0, making
00018 // it not very reliable. Either make sure the user understands immediate
00019 // finish (and does it themselves) or keep a copy of udat.
00020 
00021 // listener socket must be already associated with an IOCP
00022 // in doing an AcceptEx, it might succeed immediately - do you still
00023 // get the IOCP wakeup?
00024 class DEMUX_EXTERN acceptex_control_block : public iocp_wakeup {
00025   enum { ACCEPTEX_ADDR_SIZE = sizeof(SOCKADDR_IN) + 16 };
00026 
00027 public:
00028   SOCKET  listener, acceptor;
00029   // there are two of these!
00030   char  accept_buf[2*ACCEPTEX_ADDR_SIZE];
00031 
00032   virtual bool start_overlapped();
00033 
00034   acceptex_control_block()
00035     : listener(INVALID_SOCKET), acceptor(INVALID_SOCKET) {}
00036 };
00037 
00038 class DEMUX_EXTERN connectex_control_block : public iocp_wakeup
00039 {
00040 public:
00041   // move further back?
00042   int socket_err;         // outgoing
00043 
00044   // can have buffer to be sent on connection
00045   SOCKET    s;          // previously unbound socket
00046   const char* addy;       // ipv4 address
00047   int     p;          // port number
00048 
00049   // socket_err undefined
00050   connectex_control_block() : s(INVALID_SOCKET), addy(0), p(0) {}
00051 
00052   // see posix version of this, try to keep them in sync. give socket_err
00053   // initial definition that works with this?
00054   bool finished() { return ERROR_IO_PENDING != socket_err; }
00055 
00056   virtual bool start_overlapped();
00057 };
00058 
00059 // TransmitFile here (requires file handle)
00060 class DEMUX_EXTERN transmitfile_control_block : public iocp_wakeup {
00061   SOCKET  s;
00062   HANDLE  file;
00063   DWORD flags;                // for possible socket reuse.
00064 public:
00065 
00066   transmitfile_control_block(SOCKET dst)      // for reuse of socket
00067     : s(dst), file(NULL), flags(TF_DISCONNECT | TF_REUSE_SOCKET) {}
00068 
00069   transmitfile_control_block(SOCKET dst, HANDLE src)  // actual transmitfile
00070     : s(dst), file(src), flags(0) {}
00071 
00072   virtual bool start_overlapped();
00073 };
00074 
00075 
00076 // handles both WSASend & WSARecv
00077 class DEMUX_EXTERN wsasocketio_control_block : public iocp_wakeup {
00078 protected:
00079   enum { NUM_WBUFS = 1 }; // just one for now, but can do scattered send/recvs
00080   WSABUF    wbufs[NUM_WBUFS];
00081 public:
00082   SOCKET    s;
00083   sel_param*  ppb;      // on input what you want, on output what you got
00084   int     error;
00085   bool    reading;  // else use WSASend
00086 
00087   // watch the memory interfaces here, going back and forth between threads.
00088   wsasocketio_control_block(SOCKET src, sel_param* pb, bool read);
00089 
00090   virtual bool start_overlapped();
00091 
00092   virtual void iocp_op_finished( DWORD nbytes, ULONG_PTR udat,
00093     LPOVERLAPPED olp, int err);
00094 };
00095 
00096 // looks a bit like wsasocketio_control_block (bad name, sends too)
00097 class DEMUX_EXTERN winfileio_control_block : public iocp_wakeup {
00098   bool    reading;
00099 public:
00100 // probably should be a pointer (?)
00101   sel_param pb;
00102   HANDLE    file; // I like to modify this from the outside
00103 
00104   // offset?
00105   winfileio_control_block(HANDLE f, void* buf, int len, bool read);
00106 
00107   virtual bool start_overlapped();
00108 
00109   // NB: no iocp_op_finished callback. defined by users of the class.
00110 };
00111 
00112 }}
00113 
00114 #endif

Generated on Mon Dec 11 14:48:23 2006 for Felix by  doxygen 1.5.1