我正在尝试从
Ruby的UNIX套接字连接,读取和写入.它是由haproxy使用的统计套接字.
我的代码如下:
require 'socket' socket = UNIXSocket.new("/tmp/haproxy.stats.socket") # First attempt: works socket.puts("show stat") while(line = socket.gets) do puts line end # Second attemp: fails socket.puts("show stat") while(line = socket.gets) do puts line end
它第一次成功,但第二次尝试失败.我不知道为什么
# pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,dresp,ereq,econ,eresp,wretr,wredis,status,weight,act,bck,chkfail,chkdown,lastchg,downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,type,rate,rate_lim,rate_max,check_status,check_code,check_duration,hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,req_rate,req_rate_max,req_tot,cli_abrt,srv_abrt,stats,FRONTEND,2000,OPEN,1,BACKEND,UP,22,legacy_socket,1000,2,all,10000,3,socket_backend,socket,200,DOWN,4,L4CON,5,6,7,21,8,9,10,api_backend,api,L4OK,www_backend,ruby-www,/Users/Olly/Desktop/haproxy_stats.rb:14:in `write': Broken pipe (Errno::EPIPE) from /Users/Olly/Desktop/haproxy_stats.rb:14:in `puts' from /Users/Olly/Desktop/haproxy_stats.rb:14
问题是什么?有没有很好的参考使用UNIX套接字和Ruby?