fix: ports - netsurf renders pages (mmap, resources, error loop)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NQRTGoYgnZQsh7uCh6Jsxm
This commit is contained in:
@@ -11,19 +11,20 @@
|
||||
* NETSURF_USE_CURL=NO no fetcher registers a descriptor, so the only fd that
|
||||
* ever appears is the monkey frontend's stdin (fd 0).
|
||||
*
|
||||
* That makes a useful shim possible:
|
||||
* That makes a useful shim possible: fd 0 is answered from the libc's
|
||||
* montauk_stdin_ready(), which reports whether a COMPLETE line is buffered.
|
||||
* That is the readiness question monkey is really asking -- it goes on to call
|
||||
* fgets(), so reporting "readable" on a half-typed line would park the whole
|
||||
* browser inside stdio until Enter. With no line pending we sleep out the
|
||||
* caller's timeout and return 0, which lets the core's scheduled callbacks run
|
||||
* to completion: a fetch takes many main-loop iterations, and under the old
|
||||
* always-ready shim it got exactly one per line typed.
|
||||
*
|
||||
* - if any read descriptor is requested, report them ready immediately and
|
||||
* let the caller block in read(). monkey is a line-driven REPL, so
|
||||
* blocking on stdin is what it wants anyway.
|
||||
* - otherwise sleep for the timeout so an idle loop does not spin.
|
||||
*
|
||||
* LIMITATION: because a requested read fd is always reported ready, scheduled
|
||||
* callbacks do not fire while the process sits idle waiting for a command.
|
||||
* That is fine for driving monkey by hand or by script, and it is wrong for
|
||||
* anything with real network activity. When fetch_montauk lands it will
|
||||
* register descriptors here and this needs replacing with a genuine
|
||||
* waitset-backed implementation.
|
||||
* LIMITATION: only fd 0 has a readiness source. Any other read descriptor is
|
||||
* still reported ready unconditionally, and write/except sets are always
|
||||
* empty. With NETSURF_USE_CURL=NO no fetcher registers a descriptor, so fd 0
|
||||
* is the only one that ever appears. When fetch_montauk lands it will register
|
||||
* descriptors here and this needs a genuine waitset-backed implementation.
|
||||
*/
|
||||
#ifndef _MONTAUK_COMPAT_SYS_SELECT_H_
|
||||
#define _MONTAUK_COMPAT_SYS_SELECT_H_
|
||||
@@ -31,6 +32,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define FD_SETSIZE 64
|
||||
|
||||
@@ -80,6 +82,7 @@ static inline int montauk_fdset_count(const fd_set *s, int nfds)
|
||||
static inline int select(int nfds, fd_set *readfds, fd_set *writefds,
|
||||
fd_set *exceptfds, struct timeval *timeout)
|
||||
{
|
||||
int stdin_wanted;
|
||||
int ready;
|
||||
|
||||
if (writefds != NULL)
|
||||
@@ -87,21 +90,57 @@ static inline int select(int nfds, fd_set *readfds, fd_set *writefds,
|
||||
if (exceptfds != NULL)
|
||||
FD_ZERO(exceptfds);
|
||||
|
||||
if (montauk_fdset_empty(readfds) == 0) {
|
||||
/* leave readfds as-is: every requested fd is "ready" */
|
||||
return montauk_fdset_count(readfds, nfds);
|
||||
stdin_wanted = (readfds != NULL) && (nfds > 0) && FD_ISSET(0, readfds);
|
||||
if (stdin_wanted) {
|
||||
FD_CLR(0, readfds);
|
||||
if (montauk_stdin_ready()) {
|
||||
FD_SET(0, readfds);
|
||||
}
|
||||
}
|
||||
|
||||
ready = 0;
|
||||
/*
|
||||
* Descriptors other than stdin have no readiness source here, so they
|
||||
* keep the old unconditional-ready answer.
|
||||
*/
|
||||
ready = montauk_fdset_count(readfds, nfds);
|
||||
if (ready > 0)
|
||||
return ready;
|
||||
|
||||
if (timeout != NULL) {
|
||||
if (timeout == NULL) {
|
||||
/*
|
||||
* The core has nothing scheduled ("POLL BLOCKING"), so blocking
|
||||
* for a command is right -- and returning 0 here instead would
|
||||
* spin the CPU at 100%.
|
||||
*/
|
||||
if (stdin_wanted && montauk_stdin_wait()) {
|
||||
FD_SET(0, readfds);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
{
|
||||
unsigned long usec = (unsigned long) timeout->tv_sec * 1000000UL +
|
||||
(unsigned long) timeout->tv_usec;
|
||||
if (usec != 0)
|
||||
usleep(usec);
|
||||
|
||||
/*
|
||||
* Sleep in slices rather than one long usleep: a scheduled
|
||||
* timeout can be seconds long, and typing must not wait it out.
|
||||
*/
|
||||
while (usec > 0) {
|
||||
unsigned long slice = (usec > 5000UL) ? 5000UL : usec;
|
||||
|
||||
usleep(slice);
|
||||
usec -= slice;
|
||||
|
||||
if (stdin_wanted && montauk_stdin_ready()) {
|
||||
FD_SET(0, readfds);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ready;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user