make Session implement net.Listener

pull/71/head
Qian Wang 5 years ago
parent 29a45bcc1a
commit 299f08270c

@ -183,7 +183,7 @@ func dispatchConnection(conn net.Conn, sta *server.State) {
log.Printf("New session from UID:%v, sessionID:%v\n", b64.EncodeToString(UID), sessionID)
sesh.AddConnection(conn)
for {
newStream, err := sesh.AcceptStream()
newStream, err := sesh.Accept()
if err != nil {
if err == mux.ErrBrokenSession {
log.Printf("Session closed for UID:%v, sessionID:%v\n", b64.EncodeToString(UID), sessionID)

@ -79,7 +79,7 @@ func (sesh *Session) OpenStream() (*Stream, error) {
return stream, nil
}
func (sesh *Session) AcceptStream() (*Stream, error) {
func (sesh *Session) Accept() (net.Conn, error) {
select {
case <-sesh.die:
return nil, ErrBrokenSession
@ -158,3 +158,6 @@ func (sesh *Session) timeoutAfter(to time.Duration) {
sesh.streamsM.Unlock()
}
}
// Addr is only for implementing net.Listener
func (sesh *Session) Addr() net.Addr { return nil }

@ -2,6 +2,9 @@ package multiplex
import (
"errors"
"net"
"time"
//"log"
"math"
prand "math/rand"
@ -155,3 +158,15 @@ func (stream *Stream) Close() error {
func (stream *Stream) closeNoDelMap() {
stream.heliumMask.Do(func() { close(stream.die) })
}
// the following functions are purely for implementing net.Conn interface.
// they are not used
var errNotImplemented = errors.New("Not implemented")
func (stream *Stream) LocalAddr() net.Addr { return nil }
func (stream *Stream) RemoteAddr() net.Addr { return nil }
// TODO: implement the following
func (stream *Stream) SetDeadline(t time.Time) error { return errNotImplemented }
func (stream *Stream) SetReadDeadline(t time.Time) error { return errNotImplemented }
func (stream *Stream) SetWriteDeadline(t time.Time) error { return errNotImplemented }

Loading…
Cancel
Save