lib/thrift/transport/socket.rb in evernote-thrift-1.23.0 vs lib/thrift/transport/socket.rb in evernote-thrift-1.23.1
- old
+ new
@@ -32,12 +32,13 @@
attr_accessor :handle, :timeout
def open
begin
- addrinfo = ::Socket::getaddrinfo(@host, @port).first
+ addrinfo = ::Socket::getaddrinfo(@host, @port, nil, ::Socket::SOCK_STREAM).first
@handle = ::Socket.new(addrinfo[4], ::Socket::SOCK_STREAM, 0)
+ @handle.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
sockaddr = ::Socket.sockaddr_in(addrinfo[1], addrinfo[3])
begin
@handle.connect_nonblock(sockaddr)
rescue Errno::EINPROGRESS
unless IO.select(nil, [ @handle ], nil, @timeout)
@@ -58,10 +59,11 @@
!@handle.nil? and !@handle.closed?
end
def write(str)
raise IOError, "closed stream" unless open?
+ str = Bytes.force_binary_encoding(str)
begin
if @timeout.nil? or @timeout == 0
@handle.write(str)
else
len = 0
@@ -132,6 +134,6 @@
def to_io
@handle
end
end
-end
\ No newline at end of file
+end