wasip2: Deduplicate stream code in read/write/TCP#735
wasip2: Deduplicate stream code in read/write/TCP#735alexcrichton wants to merge 1 commit intoWebAssembly:mainfrom
Conversation
| if (entry->vtable->recvfrom != NULL) | ||
| return entry->vtable->recvfrom(entry->data, buf, nbyte, 0, NULL, NULL); | ||
|
|
||
| bool ok = false; | ||
|
|
||
| // Translate the file descriptor to an internal handle | ||
| streams_borrow_input_stream_t input_stream; | ||
| off_t *off; | ||
| if (__wasilibc_read_stream(fildes, &input_stream, &off, NULL) < 0) |
There was a problem hiding this comment.
Previously read would use recvfrom, if present in the vtable - that does not seem to be the case anymore - isn't this a breaking change for wasi-libc users?
From the limited research I've done, it seems that read and write are expected to behave just as recv and send on connected sockets:
The only difference between recv() and read(2) is the presence of
flags. With a zero flags argument, recv() is generally equivalent
to read(2) (but see NOTES).
https://www.man7.org/linux/man-pages/man2/recv.2.html
The send() call may be used only when the socket is in a connected
state (so that the intended recipient is known). The only
difference between send() and write(2) is the presence of flags.
With a zero flags argument, send() is equivalent to write(2).
https://www.man7.org/linux/man-pages/man2/send.2.html
Shouldn't the UDP implementation set the get_read_stream accordingly in the vtable here
wasi-libc/libc-bottom-half/sources/wasip2_udp.c
Lines 892 to 911 in d974bce
read regression?
There was a problem hiding this comment.
This was added pretty recently in #734 so not a breaking change in that sense (hasn't shipped anywhere). That's true though that it would mean that read/write wouldn't work on UDP. Unfortunately this can't implement get_{read,write}_stream for UDP sockets beacuse they have a different primitive under the hood.
Do you know whether native libc/linux supports read or write on UDP sockets? I would have assumed not but I could very well be wrong...
There was a problem hiding this comment.
Using read & write is perfectly fine on a connected UDP socket and are equivalent to recv & send without flags
| if (!entry) | ||
| return -1; | ||
| if (entry->vtable->sendto != NULL) | ||
| return entry->vtable->sendto(entry->data, buf, nbyte, 0, NULL, 0); |
There was a problem hiding this comment.
Like above, looks like UDP implementation should set get_write_stream to avoid regression here?
This commit extends the support in WebAssembly#734 by deduplicating the separate paths for reading a stream shared between `read` and `recvfrom`, for example. The `get_{read,write}_stream` methods now return more metadata and the TCP `recvfrom` implementation delegates to an internal `__wasilibc_read` to perform the actual read. This opens up the door to supporting nonblocking reads/writes on other streams in the future, for example.
7e001b7 to
3aed548
Compare
This commit extends the support in #734 by deduplicating the separate paths for reading a stream shared between
readandrecvfrom, for example. Theget_{read,write}_streammethods now return more metadata and the TCPrecvfromimplementation delegates to an internal__wasilibc_readto perform the actual read. This opens up the door to supporting nonblocking reads/writes on other streams in the future, for example.