Commit 81768801 authored by Dan McGee's avatar Dan McGee Committed by Max Kellermann

Simplify setsockopt() casting workaround

On Win32, the third setsockopt parameter has type (char *) while on POSIX systems it is (void *). However, given that it is a no-op cast to go from a char pointer to a void pointer, we can cast to a char pointer (with a possible const modifier) on all platforms and satisfy the compiler. Signed-off-by: 's avatarDan McGee <dan@archlinux.org>
parent 533a6b02
...@@ -328,7 +328,7 @@ open_udp_socket(char *hostname, unsigned short *port, ...@@ -328,7 +328,7 @@ open_udp_socket(char *hostname, unsigned short *port,
GError **error_r) GError **error_r)
{ {
int sd; int sd;
int size = 30000; const int size = 30000;
/* socket creation */ /* socket creation */
sd = socket(PF_INET, SOCK_DGRAM, 0); sd = socket(PF_INET, SOCK_DGRAM, 0);
...@@ -338,7 +338,7 @@ open_udp_socket(char *hostname, unsigned short *port, ...@@ -338,7 +338,7 @@ open_udp_socket(char *hostname, unsigned short *port,
g_strerror(errno)); g_strerror(errno));
return -1; return -1;
} }
if (setsockopt(sd, SOL_SOCKET, SO_SNDBUF, (void *) &size, sizeof(size)) < 0) { if (setsockopt(sd, SOL_SOCKET, SO_SNDBUF, (const char *) &size, sizeof(size)) < 0) {
g_set_error(error_r, raop_output_quark(), errno, g_set_error(error_r, raop_output_quark(), errno,
"failed to set UDP buffer size: %s", "failed to set UDP buffer size: %s",
g_strerror(errno)); g_strerror(errno));
......
...@@ -50,9 +50,6 @@ socket_bind_listen(int domain, int type, int protocol, ...@@ -50,9 +50,6 @@ socket_bind_listen(int domain, int type, int protocol,
{ {
int fd, ret; int fd, ret;
const int reuse = 1; const int reuse = 1;
#ifdef HAVE_STRUCT_UCRED
int passcred = 1;
#endif
fd = socket_cloexec_nonblock(domain, type, protocol); fd = socket_cloexec_nonblock(domain, type, protocol);
if (fd < 0) { if (fd < 0) {
...@@ -61,14 +58,8 @@ socket_bind_listen(int domain, int type, int protocol, ...@@ -61,14 +58,8 @@ socket_bind_listen(int domain, int type, int protocol,
return -1; return -1;
} }
#ifdef WIN32
const char *optval = (const char *)&reuse;
#else
const void *optval = &reuse;
#endif
ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
optval, sizeof(reuse)); (const char *) &reuse, sizeof(reuse));
if (ret < 0) { if (ret < 0) {
g_set_error(error, listen_quark(), errno, g_set_error(error, listen_quark(), errno,
"setsockopt() failed: %s", g_strerror(errno)); "setsockopt() failed: %s", g_strerror(errno));
...@@ -93,7 +84,8 @@ socket_bind_listen(int domain, int type, int protocol, ...@@ -93,7 +84,8 @@ socket_bind_listen(int domain, int type, int protocol,
} }
#ifdef HAVE_STRUCT_UCRED #ifdef HAVE_STRUCT_UCRED
setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &passcred, sizeof(passcred)); setsockopt(fd, SOL_SOCKET, SO_PASSCRED,
(const char *) &reuse, sizeof(reuse));
#endif #endif
return fd; return fd;
...@@ -104,12 +96,6 @@ socket_keepalive(int fd) ...@@ -104,12 +96,6 @@ socket_keepalive(int fd)
{ {
const int reuse = 1; const int reuse = 1;
#ifdef WIN32
const char *optval = (const char *)&reuse;
#else
const void *optval = &reuse;
#endif
return setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, return setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE,
optval, sizeof(reuse)); (const char *)&reuse, sizeof(reuse));
} }
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