bytecodealliance/jco

Should readViaStream/writeViaStream check fd is in descriptors list?

Closed this issue · 3 comments

Both readViaStream:

readViaStream(fd, offset) {

and writeViaStream:

writeViaStream(fd, offset) {

Check the fd is in the descriptors list before proceeding (otherwise they throw 'bad-descriptor'):

However, since both these functions use ReadableFileStream/WriteableFileStream and use the hostFd:

constructor (hostFd, position) {

Do we need this check? Aren't they just dealing with reading/writing to host files via stream, and there is no need for check here?

I think i may have got this wrong way round, if it's for reading from WASI VM, as opposed to opening stream from host.

These are good questions, although with the migration to resources, this will no longer be a concern, since all descriptor resources will by definition be valid resources.

Closing as we have now migrated to resources, thank you for taking a look and raising the implementation question though.