Skip to content

Commit

Permalink
Merge pull request #26 from hadrianl/disconnect_on_conn_loss
Browse files Browse the repository at this point in the history
Disconnect on conn loss
  • Loading branch information
hadrianl authored Feb 16, 2021
2 parents aca1732 + 4062f63 commit 4072caa
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/binary"
"errors"
"fmt"
"io"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -145,11 +144,7 @@ func (ic *IbClient) Disconnect() error {
defer ic.wrapper.ConnectionClosed()
defer log.Info("Disconnected!")

if ic.err != nil {
return ic.err
}

return nil
return ic.err
}

// IsConnected check if there is a connection to TWS or GateWay
Expand Down Expand Up @@ -2899,6 +2894,12 @@ func (ic *IbClient) goReceive() {
// ic.Disconnect()
log.Debug("try to restart receiver")
go ic.goReceive()
} else {
select {
case <-ic.terminatedSignal:
default:
ic.Disconnect()
}
}
}()
defer log.Debug("receiver end")
Expand All @@ -2918,9 +2919,9 @@ func (ic *IbClient) goReceive() {
case <-ic.terminatedSignal:
default:
switch err := ic.scanner.Err(); err {
case io.EOF:
log.Debug("scanner Done", zap.Error(err))
ic.Disconnect()
case nil:
log.Debug("scanner Done")
// go ic.Disconnect()
case bufio.ErrTooLong:
errBytes := ic.scanner.Bytes()
ic.wrapper.Error(NO_VALID_ID, BAD_LENGTH.code, fmt.Sprintf("%s:%d:%s", BAD_LENGTH.msg, len(errBytes), errBytes))
Expand Down

0 comments on commit 4072caa

Please sign in to comment.