From c123111e702041c4847ec6b0fdbda4b3d733310b Mon Sep 17 00:00:00 2001 From: Thulinma Date: Fri, 4 May 2012 14:28:01 +0200 Subject: [PATCH] Fixed bugs for debug session may 4 2012. --- util/dtsc.cpp | 2 ++ util/socket.cpp | 12 ++++++++++++ util/socket.h | 1 + 3 files changed, 15 insertions(+) diff --git a/util/dtsc.cpp b/util/dtsc.cpp index 26601a5d..9e937d8d 100644 --- a/util/dtsc.cpp +++ b/util/dtsc.cpp @@ -102,6 +102,8 @@ bool DTSC::Stream::hasAudio(){ /// Returns a packed DTSC packet, ready to sent over the network. std::string & DTSC::Stream::outPacket(unsigned int num){ + static std::string emptystring; + if (num >= buffers.size()) return emptystring; buffers[num].Pack(true); return buffers[num].packed; } diff --git a/util/socket.cpp b/util/socket.cpp index 4ddcfb81..82c52dce 100644 --- a/util/socket.cpp +++ b/util/socket.cpp @@ -40,6 +40,18 @@ Socket::Connection::Connection(){ Blocking = false; }//Socket::Connection basic constructor + +/// Set this socket to be blocking (true) or nonblocking (false). +void Socket::Connection::setBlocking(bool blocking){ + int flags = fcntl(sock, F_GETFL, 0); + if (!blocking){ + flags |= O_NONBLOCK; + }else{ + flags &= !O_NONBLOCK; + } + fcntl(sock, F_SETFL, flags); +} + /// Close connection. The internal socket is closed and then set to -1. void Socket::Connection::close(){ #if DEBUG >= 6 diff --git a/util/socket.h b/util/socket.h index 503ec4e9..03750b2a 100644 --- a/util/socket.h +++ b/util/socket.h @@ -33,6 +33,7 @@ namespace Socket{ Connection(int sockNo); ///< Create a new base socket. Connection(std::string hostname, int port, bool nonblock); ///< Create a new TCP socket. Connection(std::string adres, bool nonblock = false); ///< Create a new Unix Socket. + void setBlocking(bool blocking); ///< Set this socket to be blocking (true) or nonblocking (false). bool canRead(); ///< Calls poll() on the socket, checking if data is available. bool canWrite(); ///< Calls poll() on the socket, checking if data can be written. signed int ready(); ///< Returns the ready-state for this socket.