【发布时间】:2010-09-10 17:56:32
【问题描述】:
我正在尝试通过 ruby 中的套接字读取 HTTP 数据包,由于某种原因,我的代码在调用 recv 时一直处于阻塞状态
socket = TCPSocket.new("localhost",80)
socket.send r.join("\r\n"), 0
socket.flush
#We're only interested in the string "HTTP/1.1 XXX"
if http_status = get_http_status(socket.recv_nonblock(12))
if http_status == 200
$logger.info "Wrote #{message_packet}"
else
$logger.warn "Resubmitting message because #{line} is not 200"
@queue.publish(message)
end
end
#Get rid of the rest of the content
the_rest = socket.recv(1000)
while(the_rest != "") do
the_rest = socket.recv(1000)
end
根据我对recv 的理解,如果套接字上没有等待数据,它应该什么都不返回?
【问题讨论】:
-
这个问题写得非常糟糕,并且遗漏了一些非常重要的数据,这些数据实际上使这个问题变得有意义。代码也是错误的。请关闭它。
标签: ruby multithreading sockets