github.com/tidwall/go@v0.0.0-20170415222209-6694a6888b7d/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  // ErrClosing is returned when a descriptor is used after it has been closed.
    15  var ErrClosing = errors.New("use of closed file or network connection")
    16  
    17  // ErrTimeout is returned for an expired deadline.
    18  var ErrTimeout error = &TimeoutError{}
    19  
    20  // TimeoutError is returned for an expired deadline.
    21  type TimeoutError struct{}
    22  
    23  // Implement the net.Error interface.
    24  func (e *TimeoutError) Error() string   { return "i/o timeout" }
    25  func (e *TimeoutError) Timeout() bool   { return true }
    26  func (e *TimeoutError) Temporary() bool { return true }
    27  
    28  // consume removes data from a slice of byte slices, for writev.
    29  func consume(v *[][]byte, n int64) {
    30  	for len(*v) > 0 {
    31  		ln0 := int64(len((*v)[0]))
    32  		if ln0 > n {
    33  			(*v)[0] = (*v)[0][n:]
    34  			return
    35  		}
    36  		n -= ln0
    37  		*v = (*v)[1:]
    38  	}
    39  }
    40  
    41  // TestHookDidWritev is a hook for testing writev.
    42  var TestHookDidWritev = func(wrote int) {}