diff --git a/gsock.cpp b/gsock.cpp index d061e8e..0fa70e6 100644 --- a/gsock.cpp +++ b/gsock.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #define closesocket close using BYTE = unsigned char; #define WSAGetLastError() errno @@ -1066,6 +1067,35 @@ bool selector::is_error(const vsock& v) return FD_ISSET(v._vp->sfd, &_pp->errorset); } +#ifdef WIN32 // Windows: IOCP. Coming soon... + +#else // Linux: epoll +epoll::epoll() +{ + _fd=epoll_create(1024); // this parameter is useless. +} +epoll::~epoll() +{ + close(_fd); +} +int epoll::add(const vsock& v,epoll_event* event) +{ + return epoll_ctl(_fd,EPOLL_CTL_ADD,v._vp->sfd,event); +} +int epoll::mod(const vsock& v,epoll_event* event) +{ + return epoll_ctl(_fd,EPOLL_CTL_MOD,v._vp->sfd,event); +} +int epoll::del(const vsock& v,epoll_event* event) +{ + return epoll_ctl(_fd,EPOLL_CTL_DEL,v._vp->sfd,event); +} +int epoll::wait(epoll_event* events,int maxsize,int timeout) +{ + return epoll_wait(_fd,events,maxsize,timeout); +} +#endif + int DNSResolve(const std::string& HostName, std::vector& _out_IPStrVec) { std::vector vec; diff --git a/gsock.h b/gsock.h index 922b9b1..a512f6f 100644 --- a/gsock.h +++ b/gsock.h @@ -39,6 +39,11 @@ protected: _impl* _vp; friend class selector; +#ifdef WIN32 + +#else + friend class epoll; +#endif }; class sock : public vsock @@ -220,6 +225,29 @@ private: _impl* _pp; }; +#ifdef WIN32 // Windows: IOCP. Coming soon... + +#else // Linux: epoll +class epoll +{ +public: + epoll(); + int add(const vsock& v,epoll_event* event); + int mod(const vsock& v,epoll_event* event); + int del(const vsock& v,epoll_event* event); + + // >0: event counts. + // =0: Time up. + // <0: Error. + // Set timeout to -1 for infinity waiting. + int wait(epoll_event* events,int maxsize,int timeout); + + ~epoll(); +private: + int _fd; +}; +#endif // End of Platform specific + /// Net Tools // Return: