// Read implements tcpip.Endpoint.Read.
Read implements tcpip.Endpoint.Read.
// Read implements tcpip . Endpoint . Read .
func (e *endpoint) Read(dst io.Writer, opts tcpip.ReadOptions) (tcpip.ReadResult, tcpip.Error) {
	e.rcvMu.Lock()
	if e.rcvList.Empty() {
		var err tcpip.Error = &tcpip.ErrWouldBlock{}
		if e.rcvClosed {
			e.stats.ReadErrors.ReadClosed.Increment()
			err = &tcpip.ErrClosedForReceive{}
		}
		e.rcvMu.Unlock()
		return tcpip.ReadResult{}, err
	}
	pkt := e.rcvList.Front()
	if !opts.Peek {
		e.rcvList.Remove(pkt)
		e.rcvBufSize -= pkt.data.Size()
	}
	e.rcvMu.Unlock()
	res := tcpip.ReadResult{
		Total: pkt.data.Size(),
		ControlMessages: tcpip.ControlMessages{
			HasTimestamp: true,
			Timestamp:    pkt.receivedAt.UnixNano(),
		},
	}
	if opts.NeedRemoteAddr {
		res.RemoteAddr = pkt.senderAddr
	}
	n, err := pkt.data.ReadTo(dst, opts.Peek)
	if n == 0 && err != nil {
		return res, &tcpip.ErrBadBuffer{}
	}
	res.Count = n
	return res, nil
}
func ( e * endpoint ) Read ( dst io . Writer , opts tcpip . ReadOptions ) ( tcpip . ReadResult , tcpip . Error ) { e . rcvMu . Lock ( ) if e . rcvList . Empty ( ) { var err tcpip . Error = & tcpip . ErrWouldBlock { } if e . rcvClosed { e . stats . ReadErrors . ReadClosed . Increment ( ) err = & tcpip . ErrClosedForReceive { } } e . rcvMu . Unlock ( ) return tcpip . ReadResult { } , err } pkt := e . rcvList . Front ( ) if ! opts . Peek { e . rcvList . Remove ( pkt ) e . rcvBufSize -= pkt . data . Size ( ) } e . rcvMu . Unlock ( ) res := tcpip . ReadResult { Total : pkt . data . Size ( ) , ControlMessages : tcpip . ControlMessages { HasTimestamp : true , Timestamp : pkt . receivedAt . UnixNano ( ) , } , } if opts . NeedRemoteAddr { res . RemoteAddr = pkt . senderAddr } n , err := pkt . data . ReadTo ( dst , opts . Peek ) if n == 0 && err != nil { return res , & tcpip . ErrBadBuffer { } } res . Count = n return res , nil }
Read implements tcpip.Endpoint.Read.
Read implements tcpip . Endpoint . Read .
// If there's no data to read, return that read would block or that the // endpoint is closed.