⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 warsocketiowin32nt.h

📁 ftpserver very good sample
💻 H
字号:
/**   Implementation of Sockets IO for Windows NT and  2000. This implementation use I/O Completion ports  to aquire scalability and performance.   The WarSocket companion's On*() functions are called  by worker threads that I/O completion ports directly  in stead of the normal WarEvent.   This class require one instance of WarSvrWin32NtEngine   in the application.*/#ifndef WAR_SOCKET_IO_WIN32_NT_H#define WAR_SOCKET_IO_WIN32_NT_H/* SYSTEM INCLUDES *//* PROJECT INCLUDES */#ifndef WAR_SOCKET_IO_H#   include "WarSocketIo.h"#endif/* LOCAL INCLUDES *//* FORWARD REFERENCES */#ifdef __cplusplusextern "C" {#endif/****************** BEGIN OLD STYLE C spesific ********//****************** END OLD STYLE C spesific **********/#ifdef __cplusplus }#endif/****************** BEGIN C++ spesific ****************/#ifdef __cplusplus/// Simple support-class to AcceptEx pending sockets w/ buffersclass WarSocketIoWin32NtPending : public WarSmartPointer{public:    enum ConstantsE    {        ADDR_LEN = (sizeof(struct sockaddr) + 16),        READ_LEN = 0,        BUF_LEN = ((ADDR_LEN * 2) + READ_LEN)    };        WarSocketIoWin32NtPending(war_socket_t sck)        : mSocket(sck)    {        memset(mBuffer, 0, BUF_LEN);    }    bool operator < (const WarSocketIoWin32NtPending& from) const    {        return mSocket < from.mSocket;    }    bool operator == (const WarSocketIoWin32NtPending& from) const    {        return mSocket == from.mSocket;    }    size_t GetReadBufferLength()     {        return READ_LEN;    }    size_t GetLocalAddrBufferLength()     {           return ADDR_LEN;    }        size_t GetRemoteAddrBufferLength()     {        return ADDR_LEN;    }    size_t GetBufferLength()    {        return BUF_LEN;    }    war_socket_t mSocket;    char mBuffer[BUF_LEN];protected:    ~WarSocketIoWin32NtPending()     {        if (mSocket != WAR_INVALID_SOCKET)            closesocket(mSocket);    }};/// Winnt/2000 optimal IO class for server socketsclass WarSocketIoWin32Nt : public WarSocketIo{public:    typedef WarPtrWrapper<WarSocketIoWin32NtPending> pending_ptr_t;    typedef std::set<pending_ptr_t> pending_set_t;    enum IoOperationE    {        OP_RECV,        OP_SEND,        OP_CONNECT,        OP_ACCEPT,        OP_INVALID    };    typedef struct ol_result_def    {        OVERLAPPED mOverlappedData;        WarSocketIoWin32Nt *mpSocket;        WarPtrWrapper<WarSocket> SocketPtr;        war_transfer_buffer_ptr_t mBufferPtr;        IoOperationE mOperation;        war_socket_t mAcceptSocket;        unsigned mSegmentNum;        struct ol_result_def *mpNext; // Used in storage    } ol_result_t;    // LIFECYCLE        /**    * Default constructor.    */    WarSocketIoWin32Nt(void);        /**    * Destructor.    */    ~WarSocketIoWin32Nt(void);        // OPERATORS    // OPERATIONS           virtual void SendWithCallback(war_transfer_buffer_ptr_t& outBuffer,         size_t numSegments)        throw(WarException);     virtual void RecvWithCallback(war_transfer_buffer_ptr_t& inBuffer,         size_t numSegments)        throw(WarException);     /** Create a new socket of the same type.*/    virtual WarSocketIo *CreateSame() const throw (WarException)    {        return new WarSocketIoWin32Nt;    }        // ACCESS    virtual void AssignSocket(war_socket_t sck)         throw(WarException);        // INQUIRY    protected:    pending_set_t mListenQueue; // Sockets created for listen    virtual void OnConnect(const WarError& status);    virtual void DoListen(int backlog)        throw(WarException);     virtual void DoConnect(const struct sockaddr FAR *name, int namelen)        throw(WarException);     virtual void DoCreateSocket(int af, int type, int protocol)        throw(WarException);     ol_result_def *AllocResult(IoOperationE operation,         unsigned segmentNum);     static void DeleteResult(ol_result_def *presult);private:    static WarCriticalSection msBufferLock;    static ol_result_t *mspBufferList; // Unused buffers    static VOID CALLBACK FileIOCompletionRoutine(        DWORD dwErrorCode,                // completion code        DWORD dwNumberOfBytesTransfered,  // number of bytes transferred        LPOVERLAPPED lpOverlapped         // I/O information buffer        );        void CreateNewConnectionSocket();};/* INLINE METHODS *//* EXTERNAL REFERENCES */#endif /* __cplusplus *//****************** END C++ spesific ******************/#endif  /* WAR_SOCKET_IO_WIN32_NT_H_ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -