Fixed handling of WSAEWOULDBLOCK to be generic (#2260)

* Fixed handling of WSAEWOULDBLOCK to be generic

I don't know what was the intention of this early if statement but
now this is properly evaluated in wsa_error_no function if this is
performance issue I suggest moving evaluating this error code to the
beginning of wsa_error_no.

* Fixed handling of WSAEWOULDBLOCK to be generic

Introduced default pointer to const char * and overrides this as NULL
if function is called by zmq::wsa_error()

* Fixed handling of WSAEWOULDBLOCK to be generic

Introduced default pointer to const char * and overrides this as NULL
if function is called by zmq::wsa_error()
This commit is contained in:
Cziken 2016-12-16 15:51:00 +01:00 committed by Luca Boccassi
parent 2b565088d0
commit d514bb598a
2 changed files with 4 additions and 9 deletions

View File

@ -92,15 +92,10 @@ void zmq::zmq_abort(const char *errmsg_)
const char *zmq::wsa_error()
{
const int last_error = WSAGetLastError();
// TODO: This is not a generic way to handle this...
if (last_error == WSAEWOULDBLOCK)
return NULL;
return wsa_error_no (last_error);
return wsa_error_no (WSAGetLastError(), NULL);
}
const char *zmq::wsa_error_no (int no_)
const char *zmq::wsa_error_no (int no_, const char * wsae_wouldblock_string)
{
// TODO: It seems that list of Windows socket errors is longer than this.
// Investigate whether there's a way to convert it into the string
@ -121,7 +116,7 @@ const char *zmq::wsa_error_no (int no_)
(no_ == WSAEMFILE) ?
"Too many open files" :
(no_ == WSAEWOULDBLOCK) ?
"Operation would block" :
wsae_wouldblock_string :
(no_ == WSAEINPROGRESS) ?
"Operation now in progress" :
(no_ == WSAEALREADY) ?

View File

@ -65,7 +65,7 @@ namespace zmq
namespace zmq
{
const char *wsa_error ();
const char *wsa_error_no (int no_);
const char *wsa_error_no (int no_, const char * wsae_wouldblock_string = "Operation would block");
void win_error (char *buffer_, size_t buffer_size_);
int wsa_error_to_errno (int errcode);
}