From 3ae5ac5be962983e5e9d17de6b242033fbf669be Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 13 Nov 2012 23:20:17 +0100 Subject: [PATCH] Fixed a typo and minor speedup in dtsc lib, fixed a bug when sending or receiving empty strings in socket lib. --- lib/dtsc.cpp | 4 ++-- lib/socket.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/dtsc.cpp b/lib/dtsc.cpp index ab9dbdc2..7ee542e2 100644 --- a/lib/dtsc.cpp +++ b/lib/dtsc.cpp @@ -145,7 +145,7 @@ std::string & DTSC::Stream::lastData(){ return *datapointer; } -/// Returns the packed in this buffer number. +/// Returns the packet in this buffer number. /// \arg num Buffer number. JSON::Value & DTSC::Stream::getPacket(unsigned int num){ return buffers[num]; @@ -169,7 +169,7 @@ 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; + if (num >= buffers.size() || !buffers[num].isObject()) return emptystring; return buffers[num].toNetPacked(); } diff --git a/lib/socket.cpp b/lib/socket.cpp index 5dc642f7..b2d70084 100644 --- a/lib/socket.cpp +++ b/lib/socket.cpp @@ -442,7 +442,7 @@ void Socket::Connection::Send(std::string & data){ /// \param len Amount of bytes to write. /// \returns The amount of bytes actually written. int Socket::Connection::iwrite(const void * buffer, int len){ - if (!connected()){return 0;} + if (!connected() || len < 1){return 0;} int r; if (sock >= 0){ r = send(sock, buffer, len, 0); @@ -479,7 +479,7 @@ int Socket::Connection::iwrite(const void * buffer, int len){ /// \param len Amount of bytes to read. /// \returns The amount of bytes actually read. int Socket::Connection::iread(void * buffer, int len){ - if (!connected()){return 0;} + if (!connected() || len < 1){return 0;} int r; if (sock >= 0){ r = recv(sock, buffer, len, 0);