tls-autodetect: finish inQ overrun handling

This commit is contained in:
Přemysl Eric Janouch 2018-07-22 14:55:15 +02:00
parent 525734eeb3
commit a8f02e0d37
Signed by: p
GPG Key ID: A0420B94F92B9493

View File

@ -218,12 +218,18 @@ func (c *client) onPrepared(host string, isTLS bool) {
}
// TODO: Save the host in the client structure.
// TODO: If we've tried to send any data before now, we need to flushOutQ.
go read(c)
c.reading = true
}
// Handle the results from trying to read from the client connection.
func (c *client) onRead(data []byte, readErr error) {
if !c.reading {
// Abusing the flag to emulate CloseRead and skip over data, see below.
return
}
c.inQ = append(c.inQ, data...)
for {
advance, token, _ := bufio.ScanLines(c.inQ, false /* atEOF */)
@ -237,14 +243,6 @@ func (c *client) onRead(data []byte, readErr error) {
broadcast(line, c)
}
// TODO: Inform the client about the inQ overrun in the farewell message.
// TODO: We should stop receiving any more data from this client, or at
// least stop extending the inQ if we don't want to signal tho goroutine.
if len(c.inQ) > 8192 {
c.closeLink()
return
}
if readErr != nil {
c.reading = false
@ -259,11 +257,20 @@ func (c *client) onRead(data []byte, readErr error) {
log.Println("client EOF")
c.closeLink()
}
} else if len(c.inQ) > 8192 {
log.Println("client inQ overrun")
// TODO: Inform the client about inQ overrun in the farewell message.
c.closeLink()
// tls.Conn doesn't have the CloseRead method (and it needs to be able
// to read from the TCP connection even for writes, so there isn't much
// sense in expecting the implementation to do anything useful),
// otherwise we'd use it to block incoming packet data.
c.reading = false
}
}
// Spawn a goroutine to flush the outQ if possible and necessary. If the
// connection is not ready yet, it needs to be retried as soon as it becomes.
// Spawn a goroutine to flush the outQ if possible and necessary.
func (c *client) flushOutQ() {
if !c.writing && c.conn != nil {
go write(c, c.outQ)