mirror of
https://git.zx2c4.com/wireguard-go
synced 2025-10-06 00:57:23 +08:00
all: use Go 1.19 and its atomic types
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:

committed by
Jason A. Donenfeld

parent
d1d08426b2
commit
b51010ba13
@@ -29,7 +29,7 @@ type pipe struct {
|
||||
|
||||
type messageBytePipe struct {
|
||||
pipe
|
||||
writeClosed int32
|
||||
writeClosed atomic.Bool
|
||||
readEOF bool
|
||||
}
|
||||
|
||||
@@ -51,17 +51,17 @@ func (f *pipe) SetDeadline(t time.Time) error {
|
||||
|
||||
// CloseWrite closes the write side of a message pipe in byte mode.
|
||||
func (f *messageBytePipe) CloseWrite() error {
|
||||
if !atomic.CompareAndSwapInt32(&f.writeClosed, 0, 1) {
|
||||
if !f.writeClosed.CompareAndSwap(false, true) {
|
||||
return io.ErrClosedPipe
|
||||
}
|
||||
err := f.file.Flush()
|
||||
if err != nil {
|
||||
atomic.StoreInt32(&f.writeClosed, 0)
|
||||
f.writeClosed.Store(false)
|
||||
return err
|
||||
}
|
||||
_, err = f.file.Write(nil)
|
||||
if err != nil {
|
||||
atomic.StoreInt32(&f.writeClosed, 0)
|
||||
f.writeClosed.Store(false)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -70,7 +70,7 @@ func (f *messageBytePipe) CloseWrite() error {
|
||||
// Write writes bytes to a message pipe in byte mode. Zero-byte writes are ignored, since
|
||||
// they are used to implement CloseWrite.
|
||||
func (f *messageBytePipe) Write(b []byte) (int, error) {
|
||||
if atomic.LoadInt32(&f.writeClosed) != 0 {
|
||||
if f.writeClosed.Load() {
|
||||
return 0, io.ErrClosedPipe
|
||||
}
|
||||
if len(b) == 0 {
|
||||
|
Reference in New Issue
Block a user