Permalink
Browse files

Fixed initializtion bug in socketbuf.

Added disabled debugging output.
  • Loading branch information...
1 parent 03f8856 commit df46bc2cbe187e8d49346f7b3026ed1e7b9206ea Gulevich Vasili committed Mar 6, 2012
Showing with 22 additions and 7 deletions.
  1. +2 −6 include/socketbuf.h
  2. +20 −1 src/socketbuf.cpp
View
@@ -43,7 +43,7 @@ class socketbuf: public std::basic_streambuf<_CharT>, public socketwrapper {
public:
socketbuf(const Host & host, int port):
socketwrapper(host, port) {
- setg(_iBuffer, _iBuffer, _iBuffer+BUFFER_SIZE);
+ setg(_iBuffer, _iBuffer+BUFFER_SIZE, _iBuffer+BUFFER_SIZE);
setp(_oBuffer, _oBuffer+BUFFER_SIZE-1);
}
virtual ~socketbuf() {}
@@ -102,11 +102,7 @@ class socketbuf: public std::basic_streambuf<_CharT>, public socketwrapper {
}
int_type overflow(int_type c) {
- char_type * begin=this->pbase(),* current=this->pptr(),* end=this->epptr();
- assert(begin>=_oBuffer);
- assert(end<=_oBuffer+BUFFER_SIZE-1);
- assert(current>=begin);
- assert(current<=end);
+ char_type * current=this->pptr();
*current=traits_type::to_char_type(c); //We can write there as current is still not greater than _oBuffer+BUFFER_SIZE-1
return writeChars(_oBuffer-current+1);
}
View
@@ -15,6 +15,10 @@
#include <errno.h>
#include <unistd.h>
+#include <iostream>
+#include <iomanip>
+using namespace std;
+
//int fdescwrapper::read(char * oBuffer, int length) {
// if (_fd<0) {return 0;}
// return ::read(_fd, oBuffer, length);
@@ -169,10 +173,25 @@ socketwrapper::Error socketwrapper::connect() {
}
return UNKNOWN_CONNECT_ERROR;
}
+inline void dump(ostream & str, char * data, int size, const string & title) {
+ return;
+ if (size < 0) {
+ str << "Socket returned negative value" << endl;
+ return;
+ }
+ str << title << ":";
+ for (int i = 0; i < size; i++)
+ str << hex << (unsigned(0xFF) & unsigned(data[i])) << " ";
+ str << dec;
+ str << endl;
+}
+
int socketwrapper::read(char * oBuffer, int length) {
if (!isConnected()) return 0;
- return ::read(socket(), oBuffer, length);
+ int rv = ::read(socket(), oBuffer, length);
+ dump(cerr, oBuffer, length, "low level read");
+ return rv;
}
int socketwrapper::write(const char * iBuffer, int length) {

0 comments on commit df46bc2

Please sign in to comment.