From: Francis Cianfrocca Date: 2006-09-05T00:44:33+09:00 Subject: Re: problem with reading from socket ------=_Part_585_1974220.1157384669567 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 9/4/06, Hemant . wrote: > > 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? > > 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. ------=_Part_585_1974220.1157384669567--