Skip to content

Commit

Permalink
Merge pull request #642 from ackleymi/add-log
Browse files Browse the repository at this point in the history
Adds log to readLoop just like writeLoop
  • Loading branch information
ackleymi authored May 30, 2024
2 parents 2da4180 + 035d82e commit 7a5765f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion acceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func (a *Acceptor) handleConnection(netConn net.Conn) {

go func() {
msgIn <- fixIn{msgBytes, parser.lastRead}
readLoop(parser, msgIn)
readLoop(parser, msgIn, a.globalLog)
}()

writeLoop(netConn, msgOut, a.globalLog)
Expand Down
3 changes: 2 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ func writeLoop(connection io.Writer, messageOut chan []byte, log Log) {
}
}

func readLoop(parser *parser, msgIn chan fixIn) {
func readLoop(parser *parser, msgIn chan fixIn, log Log) {
defer close(msgIn)

for {
msg, err := parser.ReadMessage()
if err != nil {
log.OnEvent(err.Error())
return
}
msgIn <- fixIn{msg, parser.lastRead}
Expand Down
2 changes: 1 addition & 1 deletion connection_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestReadLoop(t *testing.T) {
stream := "hello8=FIX.4.09=5blah10=103garbage8=FIX.4.09=4foo10=103"

parser := newParser(strings.NewReader(stream))
go readLoop(parser, msgIn)
go readLoop(parser, msgIn, nullLog{})

var tests = []struct {
expectedMsg string
Expand Down
2 changes: 1 addition & 1 deletion initiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (i *Initiator) handleConnection(session *session, tlsConfig *tls.Config, di
goto reconnect
}

go readLoop(newParser(bufio.NewReader(netConn)), msgIn)
go readLoop(newParser(bufio.NewReader(netConn)), msgIn, session.log)
disconnected = make(chan interface{})
go func() {
writeLoop(netConn, msgOut, session.log)
Expand Down

0 comments on commit 7a5765f

Please sign in to comment.