@@ -57,10 +57,7 @@ TCPSocket::TCPSocket() :
5757 localPort_ (-1 ),
5858 remotePort_ (-1 ),
5959 remoteAddr_ (none),
60- localAddr_ (none),
61- debug_ (false ),
62- newline_ (true ),
63- mode_ (0 ) {}
60+ localAddr_ (none) {}
6461
6562// This contructor performs a change of ownership of the socket
6663TCPSocket::TCPSocket (net::TCPSocket& other) :
@@ -70,10 +67,7 @@ TCPSocket::TCPSocket(net::TCPSocket& other) :
7067 remoteHost_ (other.remoteHost_),
7168 remoteAddr_ (other.remoteAddr_),
7269 localHost_ (other.localHost_),
73- localAddr_ (other.localAddr_),
74- debug_ (false ),
75- newline_ (true ),
76- mode_ (0 ) {
70+ localAddr_ (other.localAddr_) {
7771 other.socket_ = -1 ; // Detach socket from other
7872 other.remoteAddr_ = none;
7973 other.remoteHost_ = std::string ();
@@ -95,9 +89,7 @@ TCPSocket& TCPSocket::operator=(net::TCPSocket& other) {
9589 remoteHost_ = other.remoteHost_ ;
9690 remotePort_ = other.remotePort_ ;
9791
98- debug_ = other.debug_ ;
99- newline_ = other.newline_ ;
100- mode_ = other.mode_ ;
92+ debug_ = other.debug_ ;
10193
10294 other.socket_ = -1 ; // Detach socket from other
10395
@@ -116,7 +108,7 @@ void TCPSocket::closeInput() {
116108 SYSCALL (::shutdown (socket_, SHUT_RD));
117109}
118110
119- long TCPSocket::write (const void * buf, long length) {
111+ long TCPSocket::write (const void * buf, long length) const {
120112
121113 // Allow zero length packets
122114 if (length == 0 ) {
@@ -125,20 +117,20 @@ long TCPSocket::write(const void* buf, long length) {
125117
126118 long requested = length;
127119
128- if (debug_) {
120+ if (debug_. on ) {
129121
130- if (mode_ != ' w' ) {
131- newline_ = true ;
122+ if (debug_. mode != ' w' ) {
123+ debug_. newline = true ;
132124 std::cout << std::endl
133125 << std::endl;
134- mode_ = ' w' ;
126+ debug_. mode = ' w' ;
135127 }
136128
137129 const char * p = reinterpret_cast <const char *>(buf);
138130 for (long i = 0 ; i < std::min (length, 512L ); i++) {
139- if (newline_ ) {
131+ if (debug_. newline ) {
140132 std::cout << " >>> " ;
141- newline_ = false ;
133+ debug_. newline = false ;
142134 }
143135
144136 if (p[i] == ' \r ' ) {
@@ -147,7 +139,7 @@ long TCPSocket::write(const void* buf, long length) {
147139 else if (p[i] == ' \n ' ) {
148140 std::cout << " \\ n"
149141 << std::endl;
150- newline_ = true ;
142+ debug_. newline = true ;
151143 }
152144 else {
153145 std::cout << (isprint (p[i]) ? p[i] : ' .' );
@@ -156,7 +148,7 @@ long TCPSocket::write(const void* buf, long length) {
156148
157149 if (length > 512 ) {
158150 std::cout << " ..." << std::endl;
159- newline_ = true ;
151+ debug_. newline = true ;
160152 }
161153 }
162154
@@ -206,7 +198,7 @@ long TCPSocket::write(const void* buf, long length) {
206198 return sent;
207199}
208200
209- long TCPSocket::read (void * buf, long length) {
201+ long TCPSocket::read (void * buf, long length) const {
210202 if (length <= 0 ) {
211203 return length;
212204 }
@@ -270,19 +262,19 @@ long TCPSocket::read(void* buf, long length) {
270262 return received;
271263 }
272264
273- if (debug_) {
265+ if (debug_. on ) {
274266
275- if (mode_ != ' r' ) {
276- newline_ = true ;
267+ if (debug_. mode != ' r' ) {
268+ debug_. newline = true ;
277269 std::cout << std::endl
278270 << std::endl;
279- mode_ = ' r' ;
271+ debug_. mode = ' r' ;
280272 }
281273
282274 for (long i = 0 ; i < std::min (len, 512L ); i++) {
283- if (newline_ ) {
275+ if (debug_. newline ) {
284276 std::cout << " <<< " ;
285- newline_ = false ;
277+ debug_. newline = false ;
286278 }
287279
288280 if (p[i] == ' \r ' ) {
@@ -291,7 +283,7 @@ long TCPSocket::read(void* buf, long length) {
291283 else if (p[i] == ' \n ' ) {
292284 std::cout << " \\ n"
293285 << std::endl;
294- newline_ = true ;
286+ debug_. newline = true ;
295287 }
296288 else {
297289 std::cout << (isprint (p[i]) ? p[i] : ' .' );
@@ -300,11 +292,10 @@ long TCPSocket::read(void* buf, long length) {
300292
301293 if (len > 512 ) {
302294 std::cout << " ..." << std::endl;
303- newline_ = true ;
295+ debug_. newline = true ;
304296 }
305297 }
306298
307-
308299 received += len;
309300 length -= len;
310301 p += len;
@@ -810,9 +801,9 @@ bool TCPSocket::stillConnected() const {
810801}
811802
812803void TCPSocket::debug (bool on) {
813- debug_ = on;
814- newline_ = true ;
815- mode_ = 0 ;
804+ debug_. on = on;
805+ debug_. newline = true ;
806+ debug_. mode = 0 ;
816807}
817808
818809void TCPSocket::print (std::ostream& s) const {
0 commit comments