class QRubyDriver::QConnection

Public Class Methods

new(host="localhost", port=3000, username = ENV['USER']) click to toggle source

Initializes the connection

# File lib/q-ruby-driver/q_connection.rb, line 9
def initialize(host="localhost", port=3000, username = ENV['USER'])
  @client_socket = TCPSocket.new(host, port)
  @client_socket.write [username, "001"].pack("a*H")
  @client_socket.recv(4).unpack("H*")
end

Public Instance Methods

close() click to toggle source

Closes the connection

# File lib/q-ruby-driver/q_connection.rb, line 45
def close
  @client_socket.close
end
execute(obj)
Alias for: get
get(obj) click to toggle source

Sync Send

# File lib/q-ruby-driver/q_connection.rb, line 16
def get(obj)
  write_to_socket(obj, true)
  read_from_socket()
end
Also aliased as: execute
send_raw(raw_message, sync=true) click to toggle source

Takes a hex encoded representation of the message to send

# File lib/q-ruby-driver/q_connection.rb, line 28
def send_raw(raw_message, sync=true)
  encoded_message = [raw_message].pack("H*")
  @client_socket.write encoded_message

  if (encoded_message[1] == 1)
    read_from_socket()
  else
    nil
  end
end
set(obj) click to toggle source

ASync send

# File lib/q-ruby-driver/q_connection.rb, line 23
def set(obj)
  write_to_socket(obj, false)
end
table_info(table_name) click to toggle source

Dumps table schema

# File lib/q-ruby-driver/q_connection.rb, line 40
def table_info(table_name)
  get("meta #{table_name}")
end

Private Instance Methods

buffered_recv() click to toggle source
# File lib/q-ruby-driver/q_connection.rb, line 63
def buffered_recv()
  # peek at the total message length
  peek = @client_socket.recvfrom(8, Socket::MSG_PEEK)
  length = QIO.new(peek[0]).read_message_header[0]

  # read up to full message length
  qio = QIO.new()
  while qio.length < length
    qio.write @client_socket.recvfrom(@@BUFFER_SIZE)[0]
  end
  qio.pos=0
  return qio
end
read_from_socket() click to toggle source
# File lib/q-ruby-driver/q_connection.rb, line 58
def read_from_socket()
  qio = buffered_recv()
  qio.read_message
end
write_to_socket(obj, sync=true) click to toggle source
# File lib/q-ruby-driver/q_connection.rb, line 51
def write_to_socket(obj, sync=true)
  qio = QIO.new
  qio.write_message(obj, sync ? :sync : :async)
  qio.pos=0
  @client_socket.write qio.read
end