Class: Mongo::Socket Private
- Inherits:
-
Object
- Object
- Mongo::Socket
- Includes:
- Socket::Constants
- Defined in:
- lib/mongo/socket.rb,
lib/mongo/socket/ssl.rb,
lib/mongo/socket/tcp.rb,
lib/mongo/socket/unix.rb,
lib/mongo/socket/ocsp_cache.rb,
lib/mongo/socket/ocsp_verifier.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Provides additional data around sockets for the driver’s use.
Defined Under Namespace
Modules: OcspCache Classes: OcspVerifier, SSL, TCP, Unix
Constant Summary collapse
- SSL_ERROR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Deprecated.Error message for TLS related exceptions.
'MongoDB may not be configured with TLS support'- TIMEOUT_ERROR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Deprecated.Error message for timeouts on socket calls.
'Socket request timed out'- TIMEOUT_PACK =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The pack directive for timeouts.
'l_2'- WRITE_CHUNK_SIZE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Write data to the socket in chunks of this size.
65_536
Instance Attribute Summary collapse
-
#family ⇒ Integer
readonly
private
Family The type of host family.
-
#options ⇒ Hash
readonly
private
The options.
-
#socket ⇒ Socket
readonly
private
Socket The wrapped socket.
-
#timeout ⇒ Float
readonly
private
Timeout The socket timeout.
Instance Method Summary collapse
-
#alive? ⇒ true, false
deprecated
private
Deprecated.
Use #connectable? on the connection instead.
-
#close ⇒ true
private
Close the socket.
- #connectable? ⇒ true deprecated private Deprecated.
-
#connection_address ⇒ Address
private
Address of the connection that created this socket.
-
#connection_generation ⇒ Integer
private
Generation of the connection (for non-monitoring connections) that created this socket.
-
#eof? ⇒ Boolean
private
Tests if this socket has reached EOF.
-
#gets(*args) ⇒ Object
private
Delegates gets to the underlying socket.
-
#initialize(timeout, options) ⇒ Socket
constructor
private
Initializes common socket attributes.
-
#monitor? ⇒ true | false
private
Whether this socket was created by a monitoring connection.
-
#pipe ⇒ IO
private
listen on during the select system call when reading from the socket.
-
#read(length, socket_timeout: nil, timeout: nil) ⇒ Object
private
Will read all data from the socket for the provided number of bytes.
-
#readbyte ⇒ Object
private
Read a single byte from the socket.
-
#summary ⇒ String
private
Human-readable summary of the socket for debugging.
-
#write(*args, timeout: nil) ⇒ Integer
private
Writes data to the socket instance.
Constructor Details
#initialize(timeout, options) ⇒ Socket
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes common socket attributes.
70 71 72 73 |
# File 'lib/mongo/socket.rb', line 70 def initialize(timeout, ) @timeout = timeout @options = end |
Instance Attribute Details
#family ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns family The type of host family.
76 77 78 |
# File 'lib/mongo/socket.rb', line 76 def family @family end |
#options ⇒ Hash (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The options.
82 83 84 |
# File 'lib/mongo/socket.rb', line 82 def @options end |
#socket ⇒ Socket (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns socket The wrapped socket.
79 80 81 |
# File 'lib/mongo/socket.rb', line 79 def socket @socket end |
#timeout ⇒ Float (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns timeout The socket timeout.
85 86 87 |
# File 'lib/mongo/socket.rb', line 85 def timeout @timeout end |
Instance Method Details
#alive? ⇒ true, false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Use #connectable? on the connection instead.
Is the socket connection alive?
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/mongo/socket.rb', line 146 def alive? sock_arr = [ @socket ] if Kernel.select(sock_arr, nil, sock_arr, 0) # The eof? call is supposed to return immediately since select # indicated the socket is readable. However, if @socket is a TLS # socket, eof? can block anyway - see RUBY-2140. begin Timeout.timeout(0.1) do eof? end rescue ::Timeout::Error true end else true end end |
#close ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Close the socket.
172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/mongo/socket.rb', line 172 def close begin # Sometimes it seems the close call can hang for a long time ::Timeout.timeout(5) do @socket&.close end rescue StandardError # Silence all errors end true end |
#connectable? ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
For backwards compatibility only, do not use.
271 272 273 |
# File 'lib/mongo/socket.rb', line 271 def connectable? true end |
#connection_address ⇒ Address
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Address of the connection that created this socket.
90 91 92 |
# File 'lib/mongo/socket.rb', line 90 def connection_address [:connection_address] end |
#connection_generation ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Generation of the connection (for non-monitoring connections) that created this socket.
98 99 100 |
# File 'lib/mongo/socket.rb', line 98 def connection_generation [:connection_generation] end |
#eof? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Tests if this socket has reached EOF. Primarily used for liveness checks.
260 261 262 263 264 |
# File 'lib/mongo/socket.rb', line 260 def eof? @socket.eof? rescue IOError, SystemCallError true end |
#gets(*args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Delegates gets to the underlying socket.
194 195 196 197 198 |
# File 'lib/mongo/socket.rb', line 194 def gets(*args) map_exceptions do @socket.gets(*args) end end |
#monitor? ⇒ true | false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Whether this socket was created by a monitoring connection.
106 107 108 |
# File 'lib/mongo/socket.rb', line 106 def monitor? !![:monitor] end |
#pipe ⇒ IO
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
listen on during the select system call when reading from the socket.
113 114 115 |
# File 'lib/mongo/socket.rb', line 113 def pipe [:pipe] end |
#read(length, socket_timeout: nil, timeout: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Will read all data from the socket for the provided number of bytes. If no data is returned, an exception will be raised.
217 218 219 220 221 222 223 224 225 |
# File 'lib/mongo/socket.rb', line 217 def read(length, socket_timeout: nil, timeout: nil) raise ArgumentError, 'Both timeout and socket_timeout cannot be set' if !socket_timeout.nil? && !timeout.nil? if !socket_timeout.nil? || timeout.nil? read_without_timeout(length, socket_timeout) else read_with_timeout(length, timeout) end end |
#readbyte ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Read a single byte from the socket.
235 236 237 238 239 |
# File 'lib/mongo/socket.rb', line 235 def readbyte map_exceptions do @socket.readbyte end end |
#summary ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Human-readable summary of the socket for debugging.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/mongo/socket.rb', line 120 def summary fileno = begin @socket&.fileno rescue StandardError '<no socket>' end if monitor? indicator = if [:push] 'pm' else 'm' end "#{connection_address};#{indicator};fd=#{fileno}" else "#{connection_address};c:#{connection_generation};fd=#{fileno}" end end |
#write(*args, timeout: nil) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Writes data to the socket instance.
251 252 253 254 255 |
# File 'lib/mongo/socket.rb', line 251 def write(*args, timeout: nil) map_exceptions do do_write(*args, timeout: timeout) end end |