-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathquic_connection.go
More file actions
97 lines (77 loc) · 1.98 KB
/
quic_connection.go
File metadata and controls
97 lines (77 loc) · 1.98 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package roq
import (
"context"
"github.com/quic-go/quic-go"
)
type QuicGoReceiveStream struct {
stream *quic.ReceiveStream
}
func NewQuicGoReceiveStream(stream *quic.ReceiveStream) *QuicGoReceiveStream {
return &QuicGoReceiveStream{
stream: stream,
}
}
func (s *QuicGoReceiveStream) ID() int64 {
return int64(s.stream.StreamID())
}
func (s *QuicGoReceiveStream) CancelRead(c uint64) {
s.stream.CancelRead(quic.StreamErrorCode(c))
}
func (c *QuicGoReceiveStream) Read(p []byte) (n int, err error) {
return c.stream.Read(p)
}
type QuicGoSendStream struct {
stream *quic.SendStream
}
func NewQuicstream(stream *quic.SendStream) *QuicGoSendStream {
return &QuicGoSendStream{
stream: stream,
}
}
func (s *QuicGoSendStream) ID() int64 {
return int64(s.stream.StreamID())
}
func (s *QuicGoSendStream) Write(b []byte) (int, error) {
return s.stream.Write(b)
}
func (s *QuicGoSendStream) Close() error {
return s.stream.Close()
}
func (s *QuicGoSendStream) CancelWrite(c uint64) {
s.stream.CancelWrite(quic.StreamErrorCode(c))
}
type QUICGoConnection struct {
conn *quic.Conn
}
func NewQUICGoConnection(conn *quic.Conn) *QUICGoConnection {
return &QUICGoConnection{
conn: conn,
}
}
func (c *QUICGoConnection) SendDatagram(payload []byte) error {
return c.conn.SendDatagram(payload)
}
func (c *QUICGoConnection) ReceiveDatagram(ctx context.Context) ([]byte, error) {
return c.conn.ReceiveDatagram(ctx)
}
func (c *QUICGoConnection) OpenUniStreamSync(ctx context.Context) (SendStream, error) {
s, err := c.conn.OpenUniStreamSync(ctx)
if err != nil {
return nil, err
}
return &QuicGoSendStream{
stream: s,
}, nil
}
func (c *QUICGoConnection) AcceptUniStream(ctx context.Context) (ReceiveStream, error) {
s, err := c.conn.AcceptUniStream(ctx)
if err != nil {
return nil, err
}
return &QuicGoReceiveStream{
stream: s,
}, nil
}
func (c *QUICGoConnection) CloseWithError(code uint64, reason string) error {
return c.conn.CloseWithError(quic.ApplicationErrorCode(code), reason)
}