X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsocketengine.cpp;h=df6ff5a0206d0471b41d962ffe115a9add91ab1f;hb=a032cd90ad5582914759e226085efee5aae1a1ef;hp=3735e7530aa899c65567953bce30f109aa39765c;hpb=8e8b0719bf58e2d875c06698f86377189da87e16;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/socketengine.cpp b/src/socketengine.cpp index 3735e7530..df6ff5a02 100644 --- a/src/socketengine.cpp +++ b/src/socketengine.cpp @@ -21,8 +21,10 @@ */ +#include "exitcodes.h" #include "inspircd.h" +#include /** Reference table, contains all current handlers **/ @@ -36,7 +38,7 @@ size_t SocketEngine::CurrentSetSize = 0; */ std::set SocketEngine::trials; -int SocketEngine::MAX_DESCRIPTORS; +size_t SocketEngine::MaxSetSize = 0; /** Socket engine statistics: count of various events, bandwidth usage */ @@ -61,6 +63,31 @@ void EventHandler::OnEventHandlerError(int errornum) { } +void SocketEngine::InitError() +{ + std::cerr << con_red << "FATAL ERROR!" << con_reset << " Socket engine initialization failed. " << strerror(errno) << '.' << std::endl; + exit(EXIT_STATUS_SOCKETENGINE); +} + +void SocketEngine::LookupMaxFds() +{ +#if defined _WIN32 + MaxSetSize = FD_SETSIZE; +#else + struct rlimit limits; + if (!getrlimit(RLIMIT_NOFILE, &limits)) + MaxSetSize = limits.rlim_cur; + +#if defined __APPLE__ + limits.rlim_cur = limits.rlim_max == RLIM_INFINITY ? OPEN_MAX : limits.rlim_max; +#else + limits.rlim_cur = limits.rlim_max; +#endif + if (!setrlimit(RLIMIT_NOFILE, &limits)) + MaxSetSize = limits.rlim_cur; +#endif +} + void SocketEngine::ChangeEventMask(EventHandler* eh, int change) { int old_m = eh->event_mask; @@ -221,9 +248,9 @@ int SocketEngine::Recv(EventHandler* fd, void *buf, size_t len, int flags) return nbRecvd; } -int SocketEngine::SendTo(EventHandler* fd, const void *buf, size_t len, int flags, const sockaddr *to, socklen_t tolen) +int SocketEngine::SendTo(EventHandler* fd, const void* buf, size_t len, int flags, const irc::sockets::sockaddrs& address) { - int nbSent = sendto(fd->GetFd(), (const char*)buf, len, flags, to, tolen); + int nbSent = sendto(fd->GetFd(), (const char*)buf, len, flags, &address.sa, address.sa_size()); stats.UpdateWriteCounters(nbSent); return nbSent; } @@ -254,9 +281,9 @@ int SocketEngine::WriteV(EventHandler* fd, const iovec* iovec, int count) } #endif -int SocketEngine::Connect(EventHandler* fd, const sockaddr *serv_addr, socklen_t addrlen) +int SocketEngine::Connect(EventHandler* fd, const irc::sockets::sockaddrs& address) { - int ret = connect(fd->GetFd(), serv_addr, addrlen); + int ret = connect(fd->GetFd(), &address.sa, address.sa_size()); #ifdef _WIN32 if ((ret == SOCKET_ERROR) && (WSAGetLastError() == WSAEWOULDBLOCK)) errno = EINPROGRESS;