add method LocalAddr and RemoteAddr

This commit is contained in:
xtaci
2019-05-14 21:17:35 +08:00
parent 1724e90827
commit 4299d21e8f
+21
View File
@@ -3,6 +3,7 @@ package smux
import (
"encoding/binary"
"io"
"net"
"sync"
"sync/atomic"
"time"
@@ -241,6 +242,26 @@ func (s *Session) SetDeadline(t time.Time) error {
return nil
}
// LocalAddr satisfies net.Conn interface
func (s *Session) LocalAddr() net.Addr {
if ts, ok := s.conn.(interface {
LocalAddr() net.Addr
}); ok {
return ts.LocalAddr()
}
return nil
}
// RemoteAddr satisfies net.Conn interface
func (s *Session) RemoteAddr() net.Addr {
if ts, ok := s.conn.(interface {
RemoteAddr() net.Addr
}); ok {
return ts.RemoteAddr()
}
return nil
}
// notify the session that a stream has closed
func (s *Session) streamClosed(sid uint32) {
s.streamLock.Lock()