github.com/flyinox/gosm@v0.0.0-20171117061539-16768cb62077/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 "errors" 13 14 // ErrNetClosing is returned when a network descriptor is used after 15 // it has been closed. Keep this string consistent because of issue 16 // #4373: since historically programs have not been able to detect 17 // this error, they look for the string. 18 var ErrNetClosing = errors.New("use of closed network connection") 19 20 // ErrFileClosing is returned when a file descriptor is used after it 21 // has been closed. 22 var ErrFileClosing = errors.New("use of closed file") 23 24 // Return the appropriate closing error based on isFile. 25 func errClosing(isFile bool) error { 26 if isFile { 27 return ErrFileClosing 28 } 29 return ErrNetClosing 30 } 31 32 // ErrTimeout is returned for an expired deadline. 33 var ErrTimeout error = &TimeoutError{} 34 35 // TimeoutError is returned for an expired deadline. 36 type TimeoutError struct{} 37 38 // Implement the net.Error interface. 39 func (e *TimeoutError) Error() string { return "i/o timeout" } 40 func (e *TimeoutError) Timeout() bool { return true } 41 func (e *TimeoutError) Temporary() bool { return true } 42 43 // consume removes data from a slice of byte slices, for writev. 44 func consume(v *[][]byte, n int64) { 45 for len(*v) > 0 { 46 ln0 := int64(len((*v)[0])) 47 if ln0 > n { 48 (*v)[0] = (*v)[0][n:] 49 return 50 } 51 n -= ln0 52 *v = (*v)[1:] 53 } 54 } 55 56 // TestHookDidWritev is a hook for testing writev. 57 var TestHookDidWritev = func(wrote int) {}