00001 #line 454 "./lpsrc/flx_demux.pak" 00002 #ifndef __IOCP_DEMUXER__ 00003 #define __IOCP_DEMUXER__ 00004 00005 #include <flx_demux_config.hpp> 00006 //#include <Windows.h> 00007 // be specific - flx_rtl_config.h now jigs it so that windows.h does not 00008 // include winsock version 1 headers by default. this was making the order 00009 // of inclusion of windows.h and winsock2.h significant with cl.exe. 00010 #include <WinSock2.h> 00011 00012 #include "demux_demuxer.hpp" 00013 #include "pthread_sleep_queue.hpp" 00014 00015 00016 namespace flx { namespace demux { 00017 00018 // not here? returns INVALID_SOCKET on failure. 00019 // if *io_port == 0, then a port is chosen and returned in *io_port 00020 SOCKET DEMUX_EXTERN create_listener_socket(int* io_port, int backlog); 00021 // these two probably not used. move to wsockety.h 00022 SOCKET DEMUX_EXTERN nice_accept(SOCKET listener); 00023 SOCKET DEMUX_EXTERN nice_connect(const char* addr, int port); 00024 int DEMUX_EXTERN set_tcp_nodelay(int s, int disable_nagle); 00025 00026 // ******************************************************** 00027 /// make sure you instantion ONE (1) of these before using winsock 00028 // ******************************************************** 00029 class DEMUX_EXTERN winsock_initer 00030 { 00031 public: 00032 winsock_initer(); 00033 ~winsock_initer(); 00034 }; 00035 00036 // ******************************************************** 00037 /// iocp_wakeup base class for users of iocp_demuxer 00038 /// becoming an overlapped call control block 00039 // ******************************************************** 00040 class DEMUX_EXTERN iocp_wakeup { 00041 protected: // folks need to use these in win 32 calls 00042 OVERLAPPED ol; 00043 // store wakeup error here? 00044 // I didn't want this to be felixy, useful though. 00045 void clear_overlapped(); // zero the OVERLAPPED structure 00046 public: 00047 // 2 possibilities for piggybacking data. who could ask for more? 00048 // udat = per iocp association, olp = per overlapped function call. 00049 // why don't I need this in the posix version? 00050 virtual void iocp_op_finished( DWORD nbytes, ULONG_PTR udat, 00051 LPOVERLAPPED olp, int err) = 0; 00052 00053 // start overlapped async operation. returns true if it finished 00054 // immediately. in this case there will be no iocp_finished wakeup. 00055 // assumes all args ready for call. 00056 virtual bool start_overlapped() = 0; 00057 00058 // retrieves this pointer from OVERLAPPED pointer 00059 static iocp_wakeup* from_overlapped(LPOVERLAPPED olp); 00060 }; 00061 00062 // ******************************************************** 00063 // ******************************************************** 00064 class DEMUX_EXTERN iocp_demuxer : public demuxer { 00065 HANDLE iocp; // the io completion queue 00066 00067 void get_evts(bool poll); 00068 public: 00069 iocp_demuxer(); 00070 virtual ~iocp_demuxer(); 00071 00072 // udat is the per IOCP object user cookie & the overlapped pointer 00073 // is the per overlapped operation cookie (sort of), so in the case 00074 // of acceptex, udat is set when the listener is associated with the 00075 // iocp and is passed to the subsequent acceptex iocp wakeups. 00076 // probably won't be used very often 00077 // the OVERLAPPED retrieved from the iocp is assumed to be part of 00078 // an iocp_wakeup - beware! returns 0 on success, -1 on failure. 00079 int associate_with_iocp(HANDLE obj, ULONG_PTR udat); 00080 00081 }; 00082 00083 }} // namespace demux, flx 00084 #endif 00085