summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/gliderlabs/ssh/conn.go
diff options
context:
space:
mode:
authortechknowlogick <techknowlogick@gitea.io>2019-07-06 21:28:09 -0400
committerGitHub <noreply@github.com>2019-07-06 21:28:09 -0400
commitd0ec940dd7b79876c91288be54e8fd62eb42fe54 (patch)
treefb378674d89e02aeca8de4b399c32ffc31f81a93 /vendor/github.com/gliderlabs/ssh/conn.go
parentc44f0b1c760855f578d2e5ce6fafbf9cba97da4f (diff)
downloadgitea-d0ec940dd7b79876c91288be54e8fd62eb42fe54.tar.gz
gitea-d0ec940dd7b79876c91288be54e8fd62eb42fe54.zip
switch to use gliderlabs/ssh for builtin server (#7250)
resolves git conflicts from #3896 (credit to @belak, in case github doesn't keep original author during squash) Co-Authored-By: Matti Ranta <techknowlogick@gitea.io>
Diffstat (limited to 'vendor/github.com/gliderlabs/ssh/conn.go')
-rw-r--r--vendor/github.com/gliderlabs/ssh/conn.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/vendor/github.com/gliderlabs/ssh/conn.go b/vendor/github.com/gliderlabs/ssh/conn.go
new file mode 100644
index 0000000000..ebef8845ba
--- /dev/null
+++ b/vendor/github.com/gliderlabs/ssh/conn.go
@@ -0,0 +1,55 @@
+package ssh
+
+import (
+ "context"
+ "net"
+ "time"
+)
+
+type serverConn struct {
+ net.Conn
+
+ idleTimeout time.Duration
+ maxDeadline time.Time
+ closeCanceler context.CancelFunc
+}
+
+func (c *serverConn) Write(p []byte) (n int, err error) {
+ c.updateDeadline()
+ n, err = c.Conn.Write(p)
+ if _, isNetErr := err.(net.Error); isNetErr && c.closeCanceler != nil {
+ c.closeCanceler()
+ }
+ return
+}
+
+func (c *serverConn) Read(b []byte) (n int, err error) {
+ c.updateDeadline()
+ n, err = c.Conn.Read(b)
+ if _, isNetErr := err.(net.Error); isNetErr && c.closeCanceler != nil {
+ c.closeCanceler()
+ }
+ return
+}
+
+func (c *serverConn) Close() (err error) {
+ err = c.Conn.Close()
+ if c.closeCanceler != nil {
+ c.closeCanceler()
+ }
+ return
+}
+
+func (c *serverConn) updateDeadline() {
+ switch {
+ case c.idleTimeout > 0:
+ idleDeadline := time.Now().Add(c.idleTimeout)
+ if idleDeadline.Unix() < c.maxDeadline.Unix() || c.maxDeadline.IsZero() {
+ c.Conn.SetDeadline(idleDeadline)
+ return
+ }
+ fallthrough
+ default:
+ c.Conn.SetDeadline(c.maxDeadline)
+ }
+}