diff --git a/simple_message/include/simple_message/socket/simple_socket.h b/simple_message/include/simple_message/socket/simple_socket.h index b1c016c9..bbca8701 100644 --- a/simple_message/include/simple_message/socket/simple_socket.h +++ b/simple_message/include/simple_message/socket/simple_socket.h @@ -226,10 +226,29 @@ class SimpleSocket : public industrial::smpl_msg_connection::SmplMsgConnection this->sock_handle_ = sock_handle_; } + /** + * \deprecated This could report the wrong error number. The method that takes + * errno as an argument should be used instead. + * \brief Logs message to error log and reports associated socket system error + * \param msg custom message prefixed to system error + * \param rc return code from socket + */ + __attribute__((deprecated( + "Please use: logSocketError(const char* msg, const int rc, const int error_no)"))) void logSocketError(const char* msg, int rc) { - int errno_ = errno; - LOG_ERROR("%s, rc: %d. Error: '%s' (errno: %d)", msg, rc, strerror(errno_), errno_); + logSocketError(msg, rc, errno); + } + + /** + * \brief Logs message to error log and reports associated socket system error + * \param msg custom message prefixed to system error + * \param rc return code from socket + * \param error_no errno value see (http://man7.org/linux/man-pages/man3/errno.3.html ) + */ + void logSocketError(const char* msg, const int rc, const int error_no) + { + LOG_ERROR("%s, rc: %d. Error: '%s' (errno: %d)", msg, rc, strerror(error_no), error_no); } // Send/Receive functions (inherited classes should override raw methods diff --git a/simple_message/src/socket/simple_socket.cpp b/simple_message/src/socket/simple_socket.cpp index 38d31ffa..83028aad 100644 --- a/simple_message/src/socket/simple_socket.cpp +++ b/simple_message/src/socket/simple_socket.cpp @@ -65,7 +65,7 @@ namespace industrial else { rtn = false; - logSocketError("Socket sendBytes failed", rc); + logSocketError("Socket sendBytes failed", rc, errno); } } @@ -127,7 +127,7 @@ namespace industrial rc = rawReceiveBytes(this->buffer_, remainBytes); if (this->SOCKET_FAIL == rc) { - this->logSocketError("Socket received failed", rc); + this->logSocketError("Socket received failed", rc, errno); remainBytes = 0; rtn = false; break; diff --git a/simple_message/src/socket/tcp_client.cpp b/simple_message/src/socket/tcp_client.cpp index fb2e21e9..c6c81329 100644 --- a/simple_message/src/socket/tcp_client.cpp +++ b/simple_message/src/socket/tcp_client.cpp @@ -117,7 +117,7 @@ bool TcpClient::makeConnect() } else { - this->logSocketError("Failed to connect to server", rc); + this->logSocketError("Failed to connect to server", rc, errno); rtn = false; } } diff --git a/simple_message/src/socket/tcp_socket.cpp b/simple_message/src/socket/tcp_socket.cpp index 07104068..f6d2f132 100644 --- a/simple_message/src/socket/tcp_socket.cpp +++ b/simple_message/src/socket/tcp_socket.cpp @@ -126,7 +126,7 @@ bool TcpSocket::rawPoll(int timeout, bool & ready, bool & error) } } } else { - this->logSocketError("Socket select function failed", rc); + this->logSocketError("Socket select function failed", rc, errno); rtn = false; } return rtn; diff --git a/simple_message/src/socket/udp_socket.cpp b/simple_message/src/socket/udp_socket.cpp index f7d332ad..be794481 100644 --- a/simple_message/src/socket/udp_socket.cpp +++ b/simple_message/src/socket/udp_socket.cpp @@ -152,7 +152,7 @@ bool UdpSocket::rawPoll(int timeout, bool & ready, bool & error) } } } else { - this->logSocketError("Socket select function failed", rc); + this->logSocketError("Socket select function failed", rc, errno); rtn = false; } return rtn;