X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fsocketengine.h;h=d97c0ea9f9b9bd6c139abd09575e459e6a9d5ebc;hb=2eed59bea6f6e42c77ffd7e6061570c13f172e21;hp=643bceee5571d404f12fdb6f46925b6e51bcfa40;hpb=26e7bb0b9a17a595d9935a1cae41b44504ad213e;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/socketengine.h b/include/socketengine.h index 643bceee5..d97c0ea9f 100644 --- a/include/socketengine.h +++ b/include/socketengine.h @@ -20,13 +20,12 @@ */ -#ifndef SOCKETENGINE_H -#define SOCKETENGINE_H +#pragma once #include #include #include -#include "inspircd_config.h" +#include "config.h" #include "socket.h" #include "base.h" @@ -489,9 +488,32 @@ public: /** Get data transfer statistics, kilobits per second in and out and total. */ void GetStats(float &kbitpersec_in, float &kbitpersec_out, float &kbitpersec_total); + + /** Should we ignore the error in errno? + * Checks EAGAIN and WSAEWOULDBLOCK + */ + static bool IgnoreError(); + + /** Return the last socket related error. strrerror(errno) on *nix + */ + static std::string LastError(); + + /** Returns the error for the given error num, strerror(errnum) on *nix + */ + static std::string GetError(int errnum); }; -SocketEngine* CreateSocketEngine(); +inline bool SocketEngine::IgnoreError() +{ + if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) + return true; +#ifdef _WIN32 + if (WSAGetLastError() == WSAEWOULDBLOCK) + return true; #endif + return false; +} + +SocketEngine* CreateSocketEngine();