1
0
mirror of https://github.com/fumiama/water.git synced 2026-06-09 12:40:28 +08:00
This commit is contained in:
fumiama
2021-12-31 17:41:48 +08:00
parent 80ce193460
commit 0c176c6cfb

View File

@@ -329,6 +329,7 @@ type wintunRWC struct {
readwait windows.Handle
readbuf []byte
rate rateJuggler
mu sync.Mutex
isclosed bool
}
@@ -340,6 +341,8 @@ func (w *wintunRWC) Close() error {
func (w *wintunRWC) Write(b []byte) (int, error) {
w.rate.update(uint64(len(b)))
w.mu.Lock()
defer w.mu.Unlock()
packet, err := w.s.AllocateSendPacket(len(b))
switch err {
case nil:
@@ -377,6 +380,8 @@ RETRY:
}
start := nanotime()
shouldSpin := atomic.LoadUint64(&w.rate.current) >= spinloopRateThreshold && uint64(start-atomic.LoadInt64(&w.rate.nextStartTime)) <= rateMeasurementGranularity*2
w.mu.Lock()
defer w.mu.Unlock()
for {
packet, err := w.s.ReceivePacket()
switch err {