From 7ade2da0367685e098181d7124c9ba145a010626 Mon Sep 17 00:00:00 2001 From: Charles McGarvey Date: Fri, 14 May 2010 00:35:37 -0600 Subject: [PATCH] packet copy bugfix --- src/Makefile.am | 1 + src/Moof/Packet.cc | 5 +++-- src/Moof/Service.cc | 37 +++++++++++++++++++++++++++++++++++++ src/Moof/Socket.hh | 4 ++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/Moof/Service.cc diff --git a/src/Makefile.am b/src/Makefile.am index 6dd508e..c9b5dd9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -55,6 +55,7 @@ libmoof_a_SOURCES = \ Moof/Resource.hh \ Moof/RigidBody.hh \ Moof/Script.hh \ + Moof/Service.cc \ Moof/Service.hh \ Moof/Settings.cc \ Moof/Settings.hh \ diff --git a/src/Moof/Packet.cc b/src/Moof/Packet.cc index 6923e7c..842d6c1 100644 --- a/src/Moof/Packet.cc +++ b/src/Moof/Packet.cc @@ -144,6 +144,7 @@ Packet& Packet::operator=(const Packet& copy) mBoolW = copy.mBoolW; mBoolNumR = copy.mBoolNumR; mBoolNumW = copy.mBoolNumW; + if (mBuffer) memcpy(mBuffer, copy.mBuffer, mSize); return *this; } @@ -254,7 +255,7 @@ size_t Packet::write(const void* bytes, size_t size) } if (!mBuffer) return 0; } - memcpy(&mBuffer[mW], bytes, nBytes); + memcpy(mBuffer + mW, bytes, nBytes); mW += nBytes; return nBytes; } @@ -345,7 +346,7 @@ Packet& Packet::operator>>(double& value) size_t Packet::read(void* bytes, size_t size) { size_t nBytes = std::min(size, mW - mR); - memcpy(bytes, &mBuffer[mR], nBytes); + memcpy(bytes, mBuffer + mR, nBytes); mR += nBytes; return nBytes; } diff --git a/src/Moof/Service.cc b/src/Moof/Service.cc new file mode 100644 index 0000000..43689af --- /dev/null +++ b/src/Moof/Service.cc @@ -0,0 +1,37 @@ + +/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +**] All rights reserved. +* +* vi:ts=4 sw=4 tw=75 +* +* Distributable under the terms and conditions of the 2-clause BSD license; +* see the file COPYING for a complete text of the license. +* +**************************************************************************/ + +#include "Service.hh" + + +namespace Mf { + + +ServiceBroadcaster::ServiceBroadcaster(const std::string& name) +{ +} + +void ServiceBroadcaster::update(Scalar t, Scalar dt) +{ +} + + +ServiceLocator::ServiceLocator(const std::string& name) +{ +} + +void ServiceLocator::update(Scalar t, Scalar dt) +{ +} + + +} // namespace Mf + diff --git a/src/Moof/Socket.hh b/src/Moof/Socket.hh index 948f942..fcf1a3e 100644 --- a/src/Moof/Socket.hh +++ b/src/Moof/Socket.hh @@ -390,6 +390,7 @@ public: int set(int option, int value = 0) { + if (mFd == -1) mFd = socket(mAddress.family(), mAddress.type(), 0); if (option == SO_NONBLOCK) { #ifdef HAVE_FCNTL @@ -404,12 +405,14 @@ public: int set(int option, const std::string& value) { + if (mFd == -1) mFd = socket(mAddress.family(), mAddress.type(), 0); return setsockopt(mFd, SOL_SOCKET, option, value.data(), value.length()); } int get(int option, int& value) { + if (mFd == -1) mFd = socket(mAddress.family(), mAddress.type(), 0); if (option == SO_NONBLOCK) { #ifdef HAVE_FCNTL @@ -425,6 +428,7 @@ public: int get(int option, std::string& value) { + if (mFd == -1) mFd = socket(mAddress.family(), mAddress.type(), 0); char str[64] = {'\0'}; socklen_t optlen = sizeof(str); int result = getsockopt(mFd, SOL_SOCKET, option, &str, &optlen); -- 2.43.0