Skip to content

Commit

Permalink
Merge pull request ros-industrial#102 from shaun-edwards/issue48_pass…
Browse files Browse the repository at this point in the history
…_errno

Fix for issue ros-industrial#48.  Deprecated original logSocketError method
  • Loading branch information
shaun-edwards committed Feb 28, 2015
2 parents 406751d + 079a7cc commit e7ca370
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
23 changes: 21 additions & 2 deletions simple_message/include/simple_message/socket/simple_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions simple_message/src/socket/simple_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace industrial
else
{
rtn = false;
logSocketError("Socket sendBytes failed", rc);
logSocketError("Socket sendBytes failed", rc, errno);
}

}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion simple_message/src/socket/tcp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion simple_message/src/socket/tcp_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion simple_message/src/socket/udp_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e7ca370

Please sign in to comment.