# Weird extension behavior

**URL:** <https://www.ruby-forum.com/t/weird-extension-behavior/61452>\
**Category:** Ruby\
**Created:** [May 24, 2006, 4:15am UTC](https://www.ruby-forum.com/t/weird-extension-behavior/61452 "2006-05-24T04:15:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Krahmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@Brian\_Krahmer](https://www.ruby-forum.com/u/Brian_Krahmer)\
**Post date:** [May 24, 2006, 4:15am UTC](https://www.ruby-forum.com/t/weird-extension-behavior/61452/1 "2006-05-24T04:15:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Brian\_Krahmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@Brian\_Krahmer](https://www.ruby-forum.com/u/Brian_Krahmer)\
**Post date:** [May 29, 2006, 5:21pm UTC](https://www.ruby-forum.com/t/weird-extension-behavior/61452/2 "2006-05-29T17:21:25Z")

</div>

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.
