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

net: wrong sample code in package document #8607

Closed
gopherbot opened this issue Aug 28, 2014 · 4 comments
Closed

net: wrong sample code in package document #8607

gopherbot opened this issue Aug 28, 2014 · 4 comments
Assignees
Milestone

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented Aug 28, 2014

by xiezhenye:

sample of net.Conn.Accept:

ln, err := net.Listen("tcp", ":8080")
if err != nil {
    // handle error
}
for {
    conn, err := ln.Accept()
    if err != nil {
        // handle error
        continue
    }
    go handleConnection(conn)
}

When err that Accept returns is not nil, it must not continue the loop.
recoverable err like syscall.EAGAIN, syscall.ECONNABORTED has been handler in Accept,
and all the err that returned is not recoverable. continue the loop will cause dead loop.

the sample should be:

ln, err := net.Listen("tcp", ":8080")
if err != nil {
    // handle error
}
for {
    conn, err := ln.Accept()
    if err != nil {
        // handle error
        break
    }
    go handleConnection(conn)
}
@mikioh

This comment has been minimized.

Copy link
Contributor

@mikioh mikioh commented Sep 4, 2014

Comment 1:

Mr. Fitzpatrick wrote it, so leave it to him.

Owner changed to @bradfitz.

@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Sep 29, 2014

Comment 2:

https://golang.org/cl/146470043

Labels changed: added release-go1.4, repo-main, documentation.

Status changed to Started.

@gopherbot

This comment has been minimized.

Copy link
Author

@gopherbot gopherbot commented Sep 29, 2014

Comment 3:

CL https://golang.org/cl/146470043 mentions this issue.
@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Sep 29, 2014

Comment 4:

This issue was closed by revision dca4605.

Status changed to Fixed.

@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman added a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
wheatman added a commit to wheatman/go-akaros that referenced this issue Jun 26, 2018
wheatman added a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
wheatman added a commit to wheatman/go-akaros that referenced this issue Jul 30, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.