Module: Rex::Socket::Comm
- Included in:
- Local
- Defined in:
- lib/rex/socket/comm.rb,
lib/rex/socket.rb
Overview
This mixin provides the basic interface that a derived class must implement in order to be a compatible comm class. The base comm class also supports registering event handlers that can be notified when sockets are being created and have been created. This allows code to extend sockets on creation from the single point that they are created.
Defined Under Namespace
Modules: Events Classes: Local
Class Method Summary collapse
-
.create(param) ⇒ Object
Creates a compatible socket based on the supplied uniform parameters.
Instance Method Summary collapse
-
#chainable? ⇒ Boolean
Indicates whether or not this comm can be chained with other chainable comms.
-
#deregister_event_handler(handler) ⇒ Object
Deregisters a previously registered event handler.
-
#each_event_handler(&block) ⇒ Object
Enumerates each registered event handler so that they can be notified of an event.
-
#notify_before_socket_create(comm, param) ⇒ Object
Notifies handlers of the before socket create event.
-
#notify_socket_created(comm, sock, param) ⇒ Object
Notifies handlers of the socket created event.
-
#register_event_handler(handler) ⇒ Object
Registers an event handler that implements the Rex::Socket::Comm::Event interface in at least some fashion.
Class Method Details
.create(param) ⇒ Object
Creates a compatible socket based on the supplied uniform parameters.
48 49 50 |
# File 'lib/rex/socket/comm.rb', line 48 def self.create(param) raise NotImplementedError end |
Instance Method Details
#chainable? ⇒ Boolean
Indicates whether or not this comm can be chained with other chainable comms. This is particularly important for things like Proxy Comms that can be proxied through one another. The semantics of this are currently undefined and will probably need some more thought.
58 59 60 |
# File 'lib/rex/socket/comm.rb', line 58 def chainable? false end |
#deregister_event_handler(handler) ⇒ Object
Deregisters a previously registered event handler.
78 79 80 81 82 |
# File 'lib/rex/socket/comm.rb', line 78 def deregister_event_handler(handler) if (handlers) handlers.delete(handler) end end |
#each_event_handler(&block) ⇒ Object
Enumerates each registered event handler so that they can be notified of an event.
88 89 90 91 92 |
# File 'lib/rex/socket/comm.rb', line 88 def each_event_handler(&block) if (handlers) handlers.each(&block) end end |
#notify_before_socket_create(comm, param) ⇒ Object
Notifies handlers of the before socket create event.
97 98 99 100 101 |
# File 'lib/rex/socket/comm.rb', line 97 def notify_before_socket_create(comm, param) each_event_handler() { |handler| handler.on_before_socket_create(comm, param) } end |
#notify_socket_created(comm, sock, param) ⇒ Object
Notifies handlers of the socket created event.
106 107 108 109 110 |
# File 'lib/rex/socket/comm.rb', line 106 def notify_socket_created(comm, sock, param) each_event_handler() { |handler| handler.on_socket_created(comm, sock, param) } end |
#register_event_handler(handler) ⇒ Object
Registers an event handler that implements the Rex::Socket::Comm::Event interface in at least some fashion. Event handlers are notified when sockets are created through the Comm instance that they register against.
67 68 69 70 71 72 73 |
# File 'lib/rex/socket/comm.rb', line 67 def register_event_handler(handler) if (handlers == nil) self.handlers = [] end self.handlers << handler end |