github.com/rakyll/go@v0.0.0-20170216000551-64c02460d703/src/internal/poll/fd.go (about) 1 // Copyright 2017 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package poll supports non-blocking I/O on file descriptors with polling. 6 // This supports I/O operations that block only a goroutine, not a thread. 7 // This is used by the net and os packages. 8 // It uses a poller built into the runtime, with support from the 9 // runtime scheduler. 10 package poll 11 12 import ( 13 "errors" 14 ) 15 16 // ErrClosing is returned when a descriptor is used after it has been closed. 17 var ErrClosing = errors.New("use of closed file or network connection") 18 19 // ErrTimeout is returned for an expired deadline. 20 var ErrTimeout error = &TimeoutError{} 21 22 // TimeoutError is returned for an expired deadline. 23 type TimeoutError struct{} 24 25 // Implement the net.Error interface. 26 func (e *TimeoutError) Error() string { return "i/o timeout" } 27 func (e *TimeoutError) Timeout() bool { return true } 28 func (e *TimeoutError) Temporary() bool { return true } 29 30 // consume removes data from a slice of byte slices, for writev. 31 func consume(v *[][]byte, n int64) { 32 for len(*v) > 0 { 33 ln0 := int64(len((*v)[0])) 34 if ln0 > n { 35 (*v)[0] = (*v)[0][n:] 36 return 37 } 38 n -= ln0 39 *v = (*v)[1:] 40 } 41 } 42 43 // TestHookDidWritev is a hook for testing writev. 44 var TestHookDidWritev = func(wrote int) {}