Close socket

The socket is never closed.

And "stream_set_timeout" function is moved (see #12)