Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Socket oddities

Moderators: kris

Posted: 05/10/08 00:07:08

I have some code that involves writing to sockets. I was getting no output, so I put in some print statements to make sure the right methods were being called. I wasn't getting any output from those debug Stdouts, so I added a flush() statement for each call to Stdout.

Suddenly I was getting socket output! And also output on stdout. I removed all the Stdout statements and the socket output disappeared.

What's more confusing, I only got socket output if I had one of these Stdout calls _before_ writing to the socket. (And flushing the socket didn't help.)

For now, I have a workaround of preceding my socket writes with Stdout.flush(); but that's ugly. Any ideas what might be going wrong? (I'm on Linux, dmd1.029, tango 0.99.5.)

Author Message

Posted: 05/10/08 02:52:48

wow, that sounds very strange ... you do have to flush all buffered streams in order to clear out the buffered data (and most wrapped streams in Tango are buffered -- talking directly to a Conduit instance is unbuffered), but there's no known correlation between Stdout and other streams.

BTW, the only stream that does not have to be explicitly flushed is Stdout itself, and only when it is attached to a console. If you redirect the console, then Stdout does not auto-flush either. Yes, we hate special-cases also, but people seem to expect Stdout to auto-flush for one reason or another (when attached to a console). The reason Stdout does not auto-flush when redirected is that people complained bitterly about Stdout being slow when redirected. However, none of this should have any bearing on your socket streams ... as long as you flush the output of your streams they should be just fine :)

Posted: 05/11/08 03:17:27

The issue is rather hard to track down -- if I make random changes, then I stop getting output until I add some output on stdout. I'm flushing the sockets whenever I write to them. So I really have no idea what's going on.

Posted: 05/11/08 07:23:20

Are you able to trace or breakpoint in a debugger?