diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2022-06-24 10:41:37 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2022-06-24 10:41:37 -0700 |
| commit | 3178ae580a3fe97d6a1167b4346d209f04e9b7e3 (patch) | |
| tree | da306047792334bbb97e07707d713d3fa582753a /hotline/client.go | |
| parent | a1ac9a6f60c6881bb9fe97425f6aaa524b910035 (diff) | |
Implement bufio.Scanner for transaction parsing
Diffstat (limited to 'hotline/client.go')
| -rw-r--r-- | hotline/client.go | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/hotline/client.go b/hotline/client.go index e5b396b..c322562 100644 --- a/hotline/client.go +++ b/hotline/client.go @@ -397,54 +397,6 @@ func handleNotifyDeleteUser(c *Client, t *Transaction) (res []Transaction, err e return res, err } -const readBuffSize = 1024000 // 1KB - TODO: what should this be? - -func (c *Client) ReadLoop() error { - tranBuff := make([]byte, 0) - tReadlen := 0 - // Infinite loop where take action on incoming client requests until the connection is closed - for { - buf := make([]byte, readBuffSize) - tranBuff = tranBuff[tReadlen:] - - readLen, err := c.Connection.Read(buf) - if err != nil { - return err - } - tranBuff = append(tranBuff, buf[:readLen]...) - - // We may have read multiple requests worth of bytes from Connection.Read. readTransactions splits them - // into a slice of transactions - var transactions []Transaction - if transactions, tReadlen, err = readTransactions(tranBuff); err != nil { - c.Logger.Errorw("Error handling transaction", "err", err) - } - - // iterate over all of the transactions that were parsed from the byte slice and handle them - for _, t := range transactions { - if err := c.HandleTransaction(&t); err != nil { - c.Logger.Errorw("Error handling transaction", "err", err) - } - } - } -} - -func (c *Client) GetTransactions() error { - tranBuff := make([]byte, 0) - tReadlen := 0 - - buf := make([]byte, readBuffSize) - tranBuff = tranBuff[tReadlen:] - - readLen, err := c.Connection.Read(buf) - if err != nil { - return err - } - tranBuff = append(tranBuff, buf[:readLen]...) - - return nil -} - func handleClientGetUserNameList(c *Client, t *Transaction) (res []Transaction, err error) { var users []User for _, field := range t.Fields { |