Sha256: 9a12e726ab638ddba0c5f68822bb2e17ca2ac06bab81e36c2ef9a34f82eb7edc

Contents?: true

Size: 1.45 KB

Versions: 6

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

require 'openssl'
require_relative './socket'

# Open ssl socket helper methods (to make it compatible with Socket API)
class ::OpenSSL::SSL::SSLSocket
  def dont_linger
    io.dont_linger
  end

  def no_delay
    io.no_delay
  end

  def reuse_addr
    io.reuse_addr
  end

  alias_method :orig_accept, :accept
  def accept
    loop do
      result = accept_nonblock(exception: false)
      case result
      when :wait_readable then Thread.current.agent.wait_io(io, false)
      when :wait_writable then Thread.current.agent.wait_io(io, true)
      else
        return result
      end
    end
  end

  alias_method :orig_sysread, :sysread
  def sysread(maxlen, buf = +'')
    loop do
      case (result = read_nonblock(maxlen, buf, exception: false))
      when :wait_readable then Thread.current.agent.wait_io(io, false)
      else return result
      end
    end
  end

  alias_method :orig_syswrite, :syswrite
  def syswrite(buf)
    loop do
      case (result = write_nonblock(buf, exception: false))
      when :wait_writable then Thread.current.agent.wait_io(io, true)
      else
        return result
      end
    end
  end

  def flush
    # osync = @sync
    # @sync = true
    # do_write ""
    # return self
    # ensure
    # @sync = osync
  end

  def readpartial(maxlen, buf = +'')
    result = sysread(maxlen, buf)
    result || (raise EOFError)
  end

  def read_loop
    while (data = sysread(8192))
      yield data
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
polyphony-0.43.5 lib/polyphony/extensions/openssl.rb
polyphony-0.43.4 lib/polyphony/extensions/openssl.rb
polyphony-0.43.3 lib/polyphony/extensions/openssl.rb
polyphony-0.43.2 lib/polyphony/extensions/openssl.rb
polyphony-0.43.1 lib/polyphony/extensions/openssl.rb
polyphony-0.43 lib/polyphony/extensions/openssl.rb