mirror of
https://github.com/vidarh/ruby-x11
synced 2024-12-26 09:59:02 +01:00
Use current Form module instead of obsolete Packet module; better error handling
This commit is contained in:
parent
09266ec3a2
commit
8023e81c24
1 changed files with 7 additions and 4 deletions
|
@ -50,7 +50,7 @@ module X11
|
||||||
auth_info = Auth.new.get_by_hostname(host||"localhost", family, display_id)
|
auth_info = Auth.new.get_by_hostname(host||"localhost", family, display_id)
|
||||||
auth_name, auth_data = auth_info.address, auth_info.auth_data
|
auth_name, auth_data = auth_info.address, auth_info.auth_data
|
||||||
|
|
||||||
handshake = Packet::ClientHandshake.create(
|
handshake = Form::ClientHandshake.new(
|
||||||
Protocol::BYTE_ORDER,
|
Protocol::BYTE_ORDER,
|
||||||
Protocol::MAJOR,
|
Protocol::MAJOR,
|
||||||
Protocol::MINOR,
|
Protocol::MINOR,
|
||||||
|
@ -58,9 +58,12 @@ module X11
|
||||||
auth_data
|
auth_data
|
||||||
)
|
)
|
||||||
|
|
||||||
@socket.write(handshake)
|
@socket.write(handshake.to_packet)
|
||||||
|
|
||||||
case @socket.read(1).unpack("w").first
|
data = @socket.read(1)
|
||||||
|
raise AuthorizationError, "Failed to read response from server" if !data
|
||||||
|
|
||||||
|
case data.unpack("w").first
|
||||||
when X11::Auth::FAILED
|
when X11::Auth::FAILED
|
||||||
len, major, minor, xlen = @socket.read(7).unpack("CSSS")
|
len, major, minor, xlen = @socket.read(7).unpack("CSSS")
|
||||||
reason = @socket.read(xlen * 4)
|
reason = @socket.read(xlen * 4)
|
||||||
|
@ -70,7 +73,7 @@ module X11
|
||||||
raise AuthorizationError, "Connection requires authentication"
|
raise AuthorizationError, "Connection requires authentication"
|
||||||
when X11::Auth::SUCCESS
|
when X11::Auth::SUCCESS
|
||||||
@socket.read(7) # skip unused bytes
|
@socket.read(7) # skip unused bytes
|
||||||
@internal = Packet::DisplayInfo.read(@socket)
|
@internal = Form::DisplayInfo.from_packet(@socket)
|
||||||
else
|
else
|
||||||
raise AuthorizationError, "Received unknown opcode #{type}"
|
raise AuthorizationError, "Received unknown opcode #{type}"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue