Comms: Move all classes to ZM:: namespace
The Socket class collides with a class named the same way from liblive555. This confuses the linker and links the wrong object leading to a crash when connecting to the RTSP server.
This commit is contained in:
parent
11d6de1aca
commit
4056782954
122
src/zm_comms.cpp
122
src/zm_comms.cpp
|
@ -34,7 +34,7 @@
|
||||||
#include <sys/filio.h> // define FIONREAD
|
#include <sys/filio.h> // define FIONREAD
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int CommsBase::readV(int iovcnt, /* const void *, int, */ ...) {
|
int ZM::CommsBase::readV(int iovcnt, /* const void *, int, */ ...) {
|
||||||
va_list arg_ptr;
|
va_list arg_ptr;
|
||||||
struct iovec iov[iovcnt];
|
struct iovec iov[iovcnt];
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ int CommsBase::readV(int iovcnt, /* const void *, int, */ ...) {
|
||||||
return nBytes;
|
return nBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CommsBase::writeV(int iovcnt, /* const void *, int, */ ...) {
|
int ZM::CommsBase::writeV(int iovcnt, /* const void *, int, */ ...) {
|
||||||
va_list arg_ptr;
|
va_list arg_ptr;
|
||||||
struct iovec iov[iovcnt];
|
struct iovec iov[iovcnt];
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ int CommsBase::writeV(int iovcnt, /* const void *, int, */ ...) {
|
||||||
return nBytes;
|
return nBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Pipe::open() {
|
bool ZM::Pipe::open() {
|
||||||
if ( ::pipe(mFd) < 0 ) {
|
if ( ::pipe(mFd) < 0 ) {
|
||||||
Error("pipe(), errno = %d, error = %s", errno, strerror(errno));
|
Error("pipe(), errno = %d, error = %s", errno, strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
|
@ -77,7 +77,7 @@ bool Pipe::open() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Pipe::close() {
|
bool ZM::Pipe::close() {
|
||||||
if ( mFd[0] > -1 ) ::close( mFd[0] );
|
if ( mFd[0] > -1 ) ::close( mFd[0] );
|
||||||
mFd[0] = -1;
|
mFd[0] = -1;
|
||||||
if ( mFd[1] > -1 ) ::close( mFd[1] );
|
if ( mFd[1] > -1 ) ::close( mFd[1] );
|
||||||
|
@ -85,7 +85,7 @@ bool Pipe::close() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Pipe::setBlocking(bool blocking) {
|
bool ZM::Pipe::setBlocking(bool blocking) {
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
/* Now set it for non-blocking I/O */
|
/* Now set it for non-blocking I/O */
|
||||||
|
@ -106,10 +106,10 @@ bool Pipe::setBlocking(bool blocking) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SockAddr::SockAddr(const struct sockaddr *addr) : mAddr(addr) {
|
ZM::SockAddr::SockAddr(const struct sockaddr *addr) : mAddr(addr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SockAddr *SockAddr::newSockAddr(const struct sockaddr &addr, socklen_t len) {
|
ZM::SockAddr *ZM::SockAddr::newSockAddr(const struct sockaddr &addr, socklen_t len) {
|
||||||
if ( (addr.sa_family == AF_INET) && (len == SockAddrInet::addrSize()) ) {
|
if ( (addr.sa_family == AF_INET) && (len == SockAddrInet::addrSize()) ) {
|
||||||
return new SockAddrInet((const struct sockaddr_in *)&addr);
|
return new SockAddrInet((const struct sockaddr_in *)&addr);
|
||||||
} else if ( (addr.sa_family == AF_UNIX) && (len == SockAddrUnix::addrSize()) ) {
|
} else if ( (addr.sa_family == AF_UNIX) && (len == SockAddrUnix::addrSize()) ) {
|
||||||
|
@ -119,7 +119,7 @@ SockAddr *SockAddr::newSockAddr(const struct sockaddr &addr, socklen_t len) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
SockAddr *SockAddr::newSockAddr(const SockAddr *addr) {
|
ZM::SockAddr *ZM::SockAddr::newSockAddr(const SockAddr *addr) {
|
||||||
if ( !addr )
|
if ( !addr )
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
@ -132,10 +132,10 @@ SockAddr *SockAddr::newSockAddr(const SockAddr *addr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
SockAddrInet::SockAddrInet() : SockAddr( (struct sockaddr *)&mAddrIn ) {
|
ZM::SockAddrInet::SockAddrInet() : SockAddr( (struct sockaddr *)&mAddrIn ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SockAddrInet::resolve(const char *host, const char *serv, const char *proto) {
|
bool ZM::SockAddrInet::resolve(const char *host, const char *serv, const char *proto) {
|
||||||
memset(&mAddrIn, 0, sizeof(mAddrIn));
|
memset(&mAddrIn, 0, sizeof(mAddrIn));
|
||||||
|
|
||||||
struct hostent *hostent = nullptr;
|
struct hostent *hostent = nullptr;
|
||||||
|
@ -157,7 +157,7 @@ bool SockAddrInet::resolve(const char *host, const char *serv, const char *proto
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SockAddrInet::resolve(const char *host, int port, const char *proto) {
|
bool ZM::SockAddrInet::resolve(const char *host, int port, const char *proto) {
|
||||||
memset(&mAddrIn, 0, sizeof(mAddrIn));
|
memset(&mAddrIn, 0, sizeof(mAddrIn));
|
||||||
|
|
||||||
struct hostent *hostent = nullptr;
|
struct hostent *hostent = nullptr;
|
||||||
|
@ -172,7 +172,7 @@ bool SockAddrInet::resolve(const char *host, int port, const char *proto) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SockAddrInet::resolve(const char *serv, const char *proto) {
|
bool ZM::SockAddrInet::resolve(const char *serv, const char *proto) {
|
||||||
memset(&mAddrIn, 0, sizeof(mAddrIn));
|
memset(&mAddrIn, 0, sizeof(mAddrIn));
|
||||||
|
|
||||||
struct servent *servent = nullptr;
|
struct servent *servent = nullptr;
|
||||||
|
@ -188,7 +188,7 @@ bool SockAddrInet::resolve(const char *serv, const char *proto) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SockAddrInet::resolve(int port, const char *proto) {
|
bool ZM::SockAddrInet::resolve(int port, const char *proto) {
|
||||||
memset(&mAddrIn, 0, sizeof(mAddrIn));
|
memset(&mAddrIn, 0, sizeof(mAddrIn));
|
||||||
|
|
||||||
mAddrIn.sin_port = htons(port);
|
mAddrIn.sin_port = htons(port);
|
||||||
|
@ -198,10 +198,10 @@ bool SockAddrInet::resolve(int port, const char *proto) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SockAddrUnix::SockAddrUnix() : SockAddr((struct sockaddr *)&mAddrUn ) {
|
ZM::SockAddrUnix::SockAddrUnix() : SockAddr((struct sockaddr *)&mAddrUn ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SockAddrUnix::resolve(const char *path, const char *proto) {
|
bool ZM::SockAddrUnix::resolve(const char *path, const char *proto) {
|
||||||
memset(&mAddrUn, 0, sizeof(mAddrUn));
|
memset(&mAddrUn, 0, sizeof(mAddrUn));
|
||||||
|
|
||||||
strncpy(mAddrUn.sun_path, path, sizeof(mAddrUn.sun_path));
|
strncpy(mAddrUn.sun_path, path, sizeof(mAddrUn.sun_path));
|
||||||
|
@ -210,7 +210,7 @@ bool SockAddrUnix::resolve(const char *path, const char *proto) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::socket() {
|
bool ZM::Socket::socket() {
|
||||||
if ( mSd >= 0 )
|
if ( mSd >= 0 )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ bool Socket::socket() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::connect() {
|
bool ZM::Socket::connect() {
|
||||||
if ( !socket() )
|
if ( !socket() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ bool Socket::connect() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::bind() {
|
bool ZM::Socket::bind() {
|
||||||
if ( !socket() )
|
if ( !socket() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -256,7 +256,7 @@ bool Socket::bind() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::listen() {
|
bool ZM::Socket::listen() {
|
||||||
if ( ::listen(mSd, SOMAXCONN) == -1 ) {
|
if ( ::listen(mSd, SOMAXCONN) == -1 ) {
|
||||||
Error("listen(), errno = %d, error = %s", errno, strerror(errno));
|
Error("listen(), errno = %d, error = %s", errno, strerror(errno));
|
||||||
close();
|
close();
|
||||||
|
@ -267,7 +267,7 @@ bool Socket::listen() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::accept() {
|
bool ZM::Socket::accept() {
|
||||||
struct sockaddr *rem_addr = mLocalAddr->getTempAddr();
|
struct sockaddr *rem_addr = mLocalAddr->getTempAddr();
|
||||||
socklen_t rem_addr_size = getAddrSize();
|
socklen_t rem_addr_size = getAddrSize();
|
||||||
|
|
||||||
|
@ -286,7 +286,7 @@ bool Socket::accept() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::accept(int &newSd) {
|
bool ZM::Socket::accept(int &newSd) {
|
||||||
struct sockaddr *rem_addr = mLocalAddr->getTempAddr();
|
struct sockaddr *rem_addr = mLocalAddr->getTempAddr();
|
||||||
socklen_t rem_addr_size = getAddrSize();
|
socklen_t rem_addr_size = getAddrSize();
|
||||||
|
|
||||||
|
@ -300,14 +300,14 @@ bool Socket::accept(int &newSd) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::close() {
|
bool ZM::Socket::close() {
|
||||||
if ( mSd > -1 ) ::close(mSd);
|
if ( mSd > -1 ) ::close(mSd);
|
||||||
mSd = -1;
|
mSd = -1;
|
||||||
mState = CLOSED;
|
mState = CLOSED;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Socket::bytesToRead() const {
|
int ZM::Socket::bytesToRead() const {
|
||||||
int bytes_to_read = 0;
|
int bytes_to_read = 0;
|
||||||
|
|
||||||
if ( ioctl(mSd, FIONREAD, &bytes_to_read) < 0 ) {
|
if ( ioctl(mSd, FIONREAD, &bytes_to_read) < 0 ) {
|
||||||
|
@ -317,7 +317,7 @@ int Socket::bytesToRead() const {
|
||||||
return bytes_to_read;
|
return bytes_to_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::getBlocking(bool &blocking) {
|
bool ZM::Socket::getBlocking(bool &blocking) {
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
if ( (flags = fcntl(mSd, F_GETFL)) < 0 ) {
|
if ( (flags = fcntl(mSd, F_GETFL)) < 0 ) {
|
||||||
|
@ -328,7 +328,7 @@ bool Socket::getBlocking(bool &blocking) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::setBlocking(bool blocking) {
|
bool ZM::Socket::setBlocking(bool blocking) {
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
/* Now set it for non-blocking I/O */
|
/* Now set it for non-blocking I/O */
|
||||||
|
@ -349,7 +349,7 @@ bool Socket::setBlocking(bool blocking) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::getSendBufferSize(int &buffersize) const {
|
bool ZM::Socket::getSendBufferSize(int &buffersize) const {
|
||||||
socklen_t optlen = sizeof(buffersize);
|
socklen_t optlen = sizeof(buffersize);
|
||||||
if ( getsockopt(mSd, SOL_SOCKET, SO_SNDBUF, &buffersize, &optlen) < 0 ) {
|
if ( getsockopt(mSd, SOL_SOCKET, SO_SNDBUF, &buffersize, &optlen) < 0 ) {
|
||||||
Error("getsockopt(), errno = %d, error = %s", errno, strerror(errno));
|
Error("getsockopt(), errno = %d, error = %s", errno, strerror(errno));
|
||||||
|
@ -358,7 +358,7 @@ bool Socket::getSendBufferSize(int &buffersize) const {
|
||||||
return buffersize;
|
return buffersize;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::getRecvBufferSize(int &buffersize) const {
|
bool ZM::Socket::getRecvBufferSize(int &buffersize) const {
|
||||||
socklen_t optlen = sizeof(buffersize);
|
socklen_t optlen = sizeof(buffersize);
|
||||||
if ( getsockopt(mSd, SOL_SOCKET, SO_RCVBUF, &buffersize, &optlen) < 0 ) {
|
if ( getsockopt(mSd, SOL_SOCKET, SO_RCVBUF, &buffersize, &optlen) < 0 ) {
|
||||||
Error("getsockopt(), errno = %d, error = %s", errno, strerror(errno));
|
Error("getsockopt(), errno = %d, error = %s", errno, strerror(errno));
|
||||||
|
@ -367,7 +367,7 @@ bool Socket::getRecvBufferSize(int &buffersize) const {
|
||||||
return buffersize;
|
return buffersize;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::setSendBufferSize(int buffersize) {
|
bool ZM::Socket::setSendBufferSize(int buffersize) {
|
||||||
if ( setsockopt(mSd, SOL_SOCKET, SO_SNDBUF, (char *)&buffersize, sizeof(buffersize)) < 0 ) {
|
if ( setsockopt(mSd, SOL_SOCKET, SO_SNDBUF, (char *)&buffersize, sizeof(buffersize)) < 0 ) {
|
||||||
Error("setsockopt(), errno = %d, error = %s", errno, strerror(errno));
|
Error("setsockopt(), errno = %d, error = %s", errno, strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
|
@ -375,7 +375,7 @@ bool Socket::setSendBufferSize(int buffersize) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::setRecvBufferSize(int buffersize) {
|
bool ZM::Socket::setRecvBufferSize(int buffersize) {
|
||||||
if ( setsockopt( mSd, SOL_SOCKET, SO_RCVBUF, (char *)&buffersize, sizeof(buffersize)) < 0 ) {
|
if ( setsockopt( mSd, SOL_SOCKET, SO_RCVBUF, (char *)&buffersize, sizeof(buffersize)) < 0 ) {
|
||||||
Error("setsockopt(), errno = %d, error = %s", errno, strerror(errno));
|
Error("setsockopt(), errno = %d, error = %s", errno, strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
|
@ -383,7 +383,7 @@ bool Socket::setRecvBufferSize(int buffersize) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::getRouting(bool &route) const {
|
bool ZM::Socket::getRouting(bool &route) const {
|
||||||
int dontRoute;
|
int dontRoute;
|
||||||
socklen_t optlen = sizeof(dontRoute);
|
socklen_t optlen = sizeof(dontRoute);
|
||||||
if ( getsockopt(mSd, SOL_SOCKET, SO_DONTROUTE, &dontRoute, &optlen) < 0 ) {
|
if ( getsockopt(mSd, SOL_SOCKET, SO_DONTROUTE, &dontRoute, &optlen) < 0 ) {
|
||||||
|
@ -394,7 +394,7 @@ bool Socket::getRouting(bool &route) const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::setRouting(bool route) {
|
bool ZM::Socket::setRouting(bool route) {
|
||||||
int dontRoute = !route;
|
int dontRoute = !route;
|
||||||
if ( setsockopt(mSd, SOL_SOCKET, SO_DONTROUTE, (char *)&dontRoute, sizeof(dontRoute)) < 0 ) {
|
if ( setsockopt(mSd, SOL_SOCKET, SO_DONTROUTE, (char *)&dontRoute, sizeof(dontRoute)) < 0 ) {
|
||||||
Error("setsockopt(), errno = %d, error = %s", errno, strerror(errno));
|
Error("setsockopt(), errno = %d, error = %s", errno, strerror(errno));
|
||||||
|
@ -403,7 +403,7 @@ bool Socket::setRouting(bool route) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::getNoDelay(bool &nodelay) const {
|
bool ZM::Socket::getNoDelay(bool &nodelay) const {
|
||||||
int int_nodelay;
|
int int_nodelay;
|
||||||
socklen_t optlen = sizeof(int_nodelay);
|
socklen_t optlen = sizeof(int_nodelay);
|
||||||
if ( getsockopt(mSd, IPPROTO_TCP, TCP_NODELAY, &int_nodelay, &optlen) < 0 ) {
|
if ( getsockopt(mSd, IPPROTO_TCP, TCP_NODELAY, &int_nodelay, &optlen) < 0 ) {
|
||||||
|
@ -414,7 +414,7 @@ bool Socket::getNoDelay(bool &nodelay) const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::setNoDelay(bool nodelay) {
|
bool ZM::Socket::setNoDelay(bool nodelay) {
|
||||||
int int_nodelay = nodelay;
|
int int_nodelay = nodelay;
|
||||||
|
|
||||||
if ( setsockopt(mSd, IPPROTO_TCP, TCP_NODELAY, (char *)&int_nodelay, sizeof(int_nodelay)) < 0 ) {
|
if ( setsockopt(mSd, IPPROTO_TCP, TCP_NODELAY, (char *)&int_nodelay, sizeof(int_nodelay)) < 0 ) {
|
||||||
|
@ -424,7 +424,7 @@ bool Socket::setNoDelay(bool nodelay) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InetSocket::connect(const char *host, const char *serv) {
|
bool ZM::InetSocket::connect(const char *host, const char *serv) {
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
struct addrinfo *result, *rp;
|
struct addrinfo *result, *rp;
|
||||||
int s;
|
int s;
|
||||||
|
@ -492,14 +492,14 @@ bool InetSocket::connect(const char *host, const char *serv) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InetSocket::connect(const char *host, int port) {
|
bool ZM::InetSocket::connect(const char *host, int port) {
|
||||||
char serv[8];
|
char serv[8];
|
||||||
snprintf(serv, sizeof(serv), "%d", port);
|
snprintf(serv, sizeof(serv), "%d", port);
|
||||||
|
|
||||||
return connect(host, serv);
|
return connect(host, serv);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InetSocket::bind(const char * host, const char * serv) {
|
bool ZM::InetSocket::bind(const char * host, const char * serv) {
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
|
|
||||||
memset(&hints, 0, sizeof(struct addrinfo));
|
memset(&hints, 0, sizeof(struct addrinfo));
|
||||||
|
@ -554,33 +554,33 @@ bool InetSocket::bind(const char * host, const char * serv) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InetSocket::bind(const char * serv) {
|
bool ZM::InetSocket::bind(const char * serv) {
|
||||||
return bind(nullptr, serv);
|
return bind(nullptr, serv);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InetSocket::bind(const char * host, int port) {
|
bool ZM::InetSocket::bind(const char * host, int port) {
|
||||||
char serv[8];
|
char serv[8];
|
||||||
snprintf(serv, sizeof(serv), "%d", port);
|
snprintf(serv, sizeof(serv), "%d", port);
|
||||||
|
|
||||||
return bind(host, serv);
|
return bind(host, serv);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InetSocket::bind(int port) {
|
bool ZM::InetSocket::bind(int port) {
|
||||||
char serv[8];
|
char serv[8];
|
||||||
snprintf(serv, sizeof(serv), "%d", port);
|
snprintf(serv, sizeof(serv), "%d", port);
|
||||||
|
|
||||||
return bind(nullptr, serv);
|
return bind(nullptr, serv);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TcpInetServer::listen() {
|
bool ZM::TcpInetServer::listen() {
|
||||||
return Socket::listen();
|
return Socket::listen();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TcpInetServer::accept() {
|
bool ZM::TcpInetServer::accept() {
|
||||||
return Socket::accept();
|
return Socket::accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TcpInetServer::accept(TcpInetSocket *&newSocket) {
|
bool ZM::TcpInetServer::accept(TcpInetSocket *&newSocket) {
|
||||||
int newSd = -1;
|
int newSd = -1;
|
||||||
newSocket = nullptr;
|
newSocket = nullptr;
|
||||||
|
|
||||||
|
@ -592,7 +592,7 @@ bool TcpInetServer::accept(TcpInetSocket *&newSocket) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TcpUnixServer::accept(TcpUnixSocket *&newSocket) {
|
bool ZM::TcpUnixServer::accept(TcpUnixSocket *&newSocket) {
|
||||||
int newSd = -1;
|
int newSd = -1;
|
||||||
newSocket = nullptr;
|
newSocket = nullptr;
|
||||||
|
|
||||||
|
@ -604,43 +604,43 @@ bool TcpUnixServer::accept(TcpUnixSocket *&newSocket) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Select::Select() : mHasTimeout(false), mMaxFd(-1) {
|
ZM::Select::Select() : mHasTimeout(false), mMaxFd(-1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Select::Select(struct timeval timeout) : mMaxFd(-1) {
|
ZM::Select::Select(struct timeval timeout) : mMaxFd(-1) {
|
||||||
setTimeout(timeout);
|
setTimeout(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
Select::Select(int timeout) : mMaxFd(-1) {
|
ZM::Select::Select(int timeout) : mMaxFd(-1) {
|
||||||
setTimeout(timeout);
|
setTimeout(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
Select::Select(double timeout) : mMaxFd(-1) {
|
ZM::Select::Select(double timeout) : mMaxFd(-1) {
|
||||||
setTimeout(timeout);
|
setTimeout(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Select::setTimeout(int timeout) {
|
void ZM::Select::setTimeout(int timeout) {
|
||||||
mTimeout.tv_sec = timeout;
|
mTimeout.tv_sec = timeout;
|
||||||
mTimeout.tv_usec = 0;
|
mTimeout.tv_usec = 0;
|
||||||
mHasTimeout = true;
|
mHasTimeout = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Select::setTimeout(double timeout) {
|
void ZM::Select::setTimeout(double timeout) {
|
||||||
mTimeout.tv_sec = int(timeout);
|
mTimeout.tv_sec = int(timeout);
|
||||||
mTimeout.tv_usec = suseconds_t((timeout-mTimeout.tv_sec)*1000000.0);
|
mTimeout.tv_usec = suseconds_t((timeout-mTimeout.tv_sec)*1000000.0);
|
||||||
mHasTimeout = true;
|
mHasTimeout = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Select::setTimeout(struct timeval timeout) {
|
void ZM::Select::setTimeout(struct timeval timeout) {
|
||||||
mTimeout = timeout;
|
mTimeout = timeout;
|
||||||
mHasTimeout = true;
|
mHasTimeout = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Select::clearTimeout() {
|
void ZM::Select::clearTimeout() {
|
||||||
mHasTimeout = false;
|
mHasTimeout = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Select::calcMaxFd() {
|
void ZM::Select::calcMaxFd() {
|
||||||
mMaxFd = -1;
|
mMaxFd = -1;
|
||||||
for ( CommsSet::iterator iter = mReaders.begin(); iter != mReaders.end(); ++iter ) {
|
for ( CommsSet::iterator iter = mReaders.begin(); iter != mReaders.end(); ++iter ) {
|
||||||
if ( (*iter)->getMaxDesc() > mMaxFd )
|
if ( (*iter)->getMaxDesc() > mMaxFd )
|
||||||
|
@ -652,7 +652,7 @@ void Select::calcMaxFd() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Select::addReader(CommsBase *comms) {
|
bool ZM::Select::addReader(CommsBase *comms) {
|
||||||
if ( !comms->isOpen() ) {
|
if ( !comms->isOpen() ) {
|
||||||
Error("Unable to add closed reader");
|
Error("Unable to add closed reader");
|
||||||
return false;
|
return false;
|
||||||
|
@ -665,7 +665,7 @@ bool Select::addReader(CommsBase *comms) {
|
||||||
return result.second;
|
return result.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Select::deleteReader(CommsBase *comms) {
|
bool ZM::Select::deleteReader(CommsBase *comms) {
|
||||||
if ( !comms->isOpen() ) {
|
if ( !comms->isOpen() ) {
|
||||||
Error("Unable to add closed reader");
|
Error("Unable to add closed reader");
|
||||||
return false;
|
return false;
|
||||||
|
@ -677,12 +677,12 @@ bool Select::deleteReader(CommsBase *comms) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Select::clearReaders() {
|
void ZM::Select::clearReaders() {
|
||||||
mReaders.clear();
|
mReaders.clear();
|
||||||
mMaxFd = -1;
|
mMaxFd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Select::addWriter(CommsBase *comms) {
|
bool ZM::Select::addWriter(CommsBase *comms) {
|
||||||
std::pair<CommsSet::iterator, bool> result = mWriters.insert(comms);
|
std::pair<CommsSet::iterator, bool> result = mWriters.insert(comms);
|
||||||
if ( result.second ) {
|
if ( result.second ) {
|
||||||
if ( comms->getMaxDesc() > mMaxFd )
|
if ( comms->getMaxDesc() > mMaxFd )
|
||||||
|
@ -691,7 +691,7 @@ bool Select::addWriter(CommsBase *comms) {
|
||||||
return result.second;
|
return result.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Select::deleteWriter(CommsBase *comms) {
|
bool ZM::Select::deleteWriter(CommsBase *comms) {
|
||||||
if ( mWriters.erase(comms) ) {
|
if ( mWriters.erase(comms) ) {
|
||||||
calcMaxFd();
|
calcMaxFd();
|
||||||
return true;
|
return true;
|
||||||
|
@ -699,12 +699,12 @@ bool Select::deleteWriter(CommsBase *comms) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Select::clearWriters() {
|
void ZM::Select::clearWriters() {
|
||||||
mWriters.clear();
|
mWriters.clear();
|
||||||
mMaxFd = -1;
|
mMaxFd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Select::wait() {
|
int ZM::Select::wait() {
|
||||||
struct timeval tempTimeout = mTimeout;
|
struct timeval tempTimeout = mTimeout;
|
||||||
struct timeval *selectTimeout = mHasTimeout?&tempTimeout:nullptr;
|
struct timeval *selectTimeout = mHasTimeout?&tempTimeout:nullptr;
|
||||||
|
|
||||||
|
@ -737,10 +737,10 @@ int Select::wait() {
|
||||||
return nFound;
|
return nFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Select::CommsList &Select::getReadable() const {
|
const ZM::Select::CommsList &ZM::Select::getReadable() const {
|
||||||
return mReadable;
|
return mReadable;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Select::CommsList &Select::getWriteable() const {
|
const ZM::Select::CommsList &ZM::Select::getWriteable() const {
|
||||||
return mWriteable;
|
return mWriteable;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,8 @@
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace ZM {
|
||||||
|
|
||||||
class CommsException : public Exception {
|
class CommsException : public Exception {
|
||||||
public:
|
public:
|
||||||
explicit CommsException( const std::string &message ) : Exception( message ) { }
|
explicit CommsException( const std::string &message ) : Exception( message ) { }
|
||||||
|
@ -643,4 +645,6 @@ public:
|
||||||
const CommsList &getWriteable() const;
|
const CommsList &getWriteable() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif // ZM_COMMS_H
|
#endif // ZM_COMMS_H
|
||||||
|
|
|
@ -243,10 +243,10 @@ int RtpCtrlThread::recvPackets( unsigned char *buffer, ssize_t nBytes ) {
|
||||||
|
|
||||||
int RtpCtrlThread::run() {
|
int RtpCtrlThread::run() {
|
||||||
Debug( 2, "Starting control thread %x on port %d", mRtpSource.getSsrc(), mRtpSource.getLocalCtrlPort() );
|
Debug( 2, "Starting control thread %x on port %d", mRtpSource.getSsrc(), mRtpSource.getLocalCtrlPort() );
|
||||||
SockAddrInet localAddr, remoteAddr;
|
ZM::SockAddrInet localAddr, remoteAddr;
|
||||||
|
|
||||||
bool sendReports;
|
bool sendReports;
|
||||||
UdpInetSocket rtpCtrlServer;
|
ZM::UdpInetSocket rtpCtrlServer;
|
||||||
if ( mRtpSource.getLocalHost() != "" ) {
|
if ( mRtpSource.getLocalHost() != "" ) {
|
||||||
if ( !rtpCtrlServer.bind( mRtpSource.getLocalHost().c_str(), mRtpSource.getLocalCtrlPort() ) )
|
if ( !rtpCtrlServer.bind( mRtpSource.getLocalHost().c_str(), mRtpSource.getLocalCtrlPort() ) )
|
||||||
Fatal( "Failed to bind RTCP server" );
|
Fatal( "Failed to bind RTCP server" );
|
||||||
|
@ -264,7 +264,7 @@ int RtpCtrlThread::run() {
|
||||||
|
|
||||||
// The only reason I can think of why we would have a timeout period is so that we can regularly send RR packets.
|
// The only reason I can think of why we would have a timeout period is so that we can regularly send RR packets.
|
||||||
// Why 10 seconds? If anything I think this should be whatever timeout value was given in the DESCRIBE response
|
// Why 10 seconds? If anything I think this should be whatever timeout value was given in the DESCRIBE response
|
||||||
Select select( 10 );
|
ZM::Select select( 10 );
|
||||||
select.addReader( &rtpCtrlServer );
|
select.addReader( &rtpCtrlServer );
|
||||||
|
|
||||||
unsigned char buffer[ZM_NETWORK_BUFSIZ];
|
unsigned char buffer[ZM_NETWORK_BUFSIZ];
|
||||||
|
@ -275,7 +275,7 @@ int RtpCtrlThread::run() {
|
||||||
while ( !mStop && select.wait() >= 0 ) {
|
while ( !mStop && select.wait() >= 0 ) {
|
||||||
|
|
||||||
time_t now = time(nullptr);
|
time_t now = time(nullptr);
|
||||||
Select::CommsList readable = select.getReadable();
|
ZM::Select::CommsList readable = select.getReadable();
|
||||||
if ( readable.size() == 0 ) {
|
if ( readable.size() == 0 ) {
|
||||||
if ( ! timeout ) {
|
if ( ! timeout ) {
|
||||||
// With this code here, we will send an SDES and RR packet every 10 seconds
|
// With this code here, we will send an SDES and RR packet every 10 seconds
|
||||||
|
@ -299,8 +299,8 @@ int RtpCtrlThread::run() {
|
||||||
timeout = false;
|
timeout = false;
|
||||||
last_receive = time(nullptr);
|
last_receive = time(nullptr);
|
||||||
}
|
}
|
||||||
for ( Select::CommsList::iterator iter = readable.begin(); iter != readable.end(); ++iter ) {
|
for ( ZM::Select::CommsList::iterator iter = readable.begin(); iter != readable.end(); ++iter ) {
|
||||||
if ( UdpInetSocket *socket = dynamic_cast<UdpInetSocket *>(*iter) ) {
|
if ( ZM::UdpInetSocket *socket = dynamic_cast<ZM::UdpInetSocket *>(*iter) ) {
|
||||||
ssize_t nBytes = socket->recv( buffer, sizeof(buffer) );
|
ssize_t nBytes = socket->recv( buffer, sizeof(buffer) );
|
||||||
Debug( 4, "Read %zd bytes on sd %d", nBytes, socket->getReadDesc() );
|
Debug( 4, "Read %zd bytes on sd %d", nBytes, socket->getReadDesc() );
|
||||||
|
|
||||||
|
|
|
@ -58,8 +58,8 @@ int RtpDataThread::run() {
|
||||||
Debug(2, "Starting data thread %d on port %d",
|
Debug(2, "Starting data thread %d on port %d",
|
||||||
mRtpSource.getSsrc(), mRtpSource.getLocalDataPort());
|
mRtpSource.getSsrc(), mRtpSource.getLocalDataPort());
|
||||||
|
|
||||||
SockAddrInet localAddr;
|
ZM::SockAddrInet localAddr;
|
||||||
UdpInetServer rtpDataSocket;
|
ZM::UdpInetServer rtpDataSocket;
|
||||||
if ( mRtpSource.getLocalHost() != "" ) {
|
if ( mRtpSource.getLocalHost() != "" ) {
|
||||||
if ( !rtpDataSocket.bind(mRtpSource.getLocalHost().c_str(), mRtpSource.getLocalDataPort()) )
|
if ( !rtpDataSocket.bind(mRtpSource.getLocalHost().c_str(), mRtpSource.getLocalDataPort()) )
|
||||||
Fatal("Failed to bind RTP server");
|
Fatal("Failed to bind RTP server");
|
||||||
|
@ -71,19 +71,19 @@ int RtpDataThread::run() {
|
||||||
}
|
}
|
||||||
Debug(3, "Bound to %s:%d", mRtpSource.getLocalHost().c_str(), mRtpSource.getLocalDataPort());
|
Debug(3, "Bound to %s:%d", mRtpSource.getLocalHost().c_str(), mRtpSource.getLocalDataPort());
|
||||||
|
|
||||||
Select select(3);
|
ZM::Select select(3);
|
||||||
select.addReader(&rtpDataSocket);
|
select.addReader(&rtpDataSocket);
|
||||||
|
|
||||||
unsigned char buffer[ZM_NETWORK_BUFSIZ];
|
unsigned char buffer[ZM_NETWORK_BUFSIZ];
|
||||||
while ( !zm_terminate && !mStop && (select.wait() >= 0) ) {
|
while ( !zm_terminate && !mStop && (select.wait() >= 0) ) {
|
||||||
Select::CommsList readable = select.getReadable();
|
ZM::Select::CommsList readable = select.getReadable();
|
||||||
if ( readable.size() == 0 ) {
|
if ( readable.size() == 0 ) {
|
||||||
Error("RTP timed out");
|
Error("RTP timed out");
|
||||||
mStop = true;
|
mStop = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for ( Select::CommsList::iterator iter = readable.begin(); iter != readable.end(); ++iter ) {
|
for ( ZM::Select::CommsList::iterator iter = readable.begin(); iter != readable.end(); ++iter ) {
|
||||||
if ( UdpInetServer *socket = dynamic_cast<UdpInetServer *>(*iter) ) {
|
if ( ZM::UdpInetServer *socket = dynamic_cast<ZM::UdpInetServer *>(*iter) ) {
|
||||||
int nBytes = socket->recv(buffer, sizeof(buffer));
|
int nBytes = socket->recv(buffer, sizeof(buffer));
|
||||||
Debug(4, "Got %d bytes on sd %d", nBytes, socket->getReadDesc());
|
Debug(4, "Got %d bytes on sd %d", nBytes, socket->getReadDesc());
|
||||||
if ( nBytes ) {
|
if ( nBytes ) {
|
||||||
|
|
|
@ -635,14 +635,14 @@ int RtspThread::run() {
|
||||||
RtpDataThread rtpDataThread( *this, *source );
|
RtpDataThread rtpDataThread( *this, *source );
|
||||||
RtpCtrlThread rtpCtrlThread( *this, *source );
|
RtpCtrlThread rtpCtrlThread( *this, *source );
|
||||||
|
|
||||||
Select select( double(config.http_timeout)/1000.0 );
|
ZM::Select select( double(config.http_timeout)/1000.0 );
|
||||||
select.addReader( &mRtspSocket );
|
select.addReader( &mRtspSocket );
|
||||||
|
|
||||||
Buffer buffer( ZM_NETWORK_BUFSIZ );
|
Buffer buffer( ZM_NETWORK_BUFSIZ );
|
||||||
std::string keepaliveMessage = "OPTIONS "+mUrl+" RTSP/1.0\r\n";
|
std::string keepaliveMessage = "OPTIONS "+mUrl+" RTSP/1.0\r\n";
|
||||||
std::string keepaliveResponse = "RTSP/1.0 200 OK\r\n";
|
std::string keepaliveResponse = "RTSP/1.0 200 OK\r\n";
|
||||||
while ( !mStop && select.wait() >= 0 ) {
|
while ( !mStop && select.wait() >= 0 ) {
|
||||||
Select::CommsList readable = select.getReadable();
|
ZM::Select::CommsList readable = select.getReadable();
|
||||||
if ( readable.size() == 0 ) {
|
if ( readable.size() == 0 ) {
|
||||||
Error( "RTSP timed out" );
|
Error( "RTSP timed out" );
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -66,8 +66,8 @@ private:
|
||||||
|
|
||||||
std::string mHttpSession; ///< Only for RTSP over HTTP sessions
|
std::string mHttpSession; ///< Only for RTSP over HTTP sessions
|
||||||
|
|
||||||
TcpInetClient mRtspSocket;
|
ZM::TcpInetClient mRtspSocket;
|
||||||
TcpInetClient mRtspSocket2;
|
ZM::TcpInetClient mRtspSocket2;
|
||||||
|
|
||||||
SourceMap mSources;
|
SourceMap mSources;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue