class DbgProtocol

Public Class Methods

new(host='127.0.0.1', port='9000') click to toggle source
# File lib/ruby-xdebug/protocol.rb, line 3
def initialize(host='127.0.0.1', port='9000')
    server = TCPServer.new(host, port)
    @sock = server.accept
    recv_msg
end

Public Instance Methods

recv_length() click to toggle source
# File lib/ruby-xdebug/protocol.rb, line 9
def recv_length
    length = ''
    loop {
        c = @sock.recv(1)
        if c == ''
            @sock.close
            raise 'Socket Closed'
        elsif c == "\x00"
            break
        elsif c.to_i.to_s == c
            length = length + c
        end
    }
    length.to_i
end
recv_msg() click to toggle source
# File lib/ruby-xdebug/protocol.rb, line 37
def recv_msg
    body = ''
    to_recv = recv_length
    while to_recv > 0
        buf = @sock.recv(to_recv)
        to_recv = to_recv - buf.length
        body = body + buf
    end
    recv_null
    body
end
recv_null() click to toggle source
# File lib/ruby-xdebug/protocol.rb, line 25
def recv_null
    loop {
        c = @sock.recv(1)
        if c == ''
            @sock.close
            raise 'Socket Closed'
        elsif c == "\x00"
            break
        end
    }
end
send_msg(cmd) click to toggle source
# File lib/ruby-xdebug/protocol.rb, line 49
def send_msg(cmd)
    @sock.send cmd + "\x00", 0
end