Fail* directories reorganized, Code-cleanup (-> coding-style), Typos+comments fixed.

git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1321 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
adrian
2012-06-08 20:09:43 +00:00
parent d474a5b952
commit 2575604b41
866 changed files with 1848 additions and 1879 deletions

View File

@ -0,0 +1,52 @@
#include <string>
#include "SocketComm.hpp"
namespace fail {
bool SocketComm::sendMsg(int sockfd, google::protobuf::Message& msg)
{
#ifdef USE_SIZE_PREFIX
int size = htonl(msg.ByteSize());
if (write(sockfd, &size, sizeof(size)) != sizeof(size)) {
return false;
}
std::string buf;
msg.SerializeToString(&buf);
if (write(sockfd, buf.c_str(), buf.size()) != (ssize_t) buf.size()) {
return false;
}
#else
char c = 0;
if (!msg.SerializeToFileDescriptor(sockfd) || write(sockfd, &c, 1) != 1) {
return false;
}
#endif
return true;
}
bool SocketComm::rcvMsg(int sockfd, google::protobuf::Message& msg)
{
#ifdef USE_SIZE_PREFIX
int size;
// FIXME: read() may need to be called multiple times until all data was read
if (read(sockfd, &size, sizeof(size)) != sizeof(size)) {
return false;
}
size = ntohl(size);
char *buf = new char[size];
// FIXME: read() may need to be called multiple times until all data was read
if (read(sockfd, buf, size) != size) {
delete [] buf;
return false;
}
std::string st(buf, size);
delete [] buf;
msg.ParseFromString(st);
return true;
#else
return msg.ParseFromFileDescriptor(sockfd);
#endif
}
} // end-of-namespace: fail