From dc50c2b7927c953d46ea87dfea2a8faedf121870 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Wed, 2 Aug 2023 21:16:18 +0200 Subject: [PATCH] Improve comments in code Signed-off-by: Edoardo Vacchi --- imports/wasi_snapshot_preview1/poll.go | 11 +++++++---- imports/wasi_snapshot_preview1/poll_test.go | 4 ---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/imports/wasi_snapshot_preview1/poll.go b/imports/wasi_snapshot_preview1/poll.go index fdc04d63f2..4248e81f33 100644 --- a/imports/wasi_snapshot_preview1/poll.go +++ b/imports/wasi_snapshot_preview1/poll.go @@ -28,6 +28,7 @@ import ( // - sys.ENOTSUP: a parameters is valid, but not yet supported. // - sys.EFAULT: there is not enough memory to read the subscriptions or // write results. +// - sys.EINTR: an OS interrupt has occurred while invoking the syscall. // // # Notes // @@ -95,6 +96,8 @@ func pollOneoffFn(_ context.Context, mod api.Module, params []uint64) sys.Errno // The timeout is initialized at max Duration, the loop will find the minimum. var timeout time.Duration = 1<<63 - 1 // Count of all the subscriptions that have been already written back to outBuf. + // nevents*32 returns at all times the offset where the next event should be written: + // this way we ensure that there are no gaps between records. nevents := uint32(0) // Layout is subscription_u: Union @@ -136,14 +139,14 @@ func pollOneoffFn(_ context.Context, mod api.Module, params []uint64) sys.Errno evt.errno = wasip1.ErrnoBadf writeEvent(outBuf[outOffset:], evt) nevents++ - } else if !file.File.IsNonblock() { + } else if file.File.IsNonblock() { + writeEvent(outBuf[outOffset:], evt) + nevents++ + } else { // If the fd is blocking, do not ack yet, // append to a slice for delayed evaluation. fe := &filePollEvent{f: file, e: evt} blockingSubs = append(blockingSubs, fe) - } else { - writeEvent(outBuf[outOffset:], evt) - nevents++ } case wasip1.EventTypeFdWrite: fd := int32(le.Uint32(argBuf)) diff --git a/imports/wasi_snapshot_preview1/poll_test.go b/imports/wasi_snapshot_preview1/poll_test.go index 507d45875c..a2d5291da7 100644 --- a/imports/wasi_snapshot_preview1/poll_test.go +++ b/imports/wasi_snapshot_preview1/poll_test.go @@ -416,7 +416,6 @@ func Test_pollOneoff_Mixed(t *testing.T) { tests := []struct { name string - skip bool in, out, nsubscriptions, resultNevents uint32 connected, nonblocking bool mem []byte // at offset in @@ -620,9 +619,6 @@ func Test_pollOneoff_Mixed(t *testing.T) { tc := tt t.Run(tc.name, func(t *testing.T) { - if tc.skip { - t.Skip() - } ctx := sock.WithConfig(testCtx, sock.NewConfig().WithTCPListener("127.0.0.1", 0))