I'm writing my first extension, which has some low-level networking functions to interface with some legacy code. I have two functions in the extension, send, and recv_line, which work with a socket. I'm testing with ruby 1.8.4 on debian using the echo service (port 7). As a debugging measure, I had the following code, which works perfectly: puts socket.send("hello\n") puts socket.recv_line() If I take the return from the send and place it in a variable, the code takes exactly three seconds to run, as opposed to nearly instantly: foo = socket.send("hello\n") puts socket.recv_line() This causes it to hang forever: socket.send("hello\n") puts socket.recv_line() Using strace shows that recv_line is getting the hello, but never receives the newline character. I'm completely baffled. I can post the C code, but it doesn't seem like it would necessarily be the source of the problem. Any input would be greatly appreciated. Thanks.
on 2006-05-24 04:15
on 2006-05-29 17:21
Hi, At Wed, 24 May 2006 11:16:03 +0900, Brian Krahmer wrote in [ruby-talk:194295]: > socket.send("hello\n") > puts socket.recv_line() Some possibilities around puts. 1) it flushes stdout, and it might take effect about buffering. 2) it calls its argument's #to_s method.