Problem with reading from socket

I have a issue in reading from Sockets(both TCPSockets and
UNIXSockets).the
problem is with following code snippets:

begin
  timeout(8) do
    ret_data = @proxy_con.gets()
  end
rescue Timeout::Error
  return nil
rescue Exception => e
  return nil
end

The problem is, since read(or gets) from socket blocks the thread(or
process), i do a timeout on it.and return nil to the client.Now the next
time, the client puts some request, i put it to the socket and do a
gets. So
what happens is I get data for the previous request, because i guess the
socket buffer was not cleared up( or whatever name people use for this).

Can i use noblock on TCPSockets/UNIXSockets?

I guess, its a pretty basic problem, but how do i go about solving this?

On 9/4/06, Hemant . [email protected] wrote:

  return nil

what happens is I get data for the previous request, because i guess the
socket buffer was not cleared up( or whatever name people use for this).

Can i use noblock on TCPSockets/UNIXSockets?

I guess, its a pretty basic problem, but how do i go about solving this?

You can use nonblocking I/O on both TCP sockets and Unix-domain sockets.
Improved nbio APIs were added late last May and are in the current
snaps.
Obviously you have to use all the standard techniques for nbio. As a
possible alternative, look at the EventMachine library.