"fmt"
"io"
"io/ioutil"
- "os"
"strings"
"testing"
"testing/iotest"
{0, 1, nil, io.ErrShortWrite},
{1, 2, nil, io.ErrShortWrite},
{1, 1, nil, nil},
- {0, 1, os.EPIPE, os.EPIPE},
- {1, 2, os.EPIPE, os.EPIPE},
- {1, 1, os.EPIPE, os.EPIPE},
+ {0, 1, io.ErrClosedPipe, io.ErrClosedPipe},
+ {1, 2, io.ErrClosedPipe, io.ErrClosedPipe},
+ {1, 1, io.ErrClosedPipe, io.ErrClosedPipe},
}
func TestWriteErrors(t *testing.T) {
"errors"
"fmt"
"io"
- "os"
)
// Order specifies the bit ordering in an LZW data stream.
d.o = 0
}
+var errClosed = errors.New("compress/lzw: reader/writer is closed")
+
func (d *decoder) Close() error {
- d.err = os.EINVAL // in case any Reads come along
+ d.err = errClosed // in case any Reads come along
return nil
}
"errors"
"fmt"
"io"
- "os"
)
// A writer is a buffered, flushable writer.
// call. It is equal to invalidCode if there was no such call.
savedCode uint32
// err is the first error encountered during writing. Closing the encoder
- // will make any future Write calls return os.EINVAL.
+ // will make any future Write calls return errClosed
err error
// table is the hash table from 20-bit keys to 12-bit values. Each table
// entry contains key<<12|val and collisions resolve by linear probing.
// flush e's underlying writer.
func (e *encoder) Close() error {
if e.err != nil {
- if e.err == os.EINVAL {
+ if e.err == errClosed {
return nil
}
return e.err
}
- // Make any future calls to Write return os.EINVAL.
- e.err = os.EINVAL
+ // Make any future calls to Write return errClosed.
+ e.err = errClosed
// Write the savedCode if valid.
if e.savedCode != invalidCode {
if err := e.write(e, e.savedCode); err != nil {
return
}
_, err1 := lzww.Write(b[:n])
- if err1 == os.EPIPE {
- // Fail, but do not report the error, as some other (presumably reportable) error broke the pipe.
- return
- }
if err1 != nil {
t.Errorf("%s (order=%d litWidth=%d): %v", fn, order, litWidth, err1)
return
}
defer zlibw.Close()
_, err = zlibw.Write(b0)
- if err == os.EPIPE {
- // Fail, but do not report the error, as some other (presumably reported) error broke the pipe.
- return
- }
if err != nil {
t.Errorf("%s (level=%d, dict=%q): %v", fn, level, d, err)
return
package rand
import (
+ "errors"
"io"
"math/big"
- "os"
)
// Prime returns a number, p, of the given size, such that p is prime
// with high probability.
func Prime(rand io.Reader, bits int) (p *big.Int, err error) {
if bits < 1 {
- err = os.EINVAL
+ err = errors.New("crypto/rand: prime size must be positive")
}
b := uint(bits % 8)
}
// SetReadTimeout sets the time (in nanoseconds) that
-// Read will wait for data before returning os.EAGAIN.
+// Read will wait for data before returning a net.Error
+// with Timeout() == true.
// Setting nsec == 0 (the default) disables the deadline.
func (c *Conn) SetReadTimeout(nsec int64) error {
return c.conn.SetReadTimeout(nsec)
return c.writeRecord(recordTypeApplicationData, b)
}
-// Read can be made to time out and return err == os.EAGAIN
+// Read can be made to time out and return a net.Error with Timeout() == true
// after a fixed time limit; see SetTimeout and SetReadTimeout.
func (c *Conn) Read(b []byte) (n int, err error) {
if err = c.Handshake(); err != nil {
import (
"bytes"
"io"
- "os"
"reflect"
"strings"
"testing"
func (d *downCaser) Read(p []byte) (int, error) {
d.t.Fatalf("unexpected Read call on downCaser reader")
- return 0, os.EINVAL
+ panic("unreachable")
}
func TestRawTokenAltEncoding(t *testing.T) {
package tiff
-import (
- "io"
- "os"
-)
+import "io"
// buffer buffers an io.Reader to satisfy io.ReaderAt.
type buffer struct {
o := int(off)
end := o + len(p)
if int64(end) != off+int64(len(p)) {
- return 0, os.EINVAL
+ return 0, io.ErrUnexpectedEOF
}
m := len(b.buf)
package syslog
import (
+ "errors"
"fmt"
"log"
"net"
// Write sends a log message to the syslog daemon.
func (w *Writer) Write(b []byte) (int, error) {
if w.priority > LOG_DEBUG || w.priority < LOG_EMERG {
- return 0, os.EINVAL
+ return 0, errors.New("log/syslog: invalid priority")
}
return w.conn.writeBytes(w.priority, w.prefix, b)
}
func (r sliceReaderAt) ReadAt(b []byte, off int64) (int, error) {
if int(off) >= len(r) || off < 0 {
- return 0, os.EINVAL
+ return 0, io.ErrUnexpectedEOF
}
n := copy(b, r[int(off):])
return n, nil
ErrPipeline = &http.ProtocolError{"pipeline error"}
)
+// This is an API usage error - the local side is closed.
+// ErrPersistEOF (above) reports that the remote side is closed.
+var errClosed = errors.New("i/o operation on closed connection")
+
// A ServerConn reads requests and sends responses over an underlying
// connection, until the HTTP keepalive logic commands an end. ServerConn
// also allows hijacking the underlying connection by calling Hijack
}
if sc.r == nil { // connection closed by user in the meantime
defer sc.lk.Unlock()
- return nil, os.EBADF
+ return nil, errClosed
}
r := sc.r
lastbody := sc.lastbody
}
if cc.c == nil { // connection closed by user in the meantime
defer cc.lk.Unlock()
- return os.EBADF
+ return errClosed
}
c := cc.c
if req.Close {
}
if cc.r == nil { // connection closed by user in the meantime
defer cc.lk.Unlock()
- return nil, os.EBADF
+ return nil, errClosed
}
r := cc.r
lastbody := cc.lastbody
var remoteSideClosedFunc func(error) bool // or nil to use default
func remoteSideClosed(err error) bool {
- if err == io.EOF || err == os.EINVAL {
+ if err == io.EOF {
return true
}
if remoteSideClosedFunc != nil {
import (
"bytes"
"io"
- "os"
"unicode/utf8"
)
func (b *Writer) write0(buf []byte) {
n, err := b.output.Write(buf)
if n != len(buf) && err == nil {
- err = os.EIO
+ err = io.ErrShortWrite
}
if err != nil {
panic(osError{err})
"bufio"
"crypto/tls"
"encoding/json"
+ "errors"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
- "os"
"sync"
)
return &Addr{ws.config.Origin}
}
+var errSetTimeout = errors.New("websocket: cannot set timeout: not using a net.Conn")
+
// SetTimeout sets the connection's network timeout in nanoseconds.
func (ws *Conn) SetTimeout(nsec int64) error {
if conn, ok := ws.rwc.(net.Conn); ok {
return conn.SetTimeout(nsec)
}
- return os.EINVAL
+ return errSetTimeout
}
// SetReadTimeout sets the connection's network read timeout in nanoseconds.
if conn, ok := ws.rwc.(net.Conn); ok {
return conn.SetReadTimeout(nsec)
}
- return os.EINVAL
+ return errSetTimeout
}
// SetWriteTimeout sets the connection's network write timeout in nanoseconds.
if conn, ok := ws.rwc.(net.Conn); ok {
return conn.SetWriteTimeout(nsec)
}
- return os.EINVAL
+ return errSetTimeout
}
// Config returns the WebSocket config.