Issue 1:
Forwarded conversation
Subject: [golang-dev] unsafe.Sizeof
------------------------

From: Anthony Martin <ality@pbrane.org>
Date: Sat, Jun 4, 2011 at 13:10
To: golang-dev@googlegroups.com

I've been working out some issues in the compiler related to
types with very large sizes and I'm almost ready to send out
a CL. Before doing so, however, I'd like some clarification
on the intended semantics of unsafe.Sizeof.

Should unsafe.Sizeof be able to represent the size of every
valid type and if so, should we allow types larger than the
maximum positive signed 32-bit integer?

Right now, there are a few parts of the compiler that are a
bit too cavalier with the width of a type.

Thanks,
Anthony

----------
From: Ian Lance Taylor <iant@google.com>
Date: Sat, Jun 4, 2011 at 16:20
To: Anthony Martin <ality@pbrane.org>
Cc: golang-dev@googlegroups.com

My opinion: Yes. No. (Or, rather, we should not allow types larger
than the size of int, which is currently 32 bits.)

Ian

----------
From: Russ Cox <rsc@golang.org>
Date: Tue, Jun 7, 2011 at 14:51
To: Ian Lance Taylor <iant@google.com>
Cc: Anthony Martin <ality@pbrane.org>, golang-dev
<golang-dev@googlegroups.com>

I think unsafe.Sizeof should return uintptr.
It's possible that unsafe.Alignof should too.
This would be a language change.

----------
From: Ian Lance Taylor <iant@google.com>
Date: Tue, Jun 7, 2011 at 15:45
To: rsc@golang.org
Cc: Anthony Martin <ality@pbrane.org>, golang-dev
<golang-dev@googlegroups.com>

Works for me.

Ian

----------
From: Rob 'Commander' Pike <r@google.com>
Date: Fri, Jun 10, 2011 at 03:22
To: Ian Lance Taylor <iant@google.com>
Cc: rsc@golang.org, Anthony Martin <ality@pbrane.org>, golang-dev
<golang-dev@googlegroups.com>

LGTM

Issue 2:
I regret having to bring up anything related to sockets. I hate them as much as the next gopher.

There are some cases[1] where setting socket options (like SO_REUSEPORT) is just unavoidable. In most cases, we can pull out the conn.File() and set them. But those few annoying cases where the option must be set on the socket before listening or dialing are impossible to handle with today's net package. (please tell me i'm wrong!)

"Setting the socket up yourself" is not a good option. Getting sockets right is not trivial-- there are bound to be dozens of tricky corner cases across platforms. I gave it a shot, but I keep finding problems in various OSes. It would be much more user friendly to stick to the net interface which already had to do all this hard work.

Now, I would even go as far as to copy the net package wholesale just to add this feature, but AFAIK the existence of the runtime· functions makes this also impossible (such a netcopy wont compile). Without them, we're left up to whittling down netcopy (and exchanging the runtime polling for select/epoll/ugliness) , most likely introducing more bugs.

A nice way to solve this -- I think -- is to make listeners and dialers have "tuners", as implemented in https://github.com/benburkert/net.tune/ [3]. This approach is based on rob's self-referential functions, and manages to contain the ugly, exposing a nice interface.[4] But I imagine there are many other approaches that are even nicer and idiomatic.

I know-- the stdlib is trying to contain the ugly as much as possible and prevent it from spreading. But in this type of case, the current state of affairs brings it out more for some of us.

[1] One example: being able to dial out from the same TCP port you're listening on is a requirement for some kinds of NAT traversal.

[2] There's issues in this very tracker showing years of tuning the use of sockets.

[3] Specifically: https://github.com/benburkert/net.tune/blob/master/dial.go#L59-L63

[4] It could be done with new functions -- or if the goal is to keep the interface thin, a variadic argument to the existing functions should be backwards compatible.