mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-10 11:09:04 -04:00
Made compile on freebsd
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2324 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
parent
a00a16b828
commit
ff40e40c9e
@ -19,6 +19,18 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "inspircd_config.h"
|
||||||
|
#include "globals.h"
|
||||||
|
#include "inspircd.h"
|
||||||
|
#ifdef USE_EPOLL
|
||||||
|
#include <sys/epoll.h>
|
||||||
|
#define EP_DELAY 5
|
||||||
|
#endif
|
||||||
|
#ifdef USE_KQUEUE
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/event.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
class SocketEngine {
|
class SocketEngine {
|
||||||
|
|
||||||
@ -39,9 +51,9 @@ public:
|
|||||||
|
|
||||||
SocketEngine();
|
SocketEngine();
|
||||||
~SocketEngine();
|
~SocketEngine();
|
||||||
bool AddFd(int fd, bool readable, bool writeable, char type);
|
bool AddFd(int fd, bool readable, char type);
|
||||||
bool DelFd(int fd);
|
bool DelFd(int fd);
|
||||||
bool Wait(unsigned long millisecs, std::vector<int> &fdlist);
|
bool Wait(std::vector<int> &fdlist);
|
||||||
std::string GetName();
|
std::string GetName();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
#include <sys/event.h>
|
#include <sys/event.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include "socketengine.h"
|
||||||
|
|
||||||
char ref[65535];
|
char ref[65535];
|
||||||
|
|
||||||
@ -32,7 +35,10 @@ SocketEngine::SocketEngine()
|
|||||||
|
|
||||||
SocketEngine::~SocketEngine()
|
SocketEngine::~SocketEngine()
|
||||||
{
|
{
|
||||||
#ifdef USE_EPOLL || USE_KQUEUE
|
#ifdef USE_EPOLL
|
||||||
|
close(EngineHandle);
|
||||||
|
#endif
|
||||||
|
#ifdef USE_KQUEUE
|
||||||
close(EngineHandle);
|
close(EngineHandle);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -57,7 +63,7 @@ bool SocketEngine::AddFd(int fd, bool readable, char type)
|
|||||||
#ifdef USE_KQUEUE
|
#ifdef USE_KQUEUE
|
||||||
struct kevent ke;
|
struct kevent ke;
|
||||||
log(DEBUG,"kqueue: Add user to events, kq=%d socket=%d",EngineHandle,fd);
|
log(DEBUG,"kqueue: Add user to events, kq=%d socket=%d",EngineHandle,fd);
|
||||||
EV_SET(&ke, socket, readable ? EVFILT_READ : EVFILT_WRITE, EV_ADD, 0, 0, NULL);
|
EV_SET(&ke, fd, readable ? EVFILT_READ : EVFILT_WRITE, EV_ADD, 0, 0, NULL);
|
||||||
int i = kevent(EngineHandle, &ke, 1, 0, 0, NULL);
|
int i = kevent(EngineHandle, &ke, 1, 0, 0, NULL);
|
||||||
if (i == -1)
|
if (i == -1)
|
||||||
{
|
{
|
||||||
@ -70,9 +76,15 @@ return true;
|
|||||||
|
|
||||||
bool SocketEngine::DelFd(int fd)
|
bool SocketEngine::DelFd(int fd)
|
||||||
{
|
{
|
||||||
std::vector<int>::iterator i = this->fds.find(fd);
|
bool found = false;
|
||||||
if (i != this->fds.end())
|
for (std::vector<int>::iterator i = fds.begin(); i != fds.end(); i++)
|
||||||
this->fds.erase(i);
|
{
|
||||||
|
if (*i == fd)
|
||||||
|
{
|
||||||
|
fds.erase(i);
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
#ifdef USE_KQUEUE
|
#ifdef USE_KQUEUE
|
||||||
struct kevent ke;
|
struct kevent ke;
|
||||||
EV_SET(&ke, fd, ref[fd] && X_READBIT ? EVFILT_READ : EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
|
EV_SET(&ke, fd, ref[fd] && X_READBIT ? EVFILT_READ : EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
|
||||||
@ -95,10 +107,10 @@ bool SocketEngine::DelFd(int fd)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
ref[fd] = 0;
|
ref[fd] = 0;
|
||||||
return (i != this->fds.end());
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SocketEngine::Wait(unsigned long millisecs, std::vector<int> &fdlist)
|
bool SocketEngine::Wait(std::vector<int> &fdlist)
|
||||||
{
|
{
|
||||||
fdlist.clear();
|
fdlist.clear();
|
||||||
#ifdef USE_SELECT
|
#ifdef USE_SELECT
|
||||||
@ -132,7 +144,7 @@ bool SocketEngine::Wait(unsigned long millisecs, std::vector<int> &fdlist)
|
|||||||
#ifdef USE_KQUEUE
|
#ifdef USE_KQUEUE
|
||||||
ts.tv_nsec = 1000L;
|
ts.tv_nsec = 1000L;
|
||||||
ts.tv_sec = 0;
|
ts.tv_sec = 0;
|
||||||
int i = kevent(EngineHandle, NULL, 0, &ke_list, 65535, &ts);
|
int i = kevent(EngineHandle, NULL, 0, &ke_list[0], 65535, &ts);
|
||||||
for (int j = 0; j < i; j++)
|
for (int j = 0; j < i; j++)
|
||||||
fdlist.push_back(ke_list[j].ident);
|
fdlist.push_back(ke_list[j].ident);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user