Files
fail/core/jobserver/SocketComm.cc
hsc b70b6fb43a another directory rename: failstar -> fail
"failstar" sounds like a name for a cruise liner from the 80s.  As "*" isn't a
desirable part of directory names, just name the whole thing "fail/", the core
parts being stored in "fail/core/".

Additionally fixing two build system dependency issues:
 - missing jobserver -> protomessages dependency
 - broken bochs -> fail dependency (add_custom_target DEPENDS only allows plain
   file dependencies ... cmake for the win)


git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@956 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
2012-03-08 19:43:02 +00:00

50 lines
1.2 KiB
C++

#include "SocketComm.hpp"
namespace fi {
bool SocketComm::send_msg(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::rcv_msg(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
}
}