rpc/timeoutconn: platform-independent sizes for computing syscall.Iovec.Len

refs #184
This commit is contained in:
Christian Schwarz
2019-06-11 12:19:12 +02:00
parent 95e16f01c1
commit 254a292362
2 changed files with 36 additions and 9 deletions

View File

@ -5,8 +5,10 @@ import (
"io"
"net"
"sync"
"syscall"
"testing"
"time"
"unsafe"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -176,3 +178,14 @@ func TestNoPartialWritesDueToDeadline(t *testing.T) {
require.True(t, ok)
assert.True(t, netErr.Timeout())
}
func TestIovecLenFieldIsMachineUint(t *testing.T) {
iov := syscall.Iovec{}
_ = iov // make linter happy (unsafe.Sizeof not recognized as usage)
size_t := unsafe.Sizeof(iov.Len)
if size_t != unsafe.Sizeof(uint(23)) {
t.Fatalf("expecting (struct iov)->Len to be sizeof(uint)")
}
// ssize_t is defined to be the signed version of size_t,
// so we know sizeof(ssize_t) == sizeof(int)
}