@@ -26,7 +26,7 @@ mod recorder;
26
26
const MIN_SERVER_VERSION : i32 = 100 ;
27
27
const MAX_SERVER_VERSION : i32 = server_versions:: HISTORICAL_SCHEDULE ;
28
28
const MAX_RETRIES : i32 = 20 ;
29
- const TWS_READ_TIMEOUT : Duration = Duration :: from_secs ( 3 ) ;
29
+ const TWS_READ_TIMEOUT : Duration = Duration :: from_secs ( 1 ) ;
30
30
31
31
pub ( crate ) trait MessageBus : Send + Sync {
32
32
// Sends formatted message to TWS and creates a reply channel by request id.
@@ -220,21 +220,22 @@ impl TcpMessageBus {
220
220
fn start_dispatcher_thread ( self : & Arc < Self > , server_version : i32 ) -> JoinHandle < ( ) > {
221
221
let message_bus = Arc :: clone ( self ) ;
222
222
223
- const RECONNECT_ERRORS : & [ ErrorKind ] = & [ ErrorKind :: ConnectionReset , ErrorKind :: ConnectionAborted , ErrorKind :: UnexpectedEof ] ;
223
+ const RECONNECT_CODES : & [ ErrorKind ] = & [ ErrorKind :: ConnectionReset , ErrorKind :: ConnectionAborted , ErrorKind :: UnexpectedEof ] ;
224
+ const TIMEOUT_CODES : & [ ErrorKind ] = & [ ErrorKind :: WouldBlock , ErrorKind :: TimedOut ] ;
224
225
225
226
thread:: spawn ( move || {
226
227
loop {
227
228
match message_bus. read_message ( ) {
228
229
Ok ( message) => {
229
230
message_bus. dispatch_message ( server_version, message) ;
230
231
}
231
- Err ( Error :: Io ( e) ) if e. kind ( ) == ErrorKind :: WouldBlock => {
232
+ Err ( Error :: Io ( e) ) if TIMEOUT_CODES . contains ( & e. kind ( ) ) => {
232
233
if message_bus. is_shutting_down ( ) {
233
234
debug ! ( "dispatcher thread exiting" ) ;
234
235
return ;
235
236
}
236
237
}
237
- Err ( Error :: Io ( e) ) if RECONNECT_ERRORS . contains ( & e. kind ( ) ) => {
238
+ Err ( Error :: Io ( e) ) if RECONNECT_CODES . contains ( & e. kind ( ) ) => {
238
239
error ! ( "error reading next message (will attempt reconnect): {:?}" , e) ;
239
240
240
241
// Attempt to reconnect to TWS.
0 commit comments