In case reading from TUN device detected TUN device was closed, it
closed the file handle and set tunFile to nil. The tunFile is
automatically reopened on retry, but... If another packet comes in the
WireGuard calls Write() method. With tunFile set to nil, this will
cause access violation.
Therefore, locking was introduced.
Signed-off-by: Simon Rozman <simon@rozman.si>
This allows buffer alignment and keeps it together with its meta-data.
Furthermore, the write buffer has been reduced - as long as we flush
after _every_ write, we don't need a 1MiB write buffer.
Signed-off-by: Simon Rozman <simon@rozman.si>
Do the WaitForSingleObject() always to provide high-load responsiveness.
Reorder events so TUN_SIGNAL_CLOSE has priority over
TUN_SIGNAL_DATA_AVAIL, to provide high-load responsiveness at all.
Signed-off-by: Simon Rozman <simon@rozman.si>