uquic/send_queue.go
2019-08-24 15:25:38 +07:00

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)
}