From 5ce6e358a9372e70e719a2c5c785afe768e6f06d Mon Sep 17 00:00:00 2001 From: Moritz Kork <35692507+moritzkork@users.noreply.github.com> Date: Fri, 10 Feb 2023 16:42:53 +0100 Subject: [PATCH] Update connection.rb patches to run in windows - line [287] added check for windows environment and reinstated line [288], commenting it out led to stall in Windows environment - line [292], [306] added check for windows environment, ingores TWS shutdown check in windows environment (functionality does not work in Windows environment) --- lib/ib/connection.rb | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/ib/connection.rb b/lib/ib/connection.rb index 49853c6..67102ae 100644 --- a/lib/ib/connection.rb +++ b/lib/ib/connection.rb @@ -284,23 +284,27 @@ def process_messages poll_time = 50 # in msec begin while (time_left = time_out - Time.now) > 0 # If socket is readable, process single incoming message - #process_message if select [socket], nil, nil, time_left - # the following checks for shutdown of TWS side; ensures we don't run in a spin loop. - # unfortunately, it raises Errors in windows environment - if select [socket], nil, nil, time_left - # # Peek at the message from the socket; if it's blank then the - # # server side of connection (TWS) has likely shut down. - socket_likely_shutdown = socket.recvmsg(100, Socket::MSG_PEEK)[0] == "" - # - # # We go ahead process messages regardless (a no-op if socket_likely_shutdown). - process_message - # - # # After processing, if socket has shut down we sleep for 100ms - # # to avoid spinning in a tight loop. If the server side somehow - # # comes back up (gets reconnedted), normal processing - # # (without the 100ms wait) should happen. - sleep(0.1) if socket_likely_shutdown - end + if windows_ver = RUBY_PLATFORM.match(/cygwin|mswin|mingw|bccwin|wince|emx/) + process_message if select [socket], nil, nil, time_left + end + # the following checks for shutdown of TWS side; ensures we don't run in a spin loop. + # unfortunately, it raises Errors in windows environment + if windows_ver.nil? + if select [socket], nil, nil, time_left + # # Peek at the message from the socket; if it's blank then the + # # server side of connection (TWS) has likely shut down. + socket_likely_shutdown = socket.recvmsg(100, Socket::MSG_PEEK)[0] == "" + # + # # We go ahead process messages regardless (a no-op if socket_likely_shutdown). + process_message + # + # # After processing, if socket has shut down we sleep for 100ms + # # to avoid spinning in a tight loop. If the server side somehow + # # comes back up (gets reconnedted), normal processing + # # (without the 100ms wait) should happen. + sleep(0.1) if socket_likely_shutdown + end + end end rescue Errno::ECONNRESET => e logger.fatal e.message