[svn] commit: r398 - /branches/parkinglot/src/lib/cc/cpp/session.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Dec 22 13:54:57 UTC 2009
Author: jelte
Date: Tue Dec 22 13:54:57 2009
New Revision: 398
Log:
fixed some en/decoding bugs in the cpp part of the new cc wire format
Modified:
branches/parkinglot/src/lib/cc/cpp/session.cc
Modified: branches/parkinglot/src/lib/cc/cpp/session.cc
==============================================================================
--- branches/parkinglot/src/lib/cc/cpp/session.cc (original)
+++ branches/parkinglot/src/lib/cc/cpp/session.cc Tue Dec 22 13:54:57 2009
@@ -57,8 +57,8 @@
ElementPtr get_lname_msg = Element::create_from_string(get_lname_stream);
sendmsg(get_lname_msg);
- ElementPtr msg;
- recvmsg(msg, false);
+ ElementPtr routing, msg;
+ recvmsg(routing, msg, false);
lname = msg->get("lname")->string_value();
cout << "My local name is: " << lname << endl;
@@ -70,10 +70,11 @@
void
Session::sendmsg(ElementPtr& msg)
{
- std::string wire = msg->to_wire();
- unsigned int length = wire.length();
+ std::string header_wire = msg->to_wire();
+ unsigned int length = 2 + header_wire.length();
unsigned int length_net = htonl(length);
- unsigned short header_length_net = htons(length);
+ unsigned short header_length = header_wire.length();
+ unsigned short header_length_net = htons(header_length);
unsigned int ret;
ret = write(sock, &length_net, 4);
@@ -84,9 +85,10 @@
if (ret != 2)
throw SessionError("Short write");
- ret = write(sock, wire.c_str(), length);
- if (ret != length)
- throw SessionError("Short write");
+ ret = write(sock, header_wire.c_str(), header_length);
+ if (ret != header_length) {
+ throw SessionError("Short write");
+ }
}
void
@@ -108,12 +110,14 @@
if (ret != 2)
throw SessionError("Short write");
- std::cout << "[XX] Header length sending: " << header_length << std::endl;
-
ret = write(sock, header_wire.c_str(), header_length);
+ if (ret != header_length) {
+ throw SessionError("Short write");
+ }
ret = write(sock, body_wire.c_str(), body_wire.length());
- if (ret != length)
- throw SessionError("Short write");
+ if (ret != body_wire.length()) {
+ throw SessionError("Short write");
+ }
}
bool
@@ -171,23 +175,24 @@
unsigned int length = ntohl(length_net);
unsigned short header_length = ntohs(header_length_net);
-
if (header_length > length)
throw SessionError("Bad header length");
-
+
+ // remove the header-length bytes from the total length
+ length -= 2;
char *buffer = new char[length];
ret = read(sock, buffer, length);
if (ret != length)
throw SessionError("Short read");
std::string header_wire = std::string(buffer, header_length);
- std::string body_wire = std::string(buffer, length - header_length);
+ std::string body_wire = std::string(buffer + header_length, length - header_length);
delete [] buffer;
std::stringstream header_wire_stream;
header_wire_stream << header_wire;
- env = Element::from_wire(header_wire_stream, length);
-
+ env = Element::from_wire(header_wire_stream, header_length);
+
std::stringstream body_wire_stream;
body_wire_stream << body_wire;
msg = Element::from_wire(body_wire_stream, length - header_length);
More information about the bind10-changes
mailing list