Class: Baykit::BayServer::Util::IOUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/baykit/bayserver/util/io_util.rb

Class Method Summary collapse

Class Method Details

.get_sock_recv_buf_size(skt) ⇒ Object



26
27
28
# File 'lib/baykit/bayserver/util/io_util.rb', line 26

def IOUtil.get_sock_recv_buf_size(skt)
  return skt.getsockopt(Socket::SOL_SOCKET, Socket::SO_RCVBUF).int
end

.read_int32(io) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/baykit/bayserver/util/io_util.rb', line 5

def IOUtil.read_int32(io)
  data = "    "
  begin
    dt = io.read_nonblock(4, data)
    if dt == nil
      return nil
    end
  rescue EOFError => e
    return nil
  end
  data = data.codepoints
  #print("IO.read->" + data[0].to_s + "," + data[1].to_s + "," + data[2].to_s + "," + data[3].to_s)
  return data[0] << 24 | (data[1]<< 16 & 0xFF0000) | (data[2] << 8 & 0xFF00) | (data[3] & 0xFF)
end

.write_int32(io, i) ⇒ Object



20
21
22
23
24
# File 'lib/baykit/bayserver/util/io_util.rb', line 20

def IOUtil.write_int32(io, i)
  data = [i >> 24, i >> 16 & 0xFF, i >> 8 & 0xFF, i & 0xFF]
  #print("IOwrite->" + data.to_s)
  io.write(data.pack("C*"))
end