1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 /* $Core: libIRCDsocketengine */
16 /********* DEFAULTS **********/
17 /* $ExtraSources: socketengines/socketengine_select.cpp */
18 /* $ExtraObjects: socketengine_select.o */
21 /* $ExtraSources: socketengines/socketengine_kqueue.cpp */
22 /* $ExtraObjects: socketengine_kqueue.o */
26 /* $ExtraSources: socketengines/socketengine_epoll.cpp */
27 /* $ExtraObjects: socketengine_epoll.o */
31 /* $ExtraSources: socketengines/socketengine_ports.cpp */
32 /* $ExtraObjects: socketengine_ports.o */
36 #include "socketengine.h"
38 int EventHandler::GetFd()
43 void EventHandler::SetFd(int FD)
48 bool EventHandler::Readable()
53 bool EventHandler::Writeable()
58 void SocketEngine::WantWrite(EventHandler* eh)
62 SocketEngine::SocketEngine(InspIRCd* Instance) : ServerInstance(Instance)
64 memset(ref, 0, sizeof(ref));
67 SocketEngine::~SocketEngine()
71 bool SocketEngine::AddFd(EventHandler* eh)
76 bool SocketEngine::HasFd(int fd)
78 if ((fd < 0) || (fd > MAX_DESCRIPTORS))
83 EventHandler* SocketEngine::GetRef(int fd)
85 if ((fd < 0) || (fd > MAX_DESCRIPTORS))
90 bool SocketEngine::DelFd(EventHandler* eh, bool force)
95 int SocketEngine::GetMaxFds()
100 int SocketEngine::GetRemainingFds()
105 int SocketEngine::DispatchEvents()
110 std::string SocketEngine::GetName()
112 return "misconfigured";
115 bool SocketEngine::BoundsCheckFd(EventHandler* eh)
119 if ((eh->GetFd() < 0) || (eh->GetFd() > MAX_DESCRIPTORS))
126 int SocketEngine::Accept(EventHandler* fd, sockaddr *addr, socklen_t *addrlen) { return -1; }
127 int SocketEngine::Close(int fd) { return -1; }
128 int SocketEngine::Close(EventHandler* fd) { return -1; }
129 int SocketEngine::Blocking(int fd) { return -1; }
130 int SocketEngine::NonBlocking(int fd) { return -1; }
131 int SocketEngine::GetSockName(EventHandler* fd, sockaddr *name, socklen_t* namelen) { return -1; }
132 int SocketEngine::RecvFrom(EventHandler* fd, void *buf, size_t len, int flags, sockaddr *from, socklen_t *fromlen) { return -1; }
136 int SocketEngine::Accept(EventHandler* fd, sockaddr *addr, socklen_t *addrlen)
138 return accept(fd->GetFd(), addr, addrlen);
141 int SocketEngine::Close(EventHandler* fd)
143 return close(fd->GetFd());
146 int SocketEngine::Close(int fd)
151 int SocketEngine::Blocking(int fd)
153 int flags = fcntl(fd, F_GETFL, 0);
154 return fcntl(fd, F_SETFL, flags ^ O_NONBLOCK);
157 int SocketEngine::NonBlocking(int fd)
159 int flags = fcntl(fd, F_GETFL, 0);
160 return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
163 int SocketEngine::GetSockName(EventHandler* fd, sockaddr *name, socklen_t* namelen)
165 return getsockname(fd->GetFd(), name, namelen);
168 int SocketEngine::RecvFrom(EventHandler* fd, void *buf, size_t len, int flags, sockaddr *from, socklen_t *fromlen)
170 return recvfrom(fd->GetFd(), buf, len, flags, from, fromlen);
175 int SocketEngine::Send(EventHandler* fd, const void *buf, size_t len, int flags)
177 return send(fd->GetFd(), (const char*)buf, len, flags);
180 int SocketEngine::Recv(EventHandler* fd, void *buf, size_t len, int flags)
182 return recv(fd->GetFd(), (char*)buf, len, flags);
185 int SocketEngine::SendTo(EventHandler* fd, const void *buf, size_t len, int flags, const sockaddr *to, socklen_t tolen)
187 return sendto(fd->GetFd(), (const char*)buf, len, flags, to, tolen);
190 int SocketEngine::Connect(EventHandler* fd, const sockaddr *serv_addr, socklen_t addrlen)
192 return connect(fd->GetFd(), serv_addr, addrlen);
195 int SocketEngine::Shutdown(EventHandler* fd, int how)
197 return shutdown(fd->GetFd(), how);
200 int SocketEngine::Bind(int fd, const sockaddr *my_addr, socklen_t addrlen)
202 return bind(fd, my_addr, addrlen);
205 int SocketEngine::Listen(int sockfd, int backlog)
207 return listen(sockfd, backlog);
210 int SocketEngine::Shutdown(int fd, int how)
212 return shutdown(fd, how);
215 void SocketEngine::RecoverFromFork()