Forum: Ruby Weird extension behavior

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Brian Krahmer (Guest)
on 2006-05-24 06:15
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.
unknown (Guest)
on 2006-05-29 19:21
(Received via mailing list)
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.
This topic is locked and can not be replied to.