@@ -38,19 +38,6 @@ class SSL < Socket
38
38
# @return [ Float ] timeout The connection timeout.
39
39
attr_reader :timeout
40
40
41
- # Close the socket.
42
- #
43
- # @example Close the socket.
44
- # socket.close
45
- #
46
- # @return [ true ] Always true.
47
- #
48
- # @since 2.0.0
49
- def close
50
- socket . sysclose rescue true
51
- true
52
- end
53
-
54
41
# Establishes a socket connection.
55
42
#
56
43
# @example Connect the socket.
@@ -91,29 +78,10 @@ def initialize(host, port, timeout, family, options = {})
91
78
@family = family
92
79
@tcp_socket = ::Socket . new ( family , SOCK_STREAM , 0 )
93
80
@tcp_socket . setsockopt ( IPPROTO_TCP , TCP_NODELAY , 1 )
94
- end
95
-
96
- # Will read all data from the socket for the provided number of bytes.
97
- # If less data is returned than requested, an exception will be raised.
98
- #
99
- # @example Read all the requested data from the socket.
100
- # socket.read(4096)
101
- #
102
- # @param [ Integer ] length The number of bytes to read.
103
- #
104
- # @raise [ Mongo::SocketError ] If not all data is returned.
105
- #
106
- # @return [ Object ] The data from the socket.
107
- #
108
- # @since 2.0.0
109
- def read ( length )
110
- handle_errors do
111
- data = read_from_socket ( length )
112
- while data . length < length
113
- data << read_from_socket ( length - data . length )
114
- end
115
- data
116
- end
81
+ encoded_timeout = [ timeout , 0 ] . pack ( TIMEOUT_PACK )
82
+ @tcp_socket . set_encoding ( BSON ::BINARY )
83
+ @tcp_socket . setsockopt ( SOL_SOCKET , SO_RCVTIMEO , encoded_timeout )
84
+ @tcp_socket . setsockopt ( SOL_SOCKET , SO_SNDTIMEO , encoded_timeout )
117
85
end
118
86
119
87
# Read a single byte from the socket.
@@ -125,21 +93,7 @@ def read(length)
125
93
#
126
94
# @since 2.0.0
127
95
def readbyte
128
- handle_errors { read_from_socket ( 1 ) }
129
- end
130
-
131
- # Writes data to the socket instance.
132
- #
133
- # @example Write to the socket.
134
- # socket.write(data)
135
- #
136
- # @param [ Object ] data The data to be written.
137
- #
138
- # @return [ Integer ] The length of bytes written to the socket.
139
- #
140
- # @since 2.0.0
141
- def write ( data )
142
- handle_errors { socket . syswrite ( data ) }
96
+ handle_errors { socket . read ( 1 ) }
143
97
end
144
98
145
99
private
@@ -159,12 +113,6 @@ def create_context(options)
159
113
context
160
114
end
161
115
162
- def read_from_socket ( length )
163
- Timeout ::timeout ( timeout , Error ::SocketTimeoutError ) do
164
- socket . sysread ( length ) || String . new
165
- end
166
- end
167
-
168
116
def verify_certificate! ( socket )
169
117
if context . verify_mode == OpenSSL ::SSL ::VERIFY_PEER
170
118
unless OpenSSL ::SSL . verify_certificate_identity ( socket . peer_cert , host )
0 commit comments