diff options
Diffstat (limited to 'prototypes/tls-autodetect.go')
-rw-r--r-- | prototypes/tls-autodetect.go | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/prototypes/tls-autodetect.go b/prototypes/tls-autodetect.go index 4ce665b..a5642d6 100644 --- a/prototypes/tls-autodetect.go +++ b/prototypes/tls-autodetect.go @@ -16,14 +16,14 @@ // // This is an example TLS-autodetecting chat server. // -// You may connect to it using either of these: -// ncat -C localhost 1234 -// ncat -C --ssl localhost 1234 -// -// These clients are unable to properly shutdown the connection: +// These clients are unable to properly shutdown the connection on their exit: // telnet localhost 1234 // openssl s_client -connect localhost:1234 // +// While this one doesn't react to an EOF from the server: +// ncat -C localhost 1234 +// ncat -C --ssl localhost 1234 +// package main import ( @@ -165,7 +165,7 @@ func forceShutdown(reason string) { // --- Client ------------------------------------------------------------------ func (c *client) send(line string) { - if !c.closing { + if c.conn != nil && !c.closing { c.outQ = append(c.outQ, (line + "\r\n")...) c.flushOutQ() } @@ -205,6 +205,7 @@ func (c *client) destroy() { c.killTimer.Stop() } + log.Println("client destroyed") delete(clients, c) } @@ -341,6 +342,8 @@ func prepare(client *client) { } } + // Note that in this demo application the autodetection prevents non-TLS + // clients from receiving any messages until they send something. isTLS := false if sysconn, err := conn.(syscall.Conn).SyscallConn(); err != nil { // This is just for the TLS detection and doesn't need to be fatal. @@ -349,6 +352,7 @@ func prepare(client *client) { isTLS = detectTLS(sysconn) } + // FIXME: When the client sends no data, we still initialize its conn. prepared <- preparedEvent{client, host, isTLS} } |