lib/steam/networking/connection.rb in steamrb-0.1.1 vs lib/steam/networking/connection.rb in steamrb-0.1.2

- old
+ new

@@ -131,20 +131,20 @@ Packet.new(data) end # @api private def write_socket(data) - socket.write(data) + handle_timeout { socket.write(data) } rescue IOError => e # If we are disconnecting, the socket is allowed to be closed return 0 if disconnecting raise e end # @api private def read_socket(len) - socket.read(len) + handle_timeout { socket.read(len) } rescue IOError => e # If we are disconnecting, the socket is allowed to be closed return nil if disconnecting raise e end @@ -170,9 +170,16 @@ end # @api private def session_key @mutex.synchronize { @session_key } + end + + def handle_timeout(&block) + raise ArgumentError, 'requires block' unless block_given? + Retryable.retryable(tries: 3, sleep: 1, on: [Errno::ETIMEDOUT]) do + block.call + end end end end end