Class: Lich::Common::SynchronizedSocket
- Inherits:
-
Object
- Object
- Lich::Common::SynchronizedSocket
- Defined in:
- documented/common/class_exts/synchronizedsocket.rb
Overview
A socket wrapper that synchronizes access to a delegate socket.
This class ensures that all operations on the delegate socket are thread-safe.
Instance Method Summary collapse
-
#initialize(o) ⇒ void
constructor
Initializes a new SynchronizedSocket instance.
-
#method_missing(method, *args) {|Proc| ... } ⇒ Object
Handles calls to methods that are not defined in this class.
-
#puts(*args) {|Proc| ... } ⇒ void
Writes a line to the delegate socket.
-
#puts_if(*args) {|Proc| ... } ⇒ Boolean
Conditionally writes a line to the delegate socket based on the block's return value.
-
#write(*args) {|Proc| ... } ⇒ void
Writes data to the delegate socket.
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) {|Proc| ... } ⇒ Object
Handles calls to methods that are not defined in this class.
This method delegates the call to the underlying socket.
68 69 70 |
# File 'documented/common/class_exts/synchronizedsocket.rb', line 68 def method_missing(method, *args, &block) @delegate.__send__ method, *args, &block end |
Instance Method Details
#puts(*args) {|Proc| ... } ⇒ void
This method returns an undefined value.
Writes a line to the delegate socket.
This method is thread-safe and will synchronize access to the delegate.
26 27 28 29 30 |
# File 'documented/common/class_exts/synchronizedsocket.rb', line 26 def puts(*args, &block) @mutex.synchronize { @delegate.puts(*args, &block) } end |
#puts_if(*args) {|Proc| ... } ⇒ Boolean
Conditionally writes a line to the delegate socket based on the block's return value.
This method is thread-safe and will synchronize access to the delegate.
38 39 40 41 42 43 44 45 46 47 |
# File 'documented/common/class_exts/synchronizedsocket.rb', line 38 def puts_if(*args) @mutex.synchronize { if yield @delegate.puts(*args) return true else return false end } end |
#write(*args) {|Proc| ... } ⇒ void
This method returns an undefined value.
Writes data to the delegate socket.
This method is thread-safe and will synchronize access to the delegate.
55 56 57 58 59 |
# File 'documented/common/class_exts/synchronizedsocket.rb', line 55 def write(*args, &block) @mutex.synchronize { @delegate.write(*args, &block) } end |