diff --git a/opt.hpp b/opt.hpp index c0d922450a396e3cf00f3bbcd0f288df14a5c89b..c4958bd00efe7856337d340e7581bf57102e5a32 100644 --- a/opt.hpp +++ b/opt.hpp @@ -67,7 +67,7 @@ namespace rlib { if(required && pos == args.cend()) throw std::invalid_argument("Required argument '{}' not provided."_format(argName)); if(pos == args.cend()) - return std::move(def); + return def; rlib_defer(([&, pos]{if(!useEqualSym) args.erase(pos+1); args.erase(pos);})); if(useEqualSym) return pos->substr(argName.size() + 1); @@ -91,7 +91,7 @@ namespace rlib { else return def; } - return std::move(value); + return value; } rlib::string getValueArg(const std::string &longName, const char *shortName) diff --git a/string.hpp b/string.hpp index c8789c15581768e4d7e947a7214b8dd3427efff6..b804952d434383509d447d8befc7a5a00444f1c7 100644 --- a/string.hpp +++ b/string.hpp @@ -131,7 +131,7 @@ namespace rlib { inline char *_format_string_c_helper(const char *fmt, ...) { int n; - int size = std::strlen(fmt); + size_t size = std::strlen(fmt); char *p, *np; va_list ap; @@ -186,10 +186,10 @@ namespace rlib { return this->c_str(); } std::string as(as_helper<std::string>) const { - return std::move(*this); + return *this; } rlib::string as(as_helper<rlib::string>) const { - return std::move(*this); + return *this; } char as(as_helper<char>) const { if(size() > 1) diff --git a/sys/sio.hpp b/sys/sio.hpp index 57902f92a02c13bd8b55e6007c816078ba912504..ff068075561657c754cecf8abf78fba48a04a36b 100644 --- a/sys/sio.hpp +++ b/sys/sio.hpp @@ -7,12 +7,16 @@ #include <winsock2.h> #include <windows.h> #include <ws2tcpip.h> +namespace rlib { + using ssize_t = int; +} #else #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #include <fcntl.h> #include <arpa/inet.h> +#include <unistd.h> #endif // Include winsock2.h before windows.h @@ -501,6 +505,11 @@ namespace rlib { currvptr = (char *)vptr + current / 2; } } + static void close_ex(sockfd_t fd) { + if (closesocket(fd) == SOCKET_ERROR) { + throw std::runtime_error("closeSocket failed. error code: " + std::to_string(WSAGetLastError())); + } + } #else // POSIX sockIO public: @@ -586,6 +595,11 @@ namespace rlib { currvptr = (char *)vptr + current / 2; } } + static void close_ex(sockfd_t fd) { + if (close(fd) == -1) { + throw std::runtime_error("close failed. error code: " + std::to_string(errno)); + } + } #endif #ifndef MSG_NOSIGNAL