mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 04:07:35 +03:00
39 lines
634 B
Go
39 lines
634 B
Go
package quic
|
|
|
|
type sendQueue struct {
|
|
queue chan *packedPacket
|
|
closeChan chan struct{}
|
|
conn connection
|
|
}
|
|
|
|
func newSendQueue(conn connection) *sendQueue {
|
|
s := &sendQueue{
|
|
conn: conn,
|
|
closeChan: make(chan struct{}),
|
|
queue: make(chan *packedPacket, 1),
|
|
}
|
|
return s
|
|
}
|
|
|
|
func (h *sendQueue) Send(p *packedPacket) {
|
|
h.queue <- p
|
|
}
|
|
|
|
func (h *sendQueue) Run() error {
|
|
var p *packedPacket
|
|
for {
|
|
select {
|
|
case <-h.closeChan:
|
|
return nil
|
|
case p = <-h.queue:
|
|
}
|
|
if err := h.conn.Write(p.raw); err != nil {
|
|
return err
|
|
}
|
|
p.buffer.Release()
|
|
}
|
|
}
|
|
|
|
func (h *sendQueue) Close() {
|
|
close(h.closeChan)
|
|
}
|