Skip to content
This repository has been archived by the owner on Jan 11, 2019. It is now read-only.

Commit

Permalink
Fix issues with nbstream::tobuf()
Browse files Browse the repository at this point in the history
  • Loading branch information
stmobo committed Feb 10, 2016
1 parent d762c56 commit bacd2e1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions server_src/netmsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int netmsg::recv(int socket, unsigned int flags) {
netlen = -1;

if(socktype == SOCK_DGRAM) {
std::cout << "doing recvfrom()" << std::endl;
//std::cout << "doing recvfrom()" << std::endl;
if((netlen = recvfrom(socket,
data.get(),
buflen,
Expand All @@ -75,7 +75,7 @@ int netmsg::recv(int socket, unsigned int flags) {
strerror(netlen) << std::endl;
}
} else if(socktype == SOCK_STREAM) {
std::cout << "doing recv()" << std::endl;
//std::cout << "doing recv()" << std::endl;
if((netlen = ::recv(socket,
static_cast<void*>(data.get()),
buflen,
Expand Down
8 changes: 4 additions & 4 deletions server_src/network_bytestream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ uint64_t netorder64(uint64_t *in) {
}

std::shared_ptr<unsigned char> nbstream::tobuf() {
std::shared_ptr<unsigned char> data(new unsigned char[this->buf.size()]);
unsigned char* dbuf = new unsigned char[this->buf.size()];
size_t i = 0;
for(auto &e : this->buf) {
data.get()[i] = e;
dbuf[i++] = e;
}
return data;
return std::shared_ptr<unsigned char>(dbuf);
}

/* ========================================================================= */
Expand Down Expand Up @@ -95,7 +95,7 @@ double nbstream::getDouble() {
/* ========================================================================= */

void nbstream::put8(uint8_t b) {
*this->cur++ = (unsigned char)b;
this->buf.push_back((unsigned char)b);
}

void nbstream::put16(uint16_t s) {
Expand Down
2 changes: 1 addition & 1 deletion server_src/sockwrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ netmsg connSocket::recv(size_t bufsz, int flags) {

netmsg connSocket::recv(int flags) {
netmsg out(default_buflen, SOCK_STREAM);
std::cout << "made netmsg object" << std::endl;
//std::cout << "made netmsg object" << std::endl;
out.recv(fd, flags);
return out;
}
Expand Down
11 changes: 7 additions & 4 deletions server_src/test_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const int connType = SOCK_STREAM;

int main() {
serverSocket listenSock(serverPort, connType);
std::cout << "Listening." << std::endl;
std::cout << "Listening on " << (std::string)listenSock.getbindaddr() << std::endl;

while(true) {
connSocket dataSock = listenSock.waitForConnection();
Expand All @@ -20,16 +20,19 @@ int main() {
std::cout << "Got connection from " << (std::string)addr << std::endl;
while(true) {
netmsg msg = dataSock.recv();
std::cout << "Got data!" << std::endl;
//std::cout << "Got data!" << std::endl;

nbstream data = nbstream(msg);

std::string dataStr = data.getNullTermString();
std::cout << "[data]: " << dataStr << std::endl;


nbstream replydata;
replydata.putNullTermString(dataStr);

std::cout << "[data]: " << dataStr << " (" << replydata.getbufsz() << " bytes) " << std::endl;;

//std::cout << "Reply created." << std::endl;

netmsg reply(replydata.tobuf(), replydata.getbufsz(), SOCK_STREAM);

dataSock.send(reply);
Expand Down

0 comments on commit bacd2e1

Please sign in to comment.