Source File
conn.go
Belonging Package
charm.land/ssh
package sshimport ()type serverConn struct {net.ConnidleTimeout time.DurationmaxDeadline time.TimecloseCanceler context.CancelFunc// handshakeDeadline is cleared once the handshake completes, which happens// after gossh.NewServerConn has started goroutines that read it via// updateDeadline. Access it only through the accessors below.mu sync.MutexhandshakeDeadline time.Time}// setHandshakeDeadline bounds how long the handshake may take.func ( *serverConn) ( time.Time) {.mu.Lock().handshakeDeadline =.mu.Unlock().updateDeadline()}// clearHandshakeDeadline drops the handshake deadline once the handshake has// completed, leaving the idle and max deadlines to govern the connection.func ( *serverConn) () {.mu.Lock().handshakeDeadline = time.Time{}.mu.Unlock().updateDeadline()}func ( *serverConn) ( []byte) ( int, error) {if .idleTimeout > 0 {.updateDeadline()}, = .Conn.Write()if , := .(net.Error); && .closeCanceler != nil {.closeCanceler()}return}func ( *serverConn) ( []byte) ( int, error) {if .idleTimeout > 0 {.updateDeadline()}, = .Conn.Read()if , := .(net.Error); && .closeCanceler != nil {.closeCanceler()}return}func ( *serverConn) () ( error) {= .Conn.Close()if .closeCanceler != nil {.closeCanceler()}return}func ( *serverConn) () {.mu.Lock():= .handshakeDeadline.mu.Unlock()// idleTimeout and maxDeadline are set before the handshake starts and never// mutated afterwards, so they need no locking.:= .maxDeadlineif !.IsZero() && (.IsZero() || .Before()) {=}if .idleTimeout > 0 {:= time.Now().Add(.idleTimeout)if .IsZero() || .Before() {=}}_ = .SetDeadline()}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |