-
Notifications
You must be signed in to change notification settings - Fork 163
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
Avoid cgo in lib/overlay/conn to simplify cross-compilation #3064
Conversation
@kormat asked for documentation that I could not find any actual documentation (I find golang documentation to be rather lackluster). Still, this seems rather safe. Looking at the various This is the complete list of
This corresponds to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not 100% comfortable. For example:
- The go std lib seems to always (or at least as far as i could find from a quick search) use
C.sizeof...
for this. - I've found at least one issue in the past where the unsafe.Sizeof value for a given C struct changed between go versions: cmd/cgo: size of struct with 0 length trailing field has changed golang/go#11925
Reviewable status: 0 of 3 files reviewed, all discussions resolved
It seems unlikely to me that this could be an issue as timespec is a particularly simple data type. Regardless, as the in our case the sizeof is only used to allocate a big enough buffer, maybe a compromise could be to explicitly use a constant size that can be expected to be >= Btw. looking at the documentation for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work you've done looking into this. <3
I've been doing some research, and discovered some interesting things
time_t
isn't guaranteed to be an integer(!) in the spec (though practically that's not a concern)struct timespec
isn't uniformly a struct containing two same-sized ints:syscall.Timespec
is not a C struct.cgo -godefs
is used to generate native Go struct: https://github.com/golang/go/blob/03ac39ce5e6af4c4bca58b54d5b160a154b7aa0e/src/syscall/ztypes_linux_amd64.go#L24-L27
So, yeah, i'm happy to go with your approach.
Btw. looking at the documentation for SO_RXQ_OVFL (the other value that is requested into/read from the oob), the value is defined as a 32-bit integer but it's currently read as a golang int. Is that intentional or a typo?
That's definitely my mistake. If you could fix that in this PR too, that would be great.
(I even double-checked the kernel source, because the docs for the option also say that it's:
the number of packets dropped by the socket between the last received packet and this received packet
which is incorrect. The counter is never reset)
Reviewed 2 of 3 files at r1, 1 of 1 files at r2.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @matzf)
go/lib/overlay/conn/conn.go, line 42 at r2 (raw file):
const ReceiveBufferSize = 1 << 20 var sizeOfInt64 = int(unsafe.Sizeof(int64(0)))
Proposal:
const sizeOfRxOverflow = 4 // Defined to be uint32
2bd4f5c
to
8c7c47d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's definitely my mistake. If you could fix that in this PR too, that would be great.
Done.
struct timespec
isn't uniformly a struct containing two same-sized ints
I was surprised by that too, but then it actually makes a lot of sense (on 32-bit systems anyway), as the number of nanoseconds per second is somewhat fixed ;)
Reviewable status: 2 of 4 files reviewed, 1 unresolved discussion (waiting on @kormat)
go/lib/overlay/conn/conn.go, line 42 at r2 (raw file):
Previously, kormat (Stephen Shirley) wrote…
Proposal:
const sizeOfRxOverflow = 4 // Defined to be uint32
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r3.
Reviewable status:complete! all files reviewed, all discussions resolved
cgo was only required to get a portable struct timespec. The `syscall.Timespec` struct seems to provide this type just as well, without requiring cgo.
Value returned is defined to be an uint32. Propagate uint32 type to RcvOvfl member of ReadMeta, as uint32 value can overflow int on 32-bit platforms. Gracefully handle (unlikely) wrap-around of counter values in diagnostics messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r4.
Reviewable status:complete! all files reviewed, all discussions resolved
…to#3064) cgo was only required to get a portable struct timespec. The `syscall.Timespec` struct to provides this type just as well, without requiring cgo. Also: - Fix SO_RXQ_OVFL to be uint32 as it is defined, and handle wrap-around of the value.
cgo was only required to get a portable struct timespec.
The
syscall.Timespec
struct seems to provide this type just as well, without requiring cgo.This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)