mirror of
https://github.com/vidarh/ruby-x11
synced 2024-12-26 09:59:02 +01:00
added error/exception classes for better handling
This commit is contained in:
parent
a6999815de
commit
11ac2cd2c6
3 changed files with 22 additions and 4 deletions
|
@ -10,4 +10,7 @@ module X11
|
|||
# of 4 bytes. For instance, C<pack(padded('Hello'), 'Hello')> gives
|
||||
# C<"Hello\0\0\0">.
|
||||
def self.pad(x); x + "\0"*(-x.length & 3); end
|
||||
|
||||
class X11Error < StandardError; end
|
||||
class X11Exception < RuntimeException; end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,15 @@
|
|||
module X11
|
||||
|
||||
class DisplayException < X11Exception; end
|
||||
class ConnectionException < DisplayException; end
|
||||
class AuthorizationException < ConnectionException
|
||||
attr_reader :errorcode
|
||||
def initialize msg, errcode=nil
|
||||
super msg
|
||||
@errorcode = errcode
|
||||
end
|
||||
end
|
||||
|
||||
class Display
|
||||
|
||||
# Open a connection to the specified display (numbered from 0) on the specified host
|
||||
|
@ -49,13 +60,13 @@ private
|
|||
len, major, minor, xlen = @socket.read(7).unpack("CSSS")
|
||||
reason = @socket.read(xlen * 4)
|
||||
reason = reason[0..len]
|
||||
raise "Connection to server failed -- (version #{major}.#{minor}) #{reason}"
|
||||
raise AuthorizationException.new "Connection to server failed -- (version #{major}.#{minor}) #{reason}", X11::Auth::FAILED
|
||||
when X11::Auth::AUTHENTICATE
|
||||
raise "Connection requires authentication"
|
||||
raise AuthorizationException.new "Connection requires authentication", X11::Auth::AUTHENTICATE
|
||||
when X11::Auth::SUCCESS
|
||||
raise "fix me"
|
||||
else
|
||||
raise "received unknown opcode #{type}"
|
||||
raise AuthorizationException.new "Received unknown opcode #{type}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
module X11
|
||||
|
||||
class ProtocolError < X11Error; end
|
||||
class ByteOrderError < ProtocolError; end
|
||||
|
||||
class Protocol
|
||||
|
||||
# endiness of your machine
|
||||
|
@ -8,7 +12,7 @@ module X11
|
|||
when "\1\0\0\0"
|
||||
"l"
|
||||
else
|
||||
raise "Cannot determine byte order"
|
||||
raise ByteOrderError.new "Cannot determine byte order"
|
||||
end
|
||||
|
||||
MAJOR = 11
|
||||
|
|
Loading…
Reference in a new issue