Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bufio: ReadBytes nead a limit maybe #8105

Closed
gopherbot opened this issue May 27, 2014 · 2 comments
Closed

bufio: ReadBytes nead a limit maybe #8105

gopherbot opened this issue May 27, 2014 · 2 comments

Comments

@gopherbot
Copy link

by golangwink:

for {
        var e error
        frag, e = b.ReadSlice(delim)
        if e == nil { // got final fragment
            break
        }
        if e != ErrBufferFull { // unexpected error
            err = e
            break
        }

        // Make a copy of the buffer.
        buf := make([]byte, len(frag))
        copy(buf, frag)
        full = append(full, buf) // if full is too big?
    }

The bufio.ReadBytes don't have a limit to append, it isn't a problem when use if for
files, but when you use bufio.ReadBytes for net socket, the client may never give you
the correct delimiter.

Then the memory of server will use up by even if only a connection.

thank you for your attention!
@ianlancetaylor
Copy link
Contributor

Comment 1:

If overly long limits are a concern, use bufio.Scanner instead.

Status changed to WorkingAsIntended.

@gopherbot
Copy link
Author

Comment 2 by golangwink:

thank you, but I wonder why the Scanner.maxTokenSize is not configurable? In my case, I
need a smaller token size.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants