lib/cosmos/streams/tcpip_socket_stream.rb in cosmos-4.5.2-java vs lib/cosmos/streams/tcpip_socket_stream.rb in cosmos-5.0.2.pre.beta2

- old
+ new

@@ -1,23 +1,31 @@ # encoding: ascii-8bit -# Copyright 2014 Ball Aerospace & Technologies Corp. +# Copyright 2022 Ball Aerospace & Technologies Corp. # All Rights Reserved. # # This program is free software; you can modify and/or redistribute it -# under the terms of the GNU General Public License +# under the terms of the GNU Affero General Public License # as published by the Free Software Foundation; version 3 with # attribution addendums as found in the LICENSE.txt +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# This program may also be used under the terms of a commercial or +# enterprise edition license of COSMOS if purchased from the +# copyright holder require 'socket' require 'thread' # For Mutex require 'timeout' # For Timeout::Error require 'cosmos/streams/stream' require 'cosmos/config/config_parser' module Cosmos - # Data {Stream} which reads and writes from Tcpip Sockets. class TcpipSocketStream < Stream attr_reader :write_socket FAST_READ = (RUBY_VERSION > "2.1") @@ -53,10 +61,11 @@ if FAST_READ begin while true # Loop until we get some data data = @read_socket.read_nonblock(65535, exception: false) raise EOFError, 'end of file reached' unless data + if data == :wait_readable # Wait for the socket to be ready for reading or for the timeout begin result = IO.fast_select([@read_socket, @pipe_reader], nil, nil, @read_timeout) # If select returns something it means the socket is now available for @@ -118,10 +127,11 @@ # No read mutex is needed because reads happen serially begin if FAST_READ data = @read_socket.read_nonblock(65535, exception: false) raise EOFError, 'end of file reached' unless data + data = '' if data == :wait_readable else data = @read_socket.read_nonblock(65535) end rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::ECONNRESET, Errno::ECONNABORTED, IOError @@ -155,10 +165,11 @@ raise Timeout::Error, "Write Timeout" end end total_bytes_sent += bytes_sent break if total_bytes_sent >= num_bytes_to_send + data_to_send = data[total_bytes_sent..-1] end end end @@ -178,9 +189,7 @@ Cosmos.close_socket(@write_socket) Cosmos.close_socket(@read_socket) @pipe_writer.write('.') @connected = false end - end # class TcpipSocketStream - end # module Cosmos