about bufio ReadBytes block?

172 views
Skip to first unread message

you fu

unread,
Sep 20, 2014, 5:25:26 AM9/20/14
to golan...@googlegroups.com
the funcion:

godoc bufio

➜  ~  godoc bufio ReadBytes
type Reader struct {
    // contains filtered or unexported fields
}
    Reader implements buffering for an io.Reader object.

func (b *Reader) ReadBytes(delim byte) (line []byte, err error)
    ReadBytes reads until the first occurrence of delim in the input,
    returning a slice containing the data up to and including the delimiter.
    If ReadBytes encounters an error before finding a delimiter, it returns
    the data read before the error and the error itself (often io.EOF).
    ReadBytes returns err != nil if and only if the returned data does not
    end in delim. For simple uses, a Scanner may be more convenient.

if the reader read data from socket,it is block?if not data arrive,i think it block.
but the function doc not illustrate it.



Dave Cheney

unread,
Sep 20, 2014, 7:13:34 AM9/20/14
to golan...@googlegroups.com
All Read functions in Go block until at least one byte of data has been received*, can you show me an example which does not?

Dave

* yes, the io.Reader contract admits that returning 0, nil is not an error, but the practice is highly discouraged.

you fu

unread,
Sep 20, 2014, 7:26:00 AM9/20/14
to golan...@googlegroups.com
but the doc function is not evident.so ask here?

thanks!
Reply all
Reply to author
Forward
0 new messages