Commit baa22108 authored by Matteo Quintiliani's avatar Matteo Quintiliani

Added function nmxp_strerror


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@1002 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent 599b66b0
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy * Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it * quintiliani@ingv.it
* *
* $Id: nmxp_base.h,v 1.29 2008-03-30 06:07:47 mtheo Exp $ * $Id: nmxp_base.h,v 1.30 2008-03-31 11:32:36 mtheo Exp $
* *
*/ */
...@@ -75,6 +75,14 @@ int nmxp_send_ctrl(int isock, void *buffer, int length); ...@@ -75,6 +75,14 @@ int nmxp_send_ctrl(int isock, void *buffer, int length);
int nmxp_setsockopt_RCVTIMEO(int isock, int timeoutsec); int nmxp_setsockopt_RCVTIMEO(int isock, int timeoutsec);
/*! \brief Wrapper to strerror, strerror_r or WSAGetLastErrorMessage
*
* \return String message of errno_value. It is static, not need to be freed.
*
*/
char *nmxp_strerror(int errno_value);
/*! \brief Receives length bytes in a buffer from a socket. /*! \brief Receives length bytes in a buffer from a socket.
* *
* \param isock A descriptor referencing the socket. * \param isock A descriptor referencing the socket.
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy * Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it * quintiliani@ingv.it
* *
* $Id: nmxp_base.c,v 1.70 2008-03-31 07:44:39 mtheo Exp $ * $Id: nmxp_base.c,v 1.71 2008-03-31 11:32:36 mtheo Exp $
* *
*/ */
...@@ -211,25 +211,52 @@ int nmxp_setsockopt_RCVTIMEO(int isock, int timeoutsec) { ...@@ -211,25 +211,52 @@ int nmxp_setsockopt_RCVTIMEO(int isock, int timeoutsec) {
return ret; return ret;
} }
int nmxp_recv_ctrl(int isock, void *buffer, int length, int timeoutsec, int *recv_errno )
{
int recvCount;
int cc;
char *buffer_char = buffer;
#define MAXLEN_RECV_ERRNO_STR 200
char *nmxp_strerror(int errno_value) {
static char ret_recv_errno_str[MAXLEN_RECV_ERRNO_STR];
#ifdef HAVE_WINDOWS_H #ifdef HAVE_WINDOWS_H
char *recv_errno_str; char *recv_errno_str;
#else #else
#ifdef HAVE_STRERROR_R #ifdef HAVE_STRERROR_R
#define MAXLEN_RECV_ERRNO_STR 200 char recv_errno_str[MAXLEN_RECV_ERRNO_STR];
char recv_errno_str[MAXLEN_RECV_ERRNO_STR]; #else
char *recv_errno_str;
#endif
#endif
ret_recv_errno_str[0] = 0;
#ifdef HAVE_WINDOWS_H
recv_errno_str = WSAGetLastErrorMessage(errno_value);
#else
#ifdef HAVE_STRERROR_R
strerror_r(errno_value, recv_errno_str, MAXLEN_RECV_ERRNO_STR);
#else #else
char *recv_errno_str; recv_errno_str = strerror(errno_value);
#endif #endif
#endif #endif
if(recv_errno_str) {
strncpy(ret_recv_errno_str, recv_errno_str, MAXLEN_RECV_ERRNO_STR);
}
return ret_recv_errno_str;
}
int nmxp_recv_ctrl(int isock, void *buffer, int length, int timeoutsec, int *recv_errno )
{
int recvCount;
int cc;
char *buffer_char = buffer;
char *recv_errno_str = NULL;
nmxp_setsockopt_RCVTIMEO(isock, timeoutsec); nmxp_setsockopt_RCVTIMEO(isock, timeoutsec);
cc = 1; cc = 1;
...@@ -274,17 +301,8 @@ int nmxp_recv_ctrl(int isock, void *buffer, int length, int timeoutsec, int *rec ...@@ -274,17 +301,8 @@ int nmxp_recv_ctrl(int isock, void *buffer, int length, int timeoutsec, int *rec
nmxp_setsockopt_RCVTIMEO(isock, 0); nmxp_setsockopt_RCVTIMEO(isock, 0);
if (recvCount != length || *recv_errno != 0 || cc <= 0) { if (recvCount != length || *recv_errno != 0 || cc <= 0) {
#ifdef HAVE_WINDOWS_H
recv_errno_str = WSAGetLastErrorMessage(*recv_errno);
#else
#ifdef HAVE_STRERROR_R recv_errno_str = nmxp_strerror(*recv_errno);
strerror_r(*recv_errno, recv_errno_str, MAXLEN_RECV_ERRNO_STR);
#else
recv_errno_str = strerror(*recv_errno);
#endif
#endif
#ifdef HAVE_WINDOWS_H #ifdef HAVE_WINDOWS_H
if(*recv_errno != WSAEWOULDBLOCK && *recv_errno != WSAETIMEDOUT) if(*recv_errno != WSAEWOULDBLOCK && *recv_errno != WSAETIMEDOUT)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment