Method: OpenC3::TcpipServerInterface#connect

Defined in:
lib/openc3/interfaces/tcpip_server_interface.rb

#connectObject

Create the read and write port listen threads. Incoming connections will spawn separate threads to process the reads and writes.



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/openc3/interfaces/tcpip_server_interface.rb', line 124

def connect
  @cancel_threads = false
  @read_queue.clear if @read_queue
  if @write_port == @read_port # One socket
    start_listen_thread(@read_port, true, true)
  else
    start_listen_thread(@write_port, true, false) if @write_port
    start_listen_thread(@read_port, false, true) if @read_port
  end

  if @write_port
    @write_thread = Thread.new do
      loop do
        write_thread_body()
        break if @cancel_threads
      end
    rescue Exception => err
      shutdown_interfaces(@write_interface_infos)
      Logger.error("#{@name}: Tcpip server write thread unexpectedly died")
      Logger.error(err.formatted)
    end
    @write_raw_thread = Thread.new do
      loop do
        write_raw_thread_body()
        break if @cancel_threads
      end
    rescue Exception => err
      shutdown_interfaces(@write_interface_infos)
      Logger.error("#{@name}: Tcpip server write raw thread unexpectedly died")
      Logger.error(err.formatted)
    end
  else
    @write_thread = nil
    @write_raw_thread = nil
  end
  @connected = true
end