Commit 1cdc68cf authored by Karl Heyes's avatar Karl Heyes

Use poll if available, select can cause stack corruption if descriptor value is over 1024

svn path=/icecast/trunk/net/; revision=14457
parent 3344ff6f
......@@ -30,6 +30,9 @@
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#ifdef HAVE_POLL
#include <poll.h>
#endif
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
......@@ -508,6 +511,26 @@ int sock_read_line(sock_t sock, char *buff, const int len)
* return 0 for try again, interrupted
* return 1 for ok
*/
#ifdef HAVE_POLL
int sock_connected (sock_t sock, int timeout)
{
struct pollfd check;
check.fd = sock;
check.events = POLLOUT;
switch (poll (&check, 1, timeout*1000))
{
case 0: return SOCK_TIMEOUT;
case -1:
if (sock_recoverable (sock_error()))
return 0;
return SOCK_ERROR;
default: return 1;
}
}
#else
int sock_connected (sock_t sock, int timeout)
{
fd_set wfds;
......@@ -545,6 +568,7 @@ int sock_connected (sock_t sock, int timeout)
return SOCK_ERROR;
}
}
#endif
#ifdef HAVE_GETADDRINFO
......
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