smol-rs / polling

Portable interface to epoll, kqueue, event ports, and wepoll
Apache License 2.0
551 stars 68 forks source link

Add support for PS Vita #160

Closed notgull closed 6 months ago

notgull commented 1 year ago

Related: https://github.com/tokio-rs/mio/pull/1721

This will probably need to be tacked onto the poll() backend like ESP-IDF is.

nikarh commented 1 year ago

Hi, I will be glad to help with this target, although this will require porting rustix first

sunfishcode commented 1 year ago

rustix 0.38.20 now compiles under armv7-sony-vita-newlibeabihf.

notgull commented 11 months ago

@nikarh You said you wanted to help for this target; any updates on this?

nikarh commented 11 months ago

@nikarh You said you wanted to help for this target; any updates on this?

Hi, sorry for the delay. I haven't started working on it yet. I'm vacating till Christmas, but after that, I'll have some free time and do it.

mamaicode commented 6 months ago

Will attempt this one

nikarh commented 6 months ago

The last time I checked almost everything worked, except for the waker. There was a problem here https://github.com/smol-rs/polling/blob/1c16a1e4affaecc9e1f149c5d00133624b268405/src/poll.rs#L225C40-L225C56

As far as I remember, this code assumes that if it writes to the pipe, the message becomes immediately available on the other side of the pipe (pop_notification does a read syscall on a NONBLOCK pipe).

On Vita message written to pipe is not immediately available for read after calling write on the other side of the pipe.

This is because Vita doesn't have a syscall that could poll both network sockets and pipes, so pipes in the Vita newlib are implemented (or more like mocked) as a net socket on a loopback, because this implementation is much simpler than reimplementing poll as a custom busy loop with multiple syscalls for different fd types.

TBH I am not sure how to solve this - we can either make pipes and poll more sensible in Vita newlib (a lot of work), or make some specific code branch for vita in this crate, which may not be something worth the maintenance burden

mamaicode commented 6 months ago

@nikarh Thank you for pointing it out before I got started! Which decision do we go with? keep me posted

notgull commented 6 months ago

On Vita message written to pipe is not immediately available for read after calling write on the other side of the pipe.

Could this be solved by blocking on the read instead of using NONBLOCK?

nikarh commented 6 months ago

On Vita message written to pipe is not immediately available for read after calling write on the other side of the pipe.

Could this be solved by blocking on the read instead of using NONBLOCK?

Yes, I made a PR with just that. With this PR all tests actually pass on Vita (except for many_connections due to severely limited max fd count on the platform, but changing 100 to something like 60 makes it pass)

@mamaicode Sorry for stealing this from you 🙏 I had this code stashed locally on my machine and wasn't sure about making a PR since the solution is kinda ugly.