X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fsocketengine.h;h=d97c0ea9f9b9bd6c139abd09575e459e6a9d5ebc;hb=2eed59bea6f6e42c77ffd7e6061570c13f172e21;hp=58af73589fd0fd121b06a3f341f6f18e2a894580;hpb=362f3009ac9a8fc7e1cedea66aa72abcdf52d934;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/socketengine.h b/include/socketengine.h index 58af73589..d97c0ea9f 100644 --- a/include/socketengine.h +++ b/include/socketengine.h @@ -20,8 +20,7 @@ */ -#ifndef SOCKETENGINE_H -#define SOCKETENGINE_H +#pragma once #include #include @@ -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();