comparison src/lib/net.c @ 17461:2e239d925c09

lib: Changed net_geterror() to return errno instead of -1 if getsockopt() fails. None of the callers were actually checking for the -1 error value but instead just passing it to strerror(). Since this error should just about never happen it's better to just return a usable return value than try to remember to handle errors that can't normally even happen. Found by Coverity
author Timo Sirainen <tss@iki.fi>
date Fri, 13 Jun 2014 00:09:23 +0300
parents e279bd060c28
children 95ac50948e39
comparison
equal deleted inserted replaced
17460:c699a3eb0b75 17461:2e239d925c09
959 int net_geterror(int fd) 959 int net_geterror(int fd)
960 { 960 {
961 int data; 961 int data;
962 socklen_t len = sizeof(data); 962 socklen_t len = sizeof(data);
963 963
964 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &data, &len) == -1) 964 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &data, &len) == -1) {
965 return -1; 965 /* we're now really returning the getsockopt()'s error code
966 instead of the socket's, but normally we should never get
967 here anyway. */
968 return errno;
969 }
966 970
967 return data; 971 return data;
968 } 972 }
969 973
970 const char *net_gethosterror(int error) 974 const char *net_gethosterror(int error)