diff options
author | zwer <zwer@1f4bef6d-8e0a-0410-8695-e467da8aaccf> | 2007-01-06 22:04:00 +0000 |
---|---|---|
committer | zwer <zwer@1f4bef6d-8e0a-0410-8695-e467da8aaccf> | 2007-01-06 22:04:00 +0000 |
commit | c6b150c7a364c5cb9d5149a92c81f854eb71d6d4 (patch) | |
tree | 023c9451d073c84056496a2bf5cb3df75d13cba0 /tools | |
parent | a1dc189c5334990a62f7b15bfa45071eec1d6db9 (diff) | |
download | vdr-plugin-ffnetdev-c6b150c7a364c5cb9d5149a92c81f854eb71d6d4.tar.gz vdr-plugin-ffnetdev-c6b150c7a364c5cb9d5149a92c81f854eb71d6d4.tar.bz2 |
- tests mit UDP-Streaming
git-svn-id: svn://svn.berlios.de/ffnetdev/trunk@24 1f4bef6d-8e0a-0410-8695-e467da8aaccf
Diffstat (limited to 'tools')
-rw-r--r-- | tools/socket.c | 44 | ||||
-rw-r--r-- | tools/socket.h | 11 |
2 files changed, 54 insertions, 1 deletions
diff --git a/tools/socket.c b/tools/socket.c index 2061dec..8bb7359 100644 --- a/tools/socket.c +++ b/tools/socket.c @@ -1,11 +1,15 @@ #include "tools/socket.h" +#include <vdr/tools.h> + #include <string.h> #include <arpa/inet.h> #include <unistd.h> #include <errno.h> #include <fcntl.h> +#define UDP_TX_BUF_SIZE ((188*7+3)*20) + cTBSocket::cTBSocket(int Type) { memset(&m_LocalAddr, 0, sizeof(m_LocalAddr)); memset(&m_RemoteAddr, 0, sizeof(m_RemoteAddr)); @@ -16,6 +20,46 @@ cTBSocket::~cTBSocket() { if (IsOpen()) Close(); } +bool cTBSocket::OpenUDP(const std::string &Host, unsigned int Port) { + int socket, tmp; + struct sockaddr_in my_addr; + + if (IsOpen()) Close(); + + if ((socket = ::socket(AF_INET, m_Type, 0)) == -1) + return false; + + m_RemoteAddr.sin_family = AF_INET; + m_RemoteAddr.sin_port = htons(Port); + m_RemoteAddr.sin_addr.s_addr = inet_addr(Host.c_str()); + + my_addr.sin_family = AF_INET; + my_addr.sin_port = htons(Port); + my_addr.sin_addr.s_addr = htonl(INADDR_ANY); + +/* tmp = 1; + if (setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, (char*)&tmp, sizeof(tmp)) < 0) + goto closefd;*/ + + /* limit the tx buf size to limit latency */ + tmp = UDP_TX_BUF_SIZE; + if (setsockopt(socket, SOL_SOCKET, SO_SNDBUF, (char*)&tmp, sizeof(tmp)) < 0) + goto closefd; + + /* the bind is needed to give a port to the socket now */ +/* if (bind(socket,(struct sockaddr *)&my_addr, sizeof(my_addr)) < 0) + goto closefd;*/ + + if (!cTBSource::Open(socket)) + goto closefd; // return false; + + return true; + +closefd: + ::close(socket); + return false; +} + bool cTBSocket::Connect(const std::string &Host, unsigned int Port) { socklen_t len; int socket; diff --git a/tools/socket.h b/tools/socket.h index d1a7d62..ee9c632 100644 --- a/tools/socket.h +++ b/tools/socket.h @@ -44,6 +44,11 @@ public: otherwise, setting errno appropriately. */ virtual bool Shutdown(int How); + /* OpenUDP() Open the associated socket. + Returns true on success and false otherwise, setting errno + appropriately. */ + virtual bool OpenUDP(const std::string &Ip, uint Port); + /* Close() closes the associated socket and releases all structures. Returns true on success and false otherwise, setting errno appropriately. The object is in the closed state afterwards, regardless @@ -102,7 +107,11 @@ inline ssize_t cTBSocket::SysRead(void *Buffer, size_t Length) const { } inline ssize_t cTBSocket::SysWrite(const void *Buffer, size_t Length) const { - return ::send(*this, Buffer, Length, 0); + if ((m_Type == SOCK_DGRAM)) { + socklen_t len = sizeof(m_RemoteAddr); + return ::sendto(*this, Buffer, Length, 0, (sockaddr*)&m_RemoteAddr, len); + } else + return ::send(*this, Buffer, Length, 0); } #endif // TOOLBOX_SOCKET_H |