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

http.Conn needs Flush method to force output #93

Closed
gopherbot opened this issue Nov 12, 2009 · 4 comments
Closed

http.Conn needs Flush method to force output #93

gopherbot opened this issue Nov 12, 2009 · 4 comments

Comments

@gopherbot
Copy link
Contributor

by david.titarenco:

What steps will reproduce the problem?
package main

import (
        "http";
        "io";
        "time";
        "fmt";
)

// yuck global :(
var Timeout bool;

//ugly timeout goroutine -- there's probably a better way to do this
func g_Timeout() {
        time.Sleep(25000000000); // 25sec
        Timeout = false;
}

// hello world, the web server
func HelloServer(c *http.Conn, req *http.Request) {
        io.WriteString(c, "Hey there. In 25 seconds I should die...<br>");

        Timeout = true;
        go g_Timeout();
        for Timeout {
           time.Sleep(5000000); // 500ms (non-blocking?)
           io.WriteString(c, ". "); // write to HTTP.Conn buffer
           fmt.Printf("."); // write to stdout
        }
        io.WriteString(c, "I'm done");
}

func main() {
        http.Handle("/test", http.HandlerFunc(HelloServer));
        err := http.ListenAndServe(":9001", nil);
        if err != nil {
                panic("ListenAndServe: ", err.String())
        }
}

What is the expected output? What do you see instead?
I expect the buffer to be drained every write increment (ie every 500ms),
but it appears that there's a certain threshold len(data) needs to reach
before the fd buffer is drained (and I consequently see it in my browser).
I didn't do much digging through the source so there might be a soft-limit
imposed? Correct me if I'm wrong.

What is your $GOOS?  $GOARCH?
GOARCH=386
GOOS=linux

Which revision are you sync'ed to?  (hg log -l 1)
4009:3732030c7584

Please provide any additional information below.
The http package also desperately needs a timeout function (there IS an fd
limit last time I checked :p). As a matter of fact, I might just make one.
@rsc
Copy link
Contributor

rsc commented Nov 12, 2009

Comment 1:

The connection output is buffered but we don't yet have a 
Flush method.  If you'd like to add one, please do, and see
http://golang.org/doc/contribute.html

Owner changed to r...@golang.org.

Status changed to Accepted.

@gopherbot
Copy link
Contributor Author

Comment 2 by david.titarenco:

Patched: http://golang.org/cl/152103

@gopherbot
Copy link
Contributor Author

Comment 3 by david.titarenco:

New CL: http://golang.org/cl/154099

@rsc
Copy link
Contributor

rsc commented Nov 14, 2009

Comment 4:

This issue was closed by revision aebae25.

Status changed to Fixed.

Merged into issue #-.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
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