diff --git a/src/Client/Connection.hpp b/src/Client/Connection.hpp index db7b323af..8b8b6fa19 100644 --- a/src/Client/Connection.hpp +++ b/src/Client/Connection.hpp @@ -523,7 +523,7 @@ static void inputBufGC(Connection &conn) { if ((conn.gc_step++ % Connection::GC_STEP_CNT) == 0) { - LOG_DEBUG("Flushed input buffer of the connection %p", &conn); + TNT_LOG_DEBUG("Flushed input buffer of the connection %p", &conn); conn.impl->inBuf.flush(); } } @@ -540,7 +540,7 @@ processResponse(Connection &conn, int req_sync, Response response; response.size = conn.impl->dec.decodeResponseSize(); if (response.size < 0) { - LOG_ERROR("Failed to decode response size"); + TNT_LOG_ERROR("Failed to decode response size"); //In case of corrupted response size all other data in the buffer //is likely to be decoded in the wrong way (since we don't // know how much bytes should be skipped). So let's simply @@ -560,8 +560,8 @@ processResponse(Connection &conn, int req_sync, ResponseendDecoded += response.size; return DECODE_ERR; } - LOG_DEBUG("Header: sync=", response.header.sync, ", code=", - response.header.code, ", schema=", response.header.schema_id); + TNT_LOG_DEBUG("Header: sync=", response.header.sync, ", code=", response.header.code, + ", schema=", response.header.schema_id); if (result != nullptr && response.header.sync == req_sync) { *result = std::move(response); } else { @@ -586,7 +586,7 @@ decodeGreeting(Connection &conn) conn.impl->greeting) != 0) return -1; conn.impl->is_greeting_received = true; - LOG_DEBUG("Version: ", conn.impl->greeting.version_id); + TNT_LOG_DEBUG("Version: ", conn.impl->greeting.version_id); #ifndef NDEBUG //print salt in hex format. @@ -598,7 +598,7 @@ decodeGreeting(Connection &conn) hex_salt[i * 2 + 1] = hex[u % 16]; } hex_salt[conn.impl->greeting.salt_size * 2] = 0; - LOG_DEBUG("Salt: ", hex_salt); + TNT_LOG_DEBUG("Salt: ", hex_salt); #endif return 0; } diff --git a/src/Client/Connector.hpp b/src/Client/Connector.hpp index f0d52ded1..ce6ee29ab 100644 --- a/src/Client/Connector.hpp +++ b/src/Client/Connector.hpp @@ -146,8 +146,7 @@ Connector::connect(Connection &conn, //Make sure that connection is not yet established. assert(conn.get_strm().has_status(SS_DEAD)); if (m_NetProvider.connect(conn, opts) != 0) { - LOG_ERROR("Failed to connect to ", - opts.address, ':', opts.service); + TNT_LOG_ERROR("Failed to connect to ", opts.address, ':', opts.service); return -1; } conn.getImpl()->is_greeting_received = false; @@ -156,8 +155,7 @@ Connector::connect(Connection &conn, // Encode auth request to reserve space in buffer. conn.prepare_auth(opts.user, opts.passwd); } - LOG_DEBUG("Connection to ", opts.address, ':', opts.service, - " has been established"); + TNT_LOG_DEBUG("Connection to ", opts.address, ':', opts.service, " has been established"); return 0; } @@ -258,7 +256,7 @@ Connector::wait(Connection &conn, rid_t future, int timeout, Response *result) { - LOG_DEBUG("Waiting for the future ", future, " with timeout ", timeout); + TNT_LOG_DEBUG("Waiting for the future ", future, " with timeout ", timeout); Timer timer{timeout}; timer.start(); static constexpr int INVALID_SYNC = -1; @@ -269,7 +267,7 @@ Connector::wait(Connection &conn, return -1; if (result != NULL && result->header.sync != INVALID_SYNC) { assert(result->header.sync == req_sync); - LOG_DEBUG("Future ", future, " is ready and decoded"); + TNT_LOG_DEBUG("Future ", future, " is ready and decoded"); return 0; } while (!conn.hasError() && !conn.futureIsReady(future)) { @@ -282,24 +280,23 @@ Connector::wait(Connection &conn, return -1; if (result != NULL && result->header.sync != INVALID_SYNC) { assert(result->header.sync == req_sync); - LOG_DEBUG("Future ", future, " is ready and decoded"); + TNT_LOG_DEBUG("Future ", future, " is ready and decoded"); return 0; } if (timer.isExpired()) break; } if (conn.hasError()) { - LOG_ERROR("Connection got an error: ", conn.getError().msg); + TNT_LOG_ERROR("Connection got an error: ", conn.getError().msg); return -1; } if (! conn.futureIsReady(future)) { - LOG_DEBUG("Connection has been timed out: future ", future, - " is not ready"); + TNT_LOG_DEBUG("Connection has been timed out: future ", future, " is not ready"); return -1; } else if (result != NULL) { *result = std::move(conn.getResponse(future)); } - LOG_DEBUG("Feature ", future, " is ready and decoded"); + TNT_LOG_DEBUG("Feature ", future, " is ready and decoded"); return 0; } @@ -331,10 +328,10 @@ Connector::waitAll(Connection &conn, break; } if (conn.hasError()) { - LOG_ERROR("Connection got an error: ", conn.getError().msg); + TNT_LOG_ERROR("Connection got an error: ", conn.getError().msg); return -1; } - LOG_DEBUG("Connection has been timed out: not all futures are ready"); + TNT_LOG_DEBUG("Connection has been timed out: not all futures are ready"); return -1; } @@ -346,14 +343,14 @@ Connector::waitAny(int timeout) timer.start(); while (m_ReadyToDecode.empty()) { if (m_NetProvider.wait(timer.timeLeft()) != 0) { - LOG_ERROR("Failed to poll connections: ", strerror(errno)); + TNT_LOG_ERROR("Failed to poll connections: ", strerror(errno)); return std::nullopt; } if (timer.isExpired()) break; } if (m_ReadyToDecode.empty()) { - LOG_DEBUG("wait() has been timed out! No responses are received"); + TNT_LOG_DEBUG("wait() has been timed out! No responses are received"); return std::nullopt; } Connection conn = *m_ReadyToDecode.begin(); @@ -391,11 +388,10 @@ Connector::waitCount(Connection &conn, break; } if (conn.hasError()) { - LOG_ERROR("Connection got an error: ", conn.getError().msg); + TNT_LOG_ERROR("Connection got an error: ", conn.getError().msg); return -1; } - LOG_DEBUG("Connection has been timed out: only ", - conn.getFutureCount() - ready_futures, " are ready"); + TNT_LOG_DEBUG("Connection has been timed out: only ", conn.getFutureCount() - ready_futures, " are ready"); return -1; } diff --git a/src/Client/EpollNetProvider.hpp b/src/Client/EpollNetProvider.hpp index ccd6aa826..d0939bd64 100644 --- a/src/Client/EpollNetProvider.hpp +++ b/src/Client/EpollNetProvider.hpp @@ -86,7 +86,7 @@ EpollNetProvider::EpollNetProvider(Connector_t &connector) : { m_EpollFd = epoll_create1(EPOLL_CLOEXEC); if (m_EpollFd == -1) { - LOG_ERROR("Failed to initialize epoll: ", strerror(errno)); + TNT_LOG_ERROR("Failed to initialize epoll: ", strerror(errno)); abort(); } } @@ -109,9 +109,7 @@ EpollNetProvider::registerEpoll(Conn_t &conn) event.data.ptr = conn.getImpl(); if (epoll_ctl(m_EpollFd, EPOLL_CTL_ADD, conn.get_strm().get_fd(), &event) != 0) { - LOG_ERROR("Failed to add socket to epoll: " - "epoll_ctl() returned with errno: ", - strerror(errno)); + TNT_LOG_ERROR("Failed to add socket to epoll: epoll_ctl() returned with errno: ", strerror(errno)); abort(); } } @@ -124,9 +122,7 @@ EpollNetProvider::setPollSetting(Conn_t &conn, int setting) { event.data.ptr = conn.getImpl(); if (epoll_ctl(m_EpollFd, EPOLL_CTL_MOD, conn.get_strm().get_fd(), &event) != 0) { - LOG_ERROR("Failed to change epoll mode: " - "epoll_ctl() returned with errno: ", - strerror(errno)); + TNT_LOG_ERROR("Failed to change epoll mode: epoll_ctl() returned with errno: ", strerror(errno)); abort(); } } @@ -142,7 +138,7 @@ EpollNetProvider::connect(Conn_t &conn, opts.address); return -1; } - LOG_DEBUG("Connected to ", opts.address, ", socket is ", strm.get_fd()); + TNT_LOG_DEBUG("Connected to ", opts.address, ", socket is ", strm.get_fd()); registerEpoll(conn); return 0; @@ -168,8 +164,7 @@ EpollNetProvider::close(Stream_t& strm) struct sockaddr_un *sa_un = (struct sockaddr_un *) &sa; snprintf(addr, 120, "%s", sa_un->sun_path); } - LOG_DEBUG("Closed connection to socket ", was_fd, - " corresponding to address ", addr); + TNT_LOG_DEBUG("Closed connection to socket ", was_fd, " corresponding to address ", addr); } #endif /* @@ -209,12 +204,12 @@ EpollNetProvider::recv(Conn_t &conn) if ((size_t) rcvd < Iproto::GREETING_SIZE) return 0; /* Receive and decode greetings. */ - LOG_DEBUG("Greetings are received, read bytes ", rcvd); + TNT_LOG_DEBUG("Greetings are received, read bytes ", rcvd); if (decodeGreeting(conn) != 0) { conn.setError("Failed to decode greetings"); return -1; } - LOG_DEBUG("Greetings are decoded"); + TNT_LOG_DEBUG("Greetings are decoded"); rcvd -= Iproto::GREETING_SIZE; if (conn.getImpl()->is_auth_required) { // Finalize auth request in buffer. @@ -261,7 +256,7 @@ EpollNetProvider::wait(int timeout) assert(timeout >= -1); if (timeout == -1) timeout = TIMEOUT_INFINITY; - LOG_DEBUG("Network engine wait for ", timeout, " milliseconds"); + TNT_LOG_DEBUG("Network engine wait for ", timeout, " milliseconds"); /* Send pending requests. */ for (auto conn = m_Connector.m_ReadyToSend.begin(); conn != m_Connector.m_ReadyToSend.end();) { @@ -276,15 +271,14 @@ EpollNetProvider::wait(int timeout) if (event_cnt < 0) { //Poll error doesn't belong to any connection so just global //log it. - LOG_ERROR("Poll failed: ", strerror(errno)); + TNT_LOG_ERROR("Poll failed: ", strerror(errno)); return -1; } for (int i = 0; i < event_cnt; ++i) { Conn_t conn((typename Conn_t::Impl_t *)events[i].data.ptr); if ((events[i].events & EPOLLIN) != 0) { - LOG_DEBUG("Registered poll event ", i, ": ", - conn.get_strm().get_fd(), - " socket is ready to read"); + TNT_LOG_DEBUG("Registered poll event ", i, ": ", conn.get_strm().get_fd(), + " socket is ready to read"); if (conn.get_strm().has_status(SS_NEED_READ_EVENT_FOR_WRITE)) { int rc = send(conn); if (rc < 0) @@ -302,9 +296,8 @@ EpollNetProvider::wait(int timeout) } if ((events[i].events & EPOLLOUT) != 0) { - LOG_DEBUG("Registered poll event ", i, ": ", - conn.get_strm().get_fd(), - " socket is ready to write"); + TNT_LOG_DEBUG("Registered poll event ", i, ": ", conn.get_strm().get_fd(), + " socket is ready to write"); if (conn.get_strm().has_status(SS_NEED_WRITE_EVENT_FOR_READ)) { int rc = recv(conn); if (rc < 0) diff --git a/src/Client/LibevNetProvider.hpp b/src/Client/LibevNetProvider.hpp index 431d1c126..aaf07a80f 100644 --- a/src/Client/LibevNetProvider.hpp +++ b/src/Client/LibevNetProvider.hpp @@ -142,12 +142,12 @@ connectionReceive(Connection> &conn) if ((size_t) rcvd < Iproto::GREETING_SIZE) return 0; /* Receive and decode greetings. */ - LOG_DEBUG("Greetings are received, read bytes ", rcvd); + TNT_LOG_DEBUG("Greetings are received, read bytes ", rcvd); if (decodeGreeting(conn) != 0) { conn.setError("Failed to decode greetings"); return -1; } - LOG_DEBUG("Greetings are decoded"); + TNT_LOG_DEBUG("Greetings are decoded"); rcvd -= Iproto::GREETING_SIZE; if (conn.getImpl()->is_auth_required) { // Finalize auth request in buffer. @@ -247,7 +247,7 @@ send_cb(struct ev_loop *loop, struct ev_io *watcher, int /* revents */) } if (rc > 0) { /* Send is not complete, setting the write watcher. */ - LOG_DEBUG("Send is not complete, setting the write watcher"); + TNT_LOG_DEBUG("Send is not complete, setting the write watcher"); if (conn.get_strm().has_status(SS_NEED_WRITE_EVENT_FOR_WRITE)) if (!ev_is_active(&waitWatcher->out)) ev_io_start(loop, &waitWatcher->out); @@ -302,7 +302,7 @@ LibevNetProvider::registerWatchers(Conn_t &conn, int fd) new (std::nothrow) WaitWatcher(&m_Connector, conn, &m_TimeoutWatcher); if (watcher == nullptr) { - LOG_ERROR("Failed to allocate memory for WaitWatcher"); + TNT_LOG_ERROR("Failed to allocate memory for WaitWatcher"); abort(); } @@ -325,7 +325,7 @@ LibevNetProvider::connect(Conn_t &conn, opts.address); return -1; } - LOG_DEBUG("Connected to ", opts.address, ", socket is ", strm.get_fd()); + TNT_LOG_DEBUG("Connected to ", opts.address, ", socket is ", strm.get_fd()); registerWatchers(conn, strm.get_fd()); return 0; @@ -354,7 +354,7 @@ void LibevNetProvider::timeout_cb(EV_P_ ev_timer *w, int /* revents */) { (void) w; - LOG_DEBUG("Libev timed out!"); + TNT_LOG_DEBUG("Libev timed out!"); /* Stop external loop */ ev_break(EV_A_ EVBREAK_ONE); } diff --git a/src/Client/ResponseDecoder.hpp b/src/Client/ResponseDecoder.hpp index 5f5a04abb..e26c0b630 100644 --- a/src/Client/ResponseDecoder.hpp +++ b/src/Client/ResponseDecoder.hpp @@ -84,11 +84,11 @@ ResponseDecoder::decodeResponse(Response &response) { /* Decode header and body separately to get more detailed error. */ if (!mpp::decode(it, response.header)) { - LOG_ERROR("Failed to decode header"); + TNT_LOG_ERROR("Failed to decode header"); return -1; } if (!mpp::decode(it, response.body)) { - LOG_ERROR("Failed to decode body"); + TNT_LOG_ERROR("Failed to decode body"); return -1; } return 0; diff --git a/src/Client/Stream.hpp b/src/Client/Stream.hpp index 6286cbbad..227a27a3f 100644 --- a/src/Client/Stream.hpp +++ b/src/Client/Stream.hpp @@ -121,7 +121,12 @@ struct ConnectOptions { class Stream { public: /* Disabled copy, enabled move. */ - Stream() noexcept = default; + /* + * Sic: toolchain of RedHat 7 doesn't have `noexcept` qualifier for `std::string` + * default constructor despite standard demands it. That's why `= default` syntax + * wouldn't work there, so let's define default constructor explicitly. + */ + Stream() noexcept {} ~Stream() noexcept = default; Stream(const Stream &) = delete; Stream &operator=(const Stream &) = delete; diff --git a/src/Client/UnixStream.hpp b/src/Client/UnixStream.hpp index 5e8bc589b..3eb3eaba9 100644 --- a/src/Client/UnixStream.hpp +++ b/src/Client/UnixStream.hpp @@ -68,9 +68,8 @@ class UnixStream : public Stream { protected: /** Log helpers. */ - template - void log_wise(LogLevel level, const char *file, int line, - const char *msg, MSG &&...more); + template + void log_wise(tnt::LogLevel level, const char *file, int line, const char *msg, MSG &&...more); template int die(const char *file, int line, const char *msg, MSG &&...more); @@ -109,8 +108,7 @@ class UnixStream : public Stream { template void -UnixStream::log_wise(LogLevel level, const char *file, int line, - const char *msg, MSG&& ...more) +UnixStream::log_wise(tnt::LogLevel level, const char *file, int line, const char *msg, MSG &&...more) { if (sizeof...(MSG) == 0 && fd < 0) log(level, file, line, msg); @@ -127,7 +125,7 @@ template int UnixStream::die(const char *file, int line, const char *msg, MSG&& ...more) { - log_wise(ERROR, file, line, msg, std::forward(more)...); + log_wise(tnt::ERROR, file, line, msg, std::forward(more)...); set_status(SS_DEAD); return -1; } @@ -137,7 +135,7 @@ int UnixStream::tell(StreamStatus st, const char *file, int line, const char *msg, MSG&& ...more) { - log_wise(INFO, file, line, msg, std::forward(more)...); + log_wise(tnt::INFO, file, line, msg, std::forward(more)...); set_status(st); return 0; } diff --git a/src/Utils/Logger.hpp b/src/Utils/Logger.hpp index 59907eb39..e98785ccc 100644 --- a/src/Utils/Logger.hpp +++ b/src/Utils/Logger.hpp @@ -36,6 +36,8 @@ #include #include +namespace tnt { + enum LogLevel { DEBUG = 0, INFO = 1, @@ -124,7 +126,9 @@ log(LogLevel level, const char *file, int line, ARGS&& ...args) gLogger.log(fd, level, file, line, std::forward(args)...); } -#define LOG_DEBUG(...) log(DEBUG, __FILE__, __LINE__, __VA_ARGS__) -#define LOG_INFO(...) log(INFO, __FILE__, __LINE__, __VA_ARGS__) -#define LOG_WARNING(...) log(WARNING, __FILE__, __LINE__, __VA_ARGS__) -#define LOG_ERROR(...) log(ERROR, __FILE__, __LINE__, __VA_ARGS__) +} /* namespace tnt */ + +#define TNT_LOG_DEBUG(...) tnt::log(tnt::DEBUG, __FILE__, __LINE__, __VA_ARGS__) +#define TNT_LOG_INFO(...) tnt::log(tnt::INFO, __FILE__, __LINE__, __VA_ARGS__) +#define TNT_LOG_WARNING(...) tnt::log(tnt::WARNING, __FILE__, __LINE__, __VA_ARGS__) +#define TNT_LOG_ERROR(...) tnt::log(tnt::ERROR, __FILE__, __LINE__, __VA_ARGS__) diff --git a/test/BufferGPerfTest.cpp b/test/BufferGPerfTest.cpp index 898ad5710..ba51573ec 100644 --- a/test/BufferGPerfTest.cpp +++ b/test/BufferGPerfTest.cpp @@ -71,12 +71,12 @@ struct StaticBuffer { template void write(T&& t) { - mempcpy(p, &t, sizeof(t)); + memcpy(p, &t, sizeof(t)); p += sizeof(t); } void write(WData d) { - mempcpy(p, d.data, d.size); + memcpy(p, d.data, d.size); p += d.size; } };