mirror of
https://github.com/Kiritow/GSock.git
synced 2024-03-22 13:10:51 +08:00
Add epoll support
This commit is contained in:
parent
37e9ecf160
commit
fee6ee7972
30
gsock.cpp
30
gsock.cpp
|
@ -38,6 +38,7 @@
|
|||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/epoll.h>
|
||||
#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<std::string>& _out_IPStrVec)
|
||||
{
|
||||
std::vector<std::string> vec;
|
||||
|
|
28
gsock.h
28
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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user