Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Commit

Permalink
fix indentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
akrennmair committed Sep 1, 2012
1 parent 53ebfbf commit d0e890b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
28 changes: 14 additions & 14 deletions lib/m2pp.cpp
Expand Up @@ -33,7 +33,7 @@ void connection::reply_http(const request& req, const std::string& response, uin
}
httpresp << "\r\n" << response;

reply(req, httpresp.str());
reply(req, httpresp.str());
}

void connection::reply(const request& req, const std::string& response) {
Expand All @@ -51,21 +51,21 @@ void connection::reply_websocket(const request& req, const std::string& response
}

void connection::deliver(const std::string& uuid, const std::vector<std::string>& idents, const std::string& data) {
assert(idents.size() <= MAX_IDENTS);
assert(idents.size() <= MAX_IDENTS);
std::ostringstream msg;
msg << uuid << " ";
msg << uuid << " ";

size_t idents_size(idents.size()-1); // initialize with size needed for spaces
for (size_t i=0; i<idents.size(); i++) {
idents_size += idents[i].size();
}
size_t idents_size(idents.size()-1); // initialize with size needed for spaces
for (size_t i=0; i<idents.size(); i++) {
idents_size += idents[i].size();
}
msg << idents_size << ":";
for (size_t i=0; i<idents.size(); i++) {
msg << idents[i];
if (i < idents.size()-1)
msg << " ";
}
msg << ", " << data;
for (size_t i=0; i<idents.size(); i++) {
msg << idents[i];
if (i < idents.size()-1)
msg << " ";
}
msg << ", " << data;

std::string msg_str = msg.str();
zmq::message_t outmsg(msg_str.length());
Expand All @@ -74,7 +74,7 @@ void connection::deliver(const std::string& uuid, const std::vector<std::string>
}

void connection::deliver_websocket(const std::string& uuid, const std::vector<std::string>& idents, const std::string& data, char opcode, char rsvd) {
deliver(uuid, idents, utils::websocket_header(data.size(), opcode, rsvd) + data);
deliver(uuid, idents, utils::websocket_header(data.size(), opcode, rsvd) + data);
}

request request::parse(zmq::message_t& msg) {
Expand Down
6 changes: 3 additions & 3 deletions lib/m2pp.hpp
Expand Up @@ -30,9 +30,9 @@ class connection {
request recv();
void reply(const request& req, const std::string& response);
void reply_http(const request& req, const std::string& response, uint16_t code = 200, const std::string& status = "OK", std::vector<header> hdrs = std::vector<header>());
void reply_websocket(const request& req, const std::string& response, char opcode=1, char rsvd=0);
void deliver(const std::string& uuid, const std::vector<std::string>& idents, const std::string& data);
void deliver_websocket(const std::string& uuid, const std::vector<std::string>& idents, const std::string& data, char opcode=1, char rsvd=0);
void reply_websocket(const request& req, const std::string& response, char opcode=1, char rsvd=0);
void deliver(const std::string& uuid, const std::vector<std::string>& idents, const std::string& data);
void deliver_websocket(const std::string& uuid, const std::vector<std::string>& idents, const std::string& data, char opcode=1, char rsvd=0);
private:
zmq::context_t ctx;
std::string sender_id;
Expand Down
2 changes: 1 addition & 1 deletion lib/m2pp_internal.hpp
Expand Up @@ -8,7 +8,7 @@ namespace m2pp {
std::vector<std::string> split(const std::string& str, const std::string& sep, unsigned int count = 0);
std::string parse_netstring(const std::string& str, std::string& rest);
std::vector<header> parse_json(const std::string& jsondoc);
std::string websocket_header(size_t data_length, char opcode=1, char rsvd=0);
std::string websocket_header(size_t data_length, char opcode=1, char rsvd=0);

}

Expand Down
46 changes: 23 additions & 23 deletions lib/utils.cpp
Expand Up @@ -59,30 +59,30 @@ std::vector<header> parse_json(const std::string& jsondoc) {
}

std::string websocket_header(size_t data_size, char opcode, char rsvd) {
std::ostringstream header;
header.put(0x80|opcode|rsvd<<4);
char dummyLength;
size_t realLength=data_size;
if (realLength < 126) {
dummyLength = static_cast<char>(realLength);
} else if (realLength < 1<<16) {
dummyLength = 126;
std::ostringstream header;
header.put(0x80|opcode|rsvd<<4);
char dummyLength;
size_t realLength=data_size;
if (realLength < 126) {
dummyLength = static_cast<char>(realLength);
} else if (realLength < 1<<16) {
dummyLength = 126;
} else {
dummyLength = 127;
}
header.put(dummyLength);
if (dummyLength == 127) {
header.put(realLength >> 56 &0xff);
header.put(realLength >> 48 &0xff);
header.put(realLength >> 40 &0xff);
header.put(realLength >> 32 &0xff);
header.put(realLength >> 24 & 0xff);
header.put(realLength >> 16 & 0xff);
} if (dummyLength == 126 || dummyLength == 127) {
header.put(realLength >> 8 & 0xff);
header.put(realLength & 0xff);
}
return header.str();
dummyLength = 127;
}
header.put(dummyLength);
if (dummyLength == 127) {
header.put(realLength >> 56 &0xff);
header.put(realLength >> 48 &0xff);
header.put(realLength >> 40 &0xff);
header.put(realLength >> 32 &0xff);
header.put(realLength >> 24 & 0xff);
header.put(realLength >> 16 & 0xff);
} if (dummyLength == 126 || dummyLength == 127) {
header.put(realLength >> 8 & 0xff);
header.put(realLength & 0xff);
}
return header.str();
}

}
Expand Down

0 comments on commit d0e890b

Please sign in to comment.