From 45e759a1facdc8644025a84a68514ebad2813a90 Mon Sep 17 00:00:00 2001 From: Ian Gudger Date: Tue, 21 Aug 2018 13:48:10 -0700 Subject: Build PCAP file with atomic blocking writes The previous use of non-blocking writes could result in corrupt PCAP files if a partial write occurs. Using (*os.File).Write solves this problem by not allowing partial writes. This change does not increase allocations (in one path it actually reduces them), but does add additional copying. PiperOrigin-RevId: 209652974 Change-Id: I4b1cf2eda4cfd7f237a4245aceb7391b3055a66c --- pkg/tcpip/link/rawfile/rawfile_unsafe.go | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'pkg/tcpip/link/rawfile') diff --git a/pkg/tcpip/link/rawfile/rawfile_unsafe.go b/pkg/tcpip/link/rawfile/rawfile_unsafe.go index 261d350d7..cea3cd6a1 100644 --- a/pkg/tcpip/link/rawfile/rawfile_unsafe.go +++ b/pkg/tcpip/link/rawfile/rawfile_unsafe.go @@ -94,29 +94,6 @@ func NonBlockingWrite2(fd int, b1, b2 []byte) *tcpip.Error { return nil } -// NonBlockingWriteN writes up to N byte slices to a file descriptor in a -// single syscall. It fails if partial data is written. -func NonBlockingWriteN(fd int, bs ...[]byte) *tcpip.Error { - iovec := make([]syscall.Iovec, 0, len(bs)) - - for _, b := range bs { - if len(b) == 0 { - continue - } - iovec = append(iovec, syscall.Iovec{ - Base: &b[0], - Len: uint64(len(b)), - }) - } - - _, _, e := syscall.RawSyscall(syscall.SYS_WRITEV, uintptr(fd), uintptr(unsafe.Pointer(&iovec[0])), uintptr(len(iovec))) - if e != 0 { - return TranslateErrno(e) - } - - return nil -} - type pollEvent struct { fd int32 events int16 -- cgit v1.2.3