diff --git a/src/lib/rlib/opt.hpp b/src/lib/rlib/opt.hpp index c0d922450a396e3cf00f3bbcd0f288df14a5c89b..c4958bd00efe7856337d340e7581bf57102e5a32 100644 --- a/src/lib/rlib/opt.hpp +++ b/src/lib/rlib/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/src/lib/rlib/string.hpp b/src/lib/rlib/string.hpp index c8789c15581768e4d7e947a7214b8dd3427efff6..b804952d434383509d447d8befc7a5a00444f1c7 100644 --- a/src/lib/rlib/string.hpp +++ b/src/lib/rlib/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/src/lib/rlib/sys/sio.hpp b/src/lib/rlib/sys/sio.hpp index 57902f92a02c13bd8b55e6007c816078ba912504..7919729f3f8280e0c3c66e6225e404a429546030 100644 --- a/src/lib/rlib/sys/sio.hpp +++ b/src/lib/rlib/sys/sio.hpp @@ -7,18 +7,21 @@ #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 #include <cerrno> #include <cstdlib> -#include <unistd.h> #include <string> #include <stdexcept> diff --git a/src/protocols/plain.hpp b/src/protocols/plain.hpp index 4159459f15bb173726360c655ae5ab31d10e5879..69aea0063715898bb4fbac0809549179645c0e51 100644 --- a/src/protocols/plain.hpp +++ b/src/protocols/plain.hpp @@ -30,7 +30,7 @@ namespace Protocols { rlib_defer([&] {close(listenFd);}); auto epollFd = epoll_create1(0); - dynamic_assert(epollFd != -1, "epoll_create1 failed"); + dynamic_assert((int)epollFd != -1, "epoll_create1 failed"); epoll_add_fd(epollFd, listenFd); epoll_add_fd(epollFd, ipcPipe); @@ -46,7 +46,7 @@ namespace Protocols { auto msg = rlib::sockIO::recv_msg(activeFd); auto clientAddr = ConnectionMapping::parseClientId(targetClientId); - auto status = sendto(udpSenderSocket, msg.data(), msg.size(), clientAddr.addr, clientAddr.len); + auto status = sendto(udpSenderSocket, msg.data(), msg.size(), 0, &clientAddr.addr, clientAddr.len); dynamic_assert(status != -1, "sendto failed"); } else if (activeFd == listenFd) { diff --git a/src/utils.hpp b/src/utils.hpp index 8faa49f1751c3a569d1ae40e565ab617acc8384b..3019e2a2bf3c2cd64328e34f3d90a905c954577f 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -28,36 +28,32 @@ struct ConnectionMapping { std::unordered_multimap<fd_t, string> server2client; static string makeClientId(const SockAddr &osStruct) { // ClientId is a binary string. + static_assert(sizeof(osStruct) == sizeof(SockAddr), "error: programming error detected."); string result(sizeof(osStruct), '\0'); std::memcpy(result.data(), &osStruct, sizeof(osStruct)); return result; } - static void parseClientId(const string &clientId, SockAddr &output) { - static_assert(sizeof(output) == sizeof(SockAddr), "error: programming error detected."); - if (clientId.size() != sizeof(output)) + static SockAddr parseClientId(const string &clientId) { + SockAddr result; + if (clientId.size() != sizeof(result)) throw std::invalid_argument("parseClientId, invalid input binary string length."); - std::memcpy(&output, clientId.data(), sizeof(output)); + std::memcpy(&result, clientId.data(), sizeof(result)); + return result; } }; inline void epoll_add_fd(fd_t epollFd, sockfd_t fd) { - epoll_event event { - .events = EPOLLIN, - .data = { - .fd = fd, - } - }; + epoll_event event; + event.events = EPOLLIN; + event.data.fd = fd; auto ret1 = epoll_ctl(epollFd, EPOLL_CTL_ADD, fd, &event); if(ret1 == -1) throw std::runtime_error("epoll_ctl failed."); } inline void epoll_del_fd(fd_t epollFd, sockfd_t fd) { - epoll_event event { - .events = EPOLLIN, - .data = { - .fd = fd, - } - }; + epoll_event event; + event.events = EPOLLIN; + event.data.fd = fd; auto ret1 = epoll_ctl(epollFd, EPOLL_CTL_DEL, fd, &event); // Can be nullptr since linux 2.6.9 if(ret1 == -1) throw std::runtime_error("epoll_ctl failed."); @@ -90,7 +86,7 @@ inline auto mk_tcp_pipe() { } #define dynamic_assert(expr, msg) do { \ - if(!(expr)) { rlog.error("Runtime Assertion Failed: AT " __FILE__ ":" __LINE__ " F(" __func__ "), {}. Errno={}, strerror={}", (msg), errno, strerror(errno)); throw std::runtime_error("dynamic_assert failed. See rlog.error."); } \ + if(!(expr)) { rlog.error("Runtime Assertion Failed: AT " __FILE__ ":{} F({}), {}. Errno={}, strerror={}", __LINE__, __func__, (msg), errno, strerror(errno)); throw std::runtime_error("dynamic_assert failed. See rlog.error."); } \ } while(false)