mirror of
https://github.com/slackhq/nebula.git
synced 2026-11-17 00:36:52 +01:00
split tun setup and tun IO
This commit is contained in:
1 parent
10e1924489
commit
2ff4852551
5 files changed
+395
-413
No files matched your search
+2
-17
@@ -15,13 +15,9 @@ type singleQueue struct {
|
||||
|
||||
// NewSingleQueue wraps a one-datagram-per-Read ReadWriteCloser (a legacy tun device) into a Queue.
|
||||
// bufSize is the per-queue read scratch size and must be at least the largest datagram the source can return.
|
||||
// Close closes rwc. The Queue implements BatchWriter when rwc does.
|
||||
// Close closes rwc.
|
||||
func NewSingleQueue(rwc io.ReadWriteCloser, bufSize int) Queue {
|
||||
q := &singleQueue{rw: rwc, closer: rwc, buf: make([]byte, bufSize)}
|
||||
if bw, ok := rwc.(BatchWriter); ok {
|
||||
return &batchSingleQueue{singleQueue: q, bw: bw}
|
||||
}
|
||||
return q
|
||||
return &singleQueue{rw: rwc, closer: rwc, buf: make([]byte, bufSize)}
|
||||
}
|
||||
|
||||
// NewSingleQueueNoClose is NewSingleQueue for a source owned by someone else,
|
||||
@@ -51,14 +47,3 @@ func (q *singleQueue) Close() error {
|
||||
}
|
||||
return q.closer.Close()
|
||||
}
|
||||
|
||||
// batchSingleQueue is a singleQueue whose source also implements BatchWriter.
|
||||
// It is a separate type so a plain singleQueue never advertises WriteBatch.
|
||||
type batchSingleQueue struct {
|
||||
*singleQueue
|
||||
bw BatchWriter
|
||||
}
|
||||
|
||||
func (q *batchSingleQueue) WriteBatch(pkts [][]byte) error {
|
||||
return q.bw.WriteBatch(pkts)
|
||||
}
|
||||
Reference in new issue
Block a user