diff options
author | phintuka <phintuka> | 2006-07-02 18:12:21 +0000 |
---|---|---|
committer | phintuka <phintuka> | 2006-07-02 18:12:21 +0000 |
commit | 1611098d37ed0188b9720f95d134aa55284f6816 (patch) | |
tree | 003c61c3a4304d688e895452303c84841ea9d94b /tools/cxsocket.h | |
parent | b5b017c0b2aba7530240d788aebe842b8dc313af (diff) | |
download | xineliboutput-1611098d37ed0188b9720f95d134aa55284f6816.tar.gz xineliboutput-1611098d37ed0188b9720f95d134aa55284f6816.tar.bz2 |
added set_socket_buffers and set_multicast_options
Diffstat (limited to 'tools/cxsocket.h')
-rw-r--r-- | tools/cxsocket.h | 88 |
1 files changed, 63 insertions, 25 deletions
diff --git a/tools/cxsocket.h b/tools/cxsocket.h index 612919ed..9bcc455f 100644 --- a/tools/cxsocket.h +++ b/tools/cxsocket.h @@ -4,7 +4,7 @@ * See the main source file 'xineliboutput.c' for copyright information and * how to reach the author. * - * $Id: cxsocket.h,v 1.3 2006-06-04 11:00:04 phintuka Exp $ + * $Id: cxsocket.h,v 1.4 2006-07-02 18:12:21 phintuka Exp $ * */ @@ -14,6 +14,67 @@ #define CLOSESOCKET(fd) do { if(fd>=0) { close(fd); fd=-1; } } while(0) // +// Set socket buffers +// +static inline void set_socket_buffers(int s, int txbuf, int rxbuf) +{ + int max_buf = txbuf; + /*while(max_buf) {*/ + errno = 0; + if(setsockopt(s, SOL_SOCKET, SO_SNDBUF, &max_buf, sizeof(int))) { + LOGERR("setsockopt(SO_SNDBUF,%d) failed", max_buf); + /*max_buf >>= 1;*/ + } + /*else {*/ + int tmp = 0; + int len = sizeof(int); + errno = 0; + if(getsockopt(s, SOL_SOCKET, SO_SNDBUF, &tmp, (socklen_t*)&len)) { + LOGERR("getsockopt(SO_SNDBUF,%d) failed", max_buf); + /*break;*/ + } else if(tmp != max_buf) { + LOGDBG("setsockopt(SO_SNDBUF): got %d bytes", tmp); + /*max_buf >>= 1;*/ + /*continue;*/ + } + /*}*/ + /*}*/ + + max_buf = rxbuf; + setsockopt(s, SOL_SOCKET, SO_RCVBUF, &max_buf, sizeof(int)); +} + +// +// Set multicast options +// +static inline int set_multicast_options(int fd_multicast, int ttl) +{ + int iReuse = 1, iLoop = 1, iTtl = xc.remote_rtp_ttl; + + errno = 0; + + if(setsockopt(fd_multicast, SOL_SOCKET, SO_REUSEADDR, + &iReuse, sizeof(int)) < 0) { + LOGERR("setsockopt(SO_REUSEADDR) failed"); + return -1; + } + + if(setsockopt(fd_multicast, IPPROTO_IP, IP_MULTICAST_TTL, + &iTtl, sizeof(int))) { + LOGERR("setsockopt(IP_MULTICAST_TTL) failed"); + return -1; + } + + if(setsockopt(fd_multicast, IPPROTO_IP, IP_MULTICAST_LOOP, + &iLoop, sizeof(int))) { + LOGERR("setsockopt(IP_MULTICAST_LOOP) failed"); + return -1; + } + + return 0; +} + +// // Connect data socket to client (take address from fd_control) // static inline int sock_connect(int fd_control, int port, int type) @@ -44,31 +105,8 @@ static inline int sock_connect(int fd_control, int port, int type) return -1; } -#if 1 // Set socket buffers: large send buffer, small receive buffer - { - int max_buf = KILOBYTE(128); - //while(max_buf) { - errno = 0; - if(setsockopt(s, SOL_SOCKET, SO_SNDBUF, &max_buf, sizeof(int))) { - LOGERR("setsockopt(SO_SNDBUF,%d) failed", max_buf); - max_buf >>= 1; - } else { - int tmp = 0; - int len = sizeof(int); - errno = 0; - if(getsockopt(s, SOL_SOCKET, SO_SNDBUF, &tmp, (socklen_t*)&len)) { - LOGERR("getsockopt(SO_SNDBUF,%d) failed", max_buf); - max_buf >>= 1; - } else if(tmp != max_buf) { - LOGDBG("setsockopt(SO_SNDBUF): got %d bytes", tmp); - max_buf >>= 1; - } - } - max_buf = 1024; - setsockopt(s, SOL_SOCKET, SO_RCVBUF, &max_buf, sizeof(int)); - } -#endif + set_socket_buffers(s, KILOBYTE(256), 2048); sin.sin_family = AF_INET; sin.sin_port = htons(port); |