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: export writeBuffers() and buffersWriter #21756

Closed
gobwas opened this issue Sep 4, 2017 · 5 comments
Closed

net: export writeBuffers() and buffersWriter #21756

gobwas opened this issue Sep 4, 2017 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@gobwas
Copy link

gobwas commented Sep 4, 2017

Hello!

Looking at net.Buffers.WriteTo() implementation one can find that it uses type assertion to non-exported type net.buffersWriter. The proposal is to export this type and methods which implement it.

Two things:

  1. When someone wants to wrap net.Conn to get some i/o statistics, say:
type ConnWatcher struct {
    c net.Conn
    n int64
}
func (c *ConnWatcher) Write(p []byte) (int, error) {
    n, err := c.conn.Write(p)
    c.n += int64(n)
    return n, err
}

It becomes impossible to use writev() syscall – ConnWatcher has no way to implement non-exported net.buffersWriter interface.

  1. When someone wants to wrap concrete *net.TCPConn (rare case, but possible) to decorate some write behaviour:
type CipherConn struct {
    *net.TCPConn                                
    Encode func([]byte) []byte
}
func (c CipherConn) Write(p []byte) (int, error) {
    return c.TCPConn.Write(c.Encode(p))
}

// Somewhere in the application.
var bs net.Buffers
var cc CipherConn
bs.WriteTo(cc) 

The last line of the example above bs.WriteTo(cc) will produce cc.TCPConn.writeBuffers(bs) call, sending raw data without encoding.

Regards,
Sergey.

@gobwas gobwas changed the title net: export writeBuffers() method net: export writeBuffers() and bufferWriter Sep 4, 2017
@gobwas gobwas changed the title net: export writeBuffers() and bufferWriter net: export writeBuffers() and buffersWriter Sep 4, 2017
@funny-falcon
Copy link
Contributor

Hidden behavior that is difficult to use right.

@odeke-em
Copy link
Member

odeke-em commented Sep 4, 2017

Looks similar to #21676 in which @zombiezen talks about how frustrating it is that writeBuffers is unexported.

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 30, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Mar 30, 2018
@gobwas gobwas closed this as completed May 8, 2018
@gobwas gobwas reopened this May 8, 2018
@gobwas
Copy link
Author

gobwas commented May 8, 2018

Sorry, for open/reopen spam ) Should I close it as a duplicate or keep it opened until Go1.11?

@ianlancetaylor
Copy link
Contributor

The two seem slightly different, let's keep them both for now.

@ianlancetaylor ianlancetaylor modified the milestones: Go1.11, Go1.12 Jun 27, 2018
@ianlancetaylor
Copy link
Contributor

After more thought, closing as dup of #21676 .

@golang golang locked and limited conversation to collaborators Dec 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants