golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.66k stars 17.62k forks source link

x/net: add Deadline, ReadBuffer, ReadDeadline, WriteBuffer, WriteDeadline getters #13196

Open sparrc opened 8 years ago

sparrc commented 8 years ago

Currently there are the following setter functions in the net package for the IPConn, TCPConn, UDPConn, and UnixConn objects:

SetDeadline(t time.Time) error
SetReadBuffer(bytes int) error
SetReadDeadline(t time.Time) error
SetWriteBuffer(bytes int) error
SetWriteDeadline(t time.Time) error

Under the covers, these all call the unix C setsockopt() function

Since setsockopt has a corresponding getsockopt function, I'm proposing that we add the corresponding Getter functions to the net package, looking something like this:

GetDeadline() (time.Time, error)
GetReadBuffer() (int, error)
GetReadDeadline() (time.Time, error)
GetWriteBuffer() (int, error)
GetWriteDeadline() (time.Time, error)

This shouldn't be too difficult to implement, since the generated zsyscall_*.go files already have the getsockopt function.

This could be useful for debugging and logging information, and for checking if the corresponding Set function needs to be called.

ianlancetaylor commented 8 years ago

Is there any way we could implement these in golang.org/x/net instead?

sparrc commented 8 years ago

@ianlancetaylor Yes, fine with me

rsc commented 8 years ago

I don't think these are generally useful enough to be worth the complexity they would add to the API. "shouldn't be too difficult" and "could be useful" are a very low bar, much lower than what is required for addition to the standard library. If you'd like to add them to x/net/ipv4 and x/net/ipv6, I guess that's fine.