summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/link/rawfile
diff options
context:
space:
mode:
authorIan Gudger <igudger@google.com>2018-08-21 13:48:10 -0700
committerShentubot <shentubot@google.com>2018-08-21 13:49:18 -0700
commit45e759a1facdc8644025a84a68514ebad2813a90 (patch)
tree5879ff71eca7bce50cfe8d7ec34e06d00fc515c4 /pkg/tcpip/link/rawfile
parentd6d165cb0b8147461388287ffd4cfee221940123 (diff)
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
Diffstat (limited to 'pkg/tcpip/link/rawfile')
-rw-r--r--pkg/tcpip/link/rawfile/rawfile_unsafe.go23
1 files changed, 0 insertions, 23 deletions
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