cubemap
*.o
*.d
+*.pb.cc
+*.pb.h
CC=gcc
CXX=g++
+PROTOC=protoc
CXXFLAGS=-Wall -O2 -g
-LDLIBS=-lcurl -lpthread
+LDLIBS=-lcurl -lpthread -lprotobuf
-OBJS=cubemap.o server.o mutexlock.o input.o
+OBJS=cubemap.o server.o mutexlock.o input.o state.pb.o
all: cubemap
+%.pb.cc %.pb.h : %.proto
+ $(PROTOC) --cpp_out=. $<
+
%.o: %.cpp
$(CXX) -MMD -MP $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $<
cubemap: $(OBJS)
#include "metacube.h"
#include "server.h"
#include "mutexlock.h"
+#include "state.pb.h"
using namespace std;
{
request.reserve(1024);
}
+
+Client::Client(const ClientProto &serialized)
+ : sock(serialized.sock()),
+ state(State(serialized.state())),
+ request(serialized.request()),
+ stream_id(serialized.stream_id()),
+ header(serialized.header()),
+ header_bytes_sent(serialized.header_bytes_sent()),
+ bytes_sent(serialized.bytes_sent())
+{
+}
+
+ClientProto Client::serialize() const
+{
+ ClientProto serialized;
+ serialized.set_sock(sock);
+ serialized.set_state(state);
+ serialized.set_request(request);
+ serialized.set_stream_id(stream_id);
+ serialized.set_header(header);
+ serialized.set_header_bytes_sent(serialized.header_bytes_sent());
+ serialized.set_bytes_sent(bytes_sent);
+ return serialized;
+}
Server::Server()
{
#define EPOLL_TIMEOUT_MS 20
#define MAX_CLIENT_REQUEST 16384
+class ClientProto;
+
struct Client {
Client() {}
Client(int sock);
+ // Serialization/deserialization.
+ Client(const ClientProto &serialized);
+ ClientProto serialize() const;
+
// The file descriptor associated with this socket.
int sock;
--- /dev/null
+// Corresponds to struct Client.
+message ClientProto {
+ optional int32 sock = 1;
+ optional int32 state = 2;
+ optional bytes request = 3;
+ optional string stream_id = 4;
+ optional bytes header = 5;
+ optional int64 header_bytes_sent = 6;
+ optional int64 bytes_sent = 7;
+};
+
+// Corresponds to struct Stream.
+message StreamProto {
+ optional bytes header = 1;
+ optional bytes data = 2;
+ optional int64 data_size = 3;
+};
+
+message CubemapStateProto {
+ repeated ClientProto clients = 1;
+ repeated StreamProto streams = 2;
+};