mirror of https://github.com/cbeuw/Cloak
Change wsAcceptor's name to wsOnceListener
This commit is contained in:
parent
8d375e3f9b
commit
e7963b9e24
|
|
@ -83,22 +83,22 @@ func (c *firstBuffedConn) Read(buf []byte) (int, error) {
|
||||||
return c.Conn.Read(buf)
|
return c.Conn.Read(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
type wsAcceptor struct {
|
type wsOnceListener struct {
|
||||||
done bool
|
done bool
|
||||||
c *firstBuffedConn
|
c *firstBuffedConn
|
||||||
}
|
}
|
||||||
|
|
||||||
// net/http provides no method to serve an existing connection, we must feed in a net.Accept interface to get an
|
// net/http provides no method to serve an existing connection, we must feed in a net.Accept interface to get an
|
||||||
// http.Server. This is an acceptor that accepts only one Conn
|
// http.Server. This is an acceptor that accepts only one Conn
|
||||||
func newWsAcceptor(conn net.Conn, first []byte) *wsAcceptor {
|
func newWsAcceptor(conn net.Conn, first []byte) *wsOnceListener {
|
||||||
f := make([]byte, len(first))
|
f := make([]byte, len(first))
|
||||||
copy(f, first)
|
copy(f, first)
|
||||||
return &wsAcceptor{
|
return &wsOnceListener{
|
||||||
c: &firstBuffedConn{Conn: conn, firstPacket: f},
|
c: &firstBuffedConn{Conn: conn, firstPacket: f},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *wsAcceptor) Accept() (net.Conn, error) {
|
func (w *wsOnceListener) Accept() (net.Conn, error) {
|
||||||
if w.done {
|
if w.done {
|
||||||
return nil, errors.New("already accepted")
|
return nil, errors.New("already accepted")
|
||||||
}
|
}
|
||||||
|
|
@ -106,12 +106,12 @@ func (w *wsAcceptor) Accept() (net.Conn, error) {
|
||||||
return w.c, nil
|
return w.c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *wsAcceptor) Close() error {
|
func (w *wsOnceListener) Close() error {
|
||||||
w.done = true
|
w.done = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *wsAcceptor) Addr() net.Addr {
|
func (w *wsOnceListener) Addr() net.Addr {
|
||||||
return w.c.LocalAddr()
|
return w.c.LocalAddr()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue