For discussion: net: consolidate common socket functions

61 views
Skip to first unread message

Dave Cheney

unread,
Apr 21, 2012, 12:09:48 AM4/21/12
to golang-dev
Hello,

In resolving 3507, the fix had to be applied individually to the four
*Conn types, tcp, udp, rawip and unix, due to the duplicate code in
each Conn type.

I'd like to present a CL for discussion which consolidates the common
net.Conn methods that all four *Conn types implement into a base conn
type.

http://codereview.appspot.com/6098047/

Pros:
* The fix for 3507 would have only needed to be applied to one method.
Further improvements, such as possibly removing the c.fd != nil check
in c.ok(), would benefit from this CL.
* Nearly 300 lines removed from the net package.
* The public interface and documentation are not changed.
* I think this is an excellent example of the power of embedding.

Cons:
* The net package is already distributed over many files, this CL adds
another place to look.
* The fix for 3507 was a total of 16 lines changed, this follow up CL
could be considered to be an overreaction as new Conn types are
unlikely to be added in the near future.

I look forward to your comments.

Cheers

Dave

Brad Fitzpatrick

unread,
Apr 21, 2012, 1:02:51 AM4/21/12
to Dave Cheney, golang-dev
Seems fine to me at least.  And net negative LOC.

Mikio Hara

unread,
Apr 21, 2012, 7:39:48 AM4/21/12
to Dave Cheney, golang-dev
LGTM.

Perhaps filename net_posix.go might be better than sock_posix.go
because type conn bridges a gap btw netFD and ProtocolConn.

-- Mikio

Dave Cheney

unread,
Apr 21, 2012, 7:46:38 AM4/21/12
to Mikio Hara, golang-dev
> Perhaps filename net_posix.go might be better than sock_posix.go
> because type conn bridges a gap btw netFD and ProtocolConn.

Certainly, a much better suggestion than sock_posix.go. Please take
another look.

Russ Cox

unread,
Apr 23, 2012, 9:58:58 AM4/23/12
to Dave Cheney, Mikio Hara, golang-dev
The main reason for the duplication was that godoc did not show
the documentation for the embedded methods. I believe that's
fixed, but can you please confirm that?

Russ

Dave Cheney

unread,
Apr 23, 2012, 5:10:14 PM4/23/12
to r...@golang.org, Mikio Hara, golang-dev
Yes, godoc now works as expected in the presence of embedded methods.
I have confirmed this visually with two browser windows before and
after this patch.

Thank you to everyone for their feedback on this proposal. I'll finish
6098047 and post it for review tomorrow.

Cheers

Dave
Reply all
Reply to author
Forward
0 new messages