1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2025-01-03 14:56:36 -05:00

clean up prototypes and sock_t handling, for win32 mainly, no functional change

svn path=/icecast/trunk/net/; revision=14041
This commit is contained in:
Karl Heyes 2007-10-24 21:42:01 +00:00
parent daa8d10380
commit 4d379b74b1
2 changed files with 30 additions and 28 deletions

View File

@ -305,14 +305,14 @@ int sock_close(sock_t sock)
*/ */
#ifdef HAVE_WRITEV #ifdef HAVE_WRITEV
ssize_t sock_writev (int sock, const struct iovec *iov, const size_t count) ssize_t sock_writev (sock_t sock, const struct iovec *iov, size_t count)
{ {
return writev (sock, iov, count); return writev (sock, iov, count);
} }
#else #else
ssize_t sock_writev (int sock, const struct iovec *iov, const size_t count) ssize_t sock_writev (sock_t sock, const struct iovec *iov, size_t count)
{ {
int i = count, accum = 0, ret; int i = count, accum = 0, ret;
const struct iovec *v = iov; const struct iovec *v = iov;
@ -343,7 +343,7 @@ ssize_t sock_writev (int sock, const struct iovec *iov, const size_t count)
** write bytes to the socket ** write bytes to the socket
** this function will _NOT_ block ** this function will _NOT_ block
*/ */
int sock_write_bytes(sock_t sock, const void *buff, const size_t len) int sock_write_bytes(sock_t sock, const void *buff, size_t len)
{ {
/* sanity check */ /* sanity check */
if (!buff) { if (!buff) {
@ -449,7 +449,7 @@ int sock_write_fmt(sock_t sock, const char *fmt, va_list ap)
#endif #endif
int sock_read_bytes(sock_t sock, char *buff, const int len) int sock_read_bytes(sock_t sock, char *buff, size_t len)
{ {
/*if (!sock_valid_socket(sock)) return 0; */ /*if (!sock_valid_socket(sock)) return 0; */
@ -508,7 +508,7 @@ int sock_read_line(sock_t sock, char *buff, const int len)
* return 0 for try again, interrupted * return 0 for try again, interrupted
* return 1 for ok * return 1 for ok
*/ */
int sock_connected (int sock, int timeout) int sock_connected (sock_t sock, int timeout)
{ {
fd_set wfds; fd_set wfds;
int val = SOCK_ERROR; int val = SOCK_ERROR;
@ -548,7 +548,7 @@ int sock_connected (int sock, int timeout)
#ifdef HAVE_GETADDRINFO #ifdef HAVE_GETADDRINFO
int sock_connect_non_blocking (const char *hostname, const unsigned port) sock_t sock_connect_non_blocking (const char *hostname, const unsigned port)
{ {
int sock = SOCK_ERROR; int sock = SOCK_ERROR;
struct addrinfo *ai, *head, hints; struct addrinfo *ai, *head, hints;
@ -592,7 +592,7 @@ int sock_connect_non_blocking (const char *hostname, const unsigned port)
*/ */
sock_t sock_connect_wto(const char *hostname, int port, int timeout) sock_t sock_connect_wto(const char *hostname, int port, int timeout)
{ {
int sock = SOCK_ERROR; sock_t sock = SOCK_ERROR;
struct addrinfo *ai, *head, hints; struct addrinfo *ai, *head, hints;
char service[8]; char service[8];
@ -693,7 +693,7 @@ sock_t sock_get_server_socket (int port, const char *sinterface)
#else #else
int sock_try_connection (int sock, const char *hostname, const unsigned port) int sock_try_connection (sock_t sock, const char *hostname, const unsigned port)
{ {
struct sockaddr_in sin, server; struct sockaddr_in sin, server;
char ip[MAX_ADDR_LEN]; char ip[MAX_ADDR_LEN];
@ -724,13 +724,13 @@ int sock_try_connection (int sock, const char *hostname, const unsigned port)
return connect(sock, (struct sockaddr *)&server, sizeof(server)); return connect(sock, (struct sockaddr *)&server, sizeof(server));
} }
int sock_connect_non_blocking (const char *hostname, const unsigned port) sock_t sock_connect_non_blocking (const char *hostname, unsigned port)
{ {
int sock; sock_t sock;
sock = socket(AF_INET, SOCK_STREAM, 0); sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == -1) if (sock == SOCK_ERROR)
return -1; return SOCK_ERROR;
sock_set_blocking (sock, SOCK_NONBLOCK); sock_set_blocking (sock, SOCK_NONBLOCK);
sock_try_connection (sock, hostname, port); sock_try_connection (sock, hostname, port);
@ -738,13 +738,13 @@ int sock_connect_non_blocking (const char *hostname, const unsigned port)
return sock; return sock;
} }
sock_t sock_connect_wto(const char *hostname, const int port, const int timeout) sock_t sock_connect_wto(const char *hostname, int port, int timeout)
{ {
int sock; sock_t sock;
sock = socket(AF_INET, SOCK_STREAM, 0); sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == -1) if (sock == SOCK_ERROR)
return -1; return SOCK_ERROR;
if (timeout) if (timeout)
{ {
@ -838,14 +838,14 @@ int sock_listen(sock_t serversock, int backlog)
return (listen(serversock, backlog) == 0); return (listen(serversock, backlog) == 0);
} }
int sock_accept(sock_t serversock, char *ip, size_t len) sock_t sock_accept(sock_t serversock, char *ip, size_t len)
{ {
#ifdef HAVE_GETNAMEINFO #ifdef HAVE_GETNAMEINFO
struct sockaddr_storage sa; struct sockaddr_storage sa;
#else #else
struct sockaddr_in sa; struct sockaddr_in sa;
#endif #endif
int ret; sock_t ret;
socklen_t slen; socklen_t slen;
if (ip == NULL || len == 0 || !sock_valid_socket(serversock)) if (ip == NULL || len == 0 || !sock_valid_socket(serversock))
@ -854,7 +854,7 @@ int sock_accept(sock_t serversock, char *ip, size_t len)
slen = sizeof(sa); slen = sizeof(sa);
ret = accept(serversock, (struct sockaddr *)&sa, &slen); ret = accept(serversock, (struct sockaddr *)&sa, &slen);
if (ret >= 0) if (ret != SOCK_ERROR)
{ {
#ifdef HAVE_GETNAMEINFO #ifdef HAVE_GETNAMEINFO
if (getnameinfo ((struct sockaddr *)&sa, slen, ip, len, NULL, 0, NI_NUMERICHOST)) if (getnameinfo ((struct sockaddr *)&sa, slen, ip, len, NULL, 0, NI_NUMERICHOST))

View File

@ -56,11 +56,13 @@ struct iovec
#define MAX_ADDR_LEN 46 #define MAX_ADDR_LEN 46
#endif #endif
typedef int sock_t; #ifndef sock_t
#define sock_t int
#endif
/* The following values are based on unix avoiding errno value clashes */ /* The following values are based on unix avoiding errno value clashes */
#define SOCK_SUCCESS 0 #define SOCK_SUCCESS 0
#define SOCK_ERROR -1 #define SOCK_ERROR (sock_t)-1
#define SOCK_TIMEOUT -2 #define SOCK_TIMEOUT -2
#define SOCK_BLOCK 0 #define SOCK_BLOCK 0
@ -113,26 +115,26 @@ int sock_set_nodelay(sock_t sock);
int sock_close(sock_t sock); int sock_close(sock_t sock);
/* Connection related socket functions */ /* Connection related socket functions */
sock_t sock_connect_wto(const char *hostname, const int port, const int timeout); sock_t sock_connect_wto(const char *hostname, int port, int timeout);
int sock_connect_non_blocking(const char *host, const unsigned port); sock_t sock_connect_non_blocking(const char *host, unsigned port);
int sock_connected(int sock, int timeout); int sock_connected(sock_t sock, int timeout);
/* Socket write functions */ /* Socket write functions */
int sock_write_bytes(sock_t sock, const void *buff, const size_t len); int sock_write_bytes(sock_t sock, const void *buff, size_t len);
int sock_write(sock_t sock, const char *fmt, ...); int sock_write(sock_t sock, const char *fmt, ...);
int sock_write_fmt(sock_t sock, const char *fmt, va_list ap); int sock_write_fmt(sock_t sock, const char *fmt, va_list ap);
int sock_write_string(sock_t sock, const char *buff); int sock_write_string(sock_t sock, const char *buff);
ssize_t sock_writev (int sock, const struct iovec *iov, const size_t count); ssize_t sock_writev (sock_t sock, const struct iovec *iov, size_t count);
/* Socket read functions */ /* Socket read functions */
int sock_read_bytes(sock_t sock, char *buff, const int len); int sock_read_bytes(sock_t sock, char *buff, size_t len);
int sock_read_line(sock_t sock, char *string, const int len); int sock_read_line(sock_t sock, char *string, const int len);
/* server socket functions */ /* server socket functions */
sock_t sock_get_server_socket(int port, const char *sinterface); sock_t sock_get_server_socket(int port, const char *sinterface);
int sock_listen(sock_t serversock, int backlog); int sock_listen(sock_t serversock, int backlog);
int sock_accept(sock_t serversock, char *ip, size_t len); sock_t sock_accept(sock_t serversock, char *ip, size_t len);
#ifdef _WIN32 #ifdef _WIN32
int inet_aton(const char *s, struct in_addr *a); int inet_aton(const char *s, struct in_addr *a);