mirror of https://github.com/gorilla/websocket.git
mod: no need to change line feed
This commit is contained in:
parent
cd973fdcfc
commit
b27407e5fd
|
@ -35,7 +35,7 @@ var (
|
|||
func decompressNoContextTakeover(r io.Reader) io.ReadCloser {
|
||||
fr, _ := flateReaderPool.Get().(io.ReadCloser)
|
||||
fr.(flate.Resetter).Reset(io.MultiReader(r, strings.NewReader(tail)), nil)
|
||||
return &flateReadWrapper{fr: fr}
|
||||
return &flateReadWrapper{fr}
|
||||
}
|
||||
|
||||
func isValidCompressionLevel(level int) bool {
|
||||
|
@ -100,7 +100,6 @@ func (w *flateWriteWrapper) Write(p []byte) (int, error) {
|
|||
if w.fw == nil {
|
||||
return 0, errWriteClosed
|
||||
}
|
||||
|
||||
return w.fw.Write(p)
|
||||
}
|
||||
|
||||
|
@ -109,22 +108,17 @@ func (w *flateWriteWrapper) Close() error {
|
|||
return errWriteClosed
|
||||
}
|
||||
err1 := w.fw.Flush()
|
||||
|
||||
w.p.Put(w.fw)
|
||||
w.fw = nil
|
||||
|
||||
if w.tw.p != [4]byte{0, 0, 0xff, 0xff} {
|
||||
return errors.New("websocket: internal error, unexpected bytes at end of flate stream")
|
||||
}
|
||||
|
||||
w.tw.p = [4]byte{}
|
||||
w.tw.n = 0
|
||||
|
||||
err2 := w.tw.w.Close()
|
||||
if err1 != nil {
|
||||
return err1
|
||||
}
|
||||
|
||||
return err2
|
||||
}
|
||||
|
||||
|
@ -136,16 +130,13 @@ func (r *flateReadWrapper) Read(p []byte) (int, error) {
|
|||
if r.fr == nil {
|
||||
return 0, io.ErrClosedPipe
|
||||
}
|
||||
|
||||
n, err := r.fr.Read(p)
|
||||
|
||||
if err == io.EOF {
|
||||
// Preemptively place the reader back in the pool. This helps with
|
||||
// scenarios where the application does not call NextReader() soon after
|
||||
// this final read.
|
||||
r.Close()
|
||||
}
|
||||
|
||||
return n, err
|
||||
}
|
||||
|
||||
|
@ -154,9 +145,7 @@ func (r *flateReadWrapper) Close() error {
|
|||
return io.ErrClosedPipe
|
||||
}
|
||||
err := r.fr.Close()
|
||||
|
||||
flateReaderPool.Put(r.fr)
|
||||
|
||||
r.fr = nil
|
||||
return err
|
||||
}
|
||||
|
|
7
conn.go
7
conn.go
|
@ -333,7 +333,6 @@ func newConnBRW(conn net.Conn, isServer bool, readBufferSize, writeBufferSize in
|
|||
enableWriteCompression: true,
|
||||
compressionLevel: defaultCompressionLevel,
|
||||
}
|
||||
|
||||
c.SetCloseHandler(nil)
|
||||
c.SetPingHandler(nil)
|
||||
c.SetPongHandler(nil)
|
||||
|
@ -755,7 +754,6 @@ func (c *Conn) WriteMessage(messageType int, data []byte) error {
|
|||
if _, err = w.Write(data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return w.Close()
|
||||
}
|
||||
|
||||
|
@ -952,7 +950,6 @@ func (c *Conn) NextReader() (messageType int, r io.Reader, err error) {
|
|||
if c.readDecompress {
|
||||
c.reader = c.newDecompressionReader(c.reader)
|
||||
}
|
||||
|
||||
return frameType, c.reader, nil
|
||||
}
|
||||
}
|
||||
|
@ -979,11 +976,9 @@ func (r *messageReader) Read(b []byte) (int, error) {
|
|||
for c.readErr == nil {
|
||||
|
||||
if c.readRemaining > 0 {
|
||||
// Determine the size of the data to be read.
|
||||
if int64(len(b)) > c.readRemaining {
|
||||
b = b[:c.readRemaining]
|
||||
}
|
||||
|
||||
n, err := c.br.Read(b)
|
||||
c.readErr = hideTempErr(err)
|
||||
if c.isServer {
|
||||
|
@ -993,7 +988,6 @@ func (r *messageReader) Read(b []byte) (int, error) {
|
|||
if c.readRemaining > 0 && c.readErr == io.EOF {
|
||||
c.readErr = errUnexpectedEOF
|
||||
}
|
||||
|
||||
return n, c.readErr
|
||||
}
|
||||
|
||||
|
@ -1031,7 +1025,6 @@ func (c *Conn) ReadMessage() (messageType int, p []byte, err error) {
|
|||
return messageType, nil, err
|
||||
}
|
||||
p, err = ioutil.ReadAll(r)
|
||||
|
||||
return messageType, p, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue