c++ - C/pp Sockets, recv()/send() works only under gdb -


Edit: In the socket: The CanReceive () argument was the reason I was checking the input 1 millisecond While stepping into GDB, everything worked out.

I have a problem with C sock send () / recv () do nothing if they are in non-debug mode. Even if std :: cout can not return their return value for some reason std :: cout is not working in my method I std: : Cerr can not even make a mistake It does not make sense to check that in GDB, because everything works perfectly as a virus in non-debug mode. C does not.

  //b - buffer // s - size // sd - socket descriptor int32_t TCP :: reception (char * b, uint32_t s) {error :: critical. SetErrorNumber (error: List :: noor); If (! Socket :: valid (sd)) {error :: serious .sitemember (error :: list :: invalid socket); Return -1; } If (Disconnect ()) {Error :: Critical. SetErrorNumber (Error :: List :: Notepanked); Return -1; } If returned (! Socket :: canvasive (SD, readtimeout)) incorrect; If (! B) {B = new four [S + 1]; Std :: memset (b, '\ 0', s + 1); } Int32_t bytes = RQV (SD, B, S, 0); If (bytes == -1) {error: critical. SetErrorNumber (wrong); Std :: cerr & lt; & Lt; Wrong & lt; & Lt; "\ N"; return false; } Std :: cout & lt; & Lt; Bytes; Return bytes; }  

The interesting fact is that without step, GDB also fails if I do not set a breakpoint in this method, then it fails and nothing logs. I thought it might be an issue over time, so there is no time to answer the server, but what does it feel? So () does not work in both ways I'm not sending TCP :: Send () , because it is the only line of difference.

You are not flushing the stream, so you are not seeing the output. Change:

  std :: cerr & lt; & Lt; Wrong & lt; & Lt; "\ N";  

to

  std :: cerr & lt; & Lt; Wrong & lt; & Lt; Std :: endl;  

and

  std :: cout & lt; & Lt; Bytes;  

to

  std :: cout & lt; & Lt; Bytes & lt; & Lt; Std :: endl;  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -