forked from yinqiwen/gsnova
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quic.go
executable file
·47 lines (38 loc) · 975 Bytes
/
quic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package mux
import (
"sync/atomic"
"time"
quic "github.com/lucas-clemente/quic-go"
)
type QUICMuxSession struct {
streamCounter int64
quic.Session
}
func (q *QUICMuxSession) Ping() (time.Duration, error) {
return 0, nil
}
func (q *QUICMuxSession) CloseStream(stream MuxStream) error {
atomic.AddInt64(&q.streamCounter, -1)
return nil
}
func (q *QUICMuxSession) OpenStream() (MuxStream, error) {
s, err := q.OpenStreamSync()
if nil != err {
return nil, err
}
atomic.AddInt64(&q.streamCounter, 1)
return &ProxyMuxStream{TimeoutReadWriteCloser: s, session: q}, nil
}
func (q *QUICMuxSession) AcceptStream() (MuxStream, error) {
s, err := q.Session.AcceptStream()
if nil != err {
return nil, err
}
return &ProxyMuxStream{TimeoutReadWriteCloser: s}, nil
}
func (q *QUICMuxSession) NumStreams() int {
return int(q.streamCounter)
}
func (q *QUICMuxSession) Close() error {
return q.Session.Close(nil)
}