Method: OpenC3::UdpReadWriteSocket#write

Defined in:
lib/openc3/io/udp_sockets.rb

#write(data, write_timeout = 10.0) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/openc3/io/udp_sockets.rb', line 88

def write(data, write_timeout = 10.0)
  num_bytes_to_send = data.length
  total_bytes_sent  = 0
  bytes_sent = 0
  data_to_send = data

  loop do
    begin
      bytes_sent = @socket.write_nonblock(data_to_send)
    rescue Errno::EAGAIN, Errno::EWOULDBLOCK
      result = IO.fast_select(nil, [@socket], nil, write_timeout)
      if result
        retry
      else
        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