Method: TCPSocket#readpartial

Defined in:
lib/polyphony/extensions/socket.rb

#readpartial(maxlen, buf = +'',, buffer_pos = 0, raise_on_eof = true) ⇒ String?

Reads up to maxlen from the socket. If buf is given, it is used as the buffer to read into, otherwise a new string is allocated. If buffer_pos is given, reads into the given offset (in bytes) in the given buffer. If the given buffer offset is negative, it is calculated from the current end of the buffer (-1 means the read data will be appended to the end of the buffer). If raise_on_eof is true (the default,) an EOFError will be raised on EOF, otherwise nil will be returned.

If no bytes are available and EOF is not hit, this method will block until the socket is ready to read from.

Parameters:

  • maxlen (Integer, nil)

    maximum bytes to read from socket

  • buf (String, nil) (defaults to: +'',)

    buffer to read into

  • buffer_pos (Number) (defaults to: 0)

    buffer position to read into

  • raise_on_eof (bool) (defaults to: true)

    whether to raise an exception on EOF

Returns:

  • (String, nil)

    buffer used for reading or nil on EOF

Raises:

  • (EOFError)


409
410
411
412
413
414
# File 'lib/polyphony/extensions/socket.rb', line 409

def readpartial(maxlen, buf = +'', buffer_pos = 0, raise_on_eof = true)
  result = Polyphony.backend_recv(self, buf, maxlen, buffer_pos)
  raise EOFError if !result && raise_on_eof

  result
end