about summary refs log tree commit diff stats
path: root/src/loader
Commit message (Collapse)AuthorAgeFilesLines
* config: clean up/simplifybptato2024-03-172-20/+12
| | | | | | | | | * Parse the default config at runtime. There's no significant performance difference, but this makes it much less painful to write config code. * Add better error reporting * Make fromJS2 easier to use * Unquote ChaPaths while parsing config
* io: add BuferedWriterbptato2024-03-162-58/+76
| | | | | | | | | | Unsurprisingly enough, calling `write` a million times is never going to be very fast. BufferedWriter basically does the same thing as serialize.swrite did, but queues up writes in batches before sending them. TODO: give sread a similar treatment
* pager, loader: add "Save file to" functionalitybptato2024-03-161-19/+53
| | | | | | | As simple as it could be; no download panel yet. Also, remove the xdg-open default mailcap entry; it's better to just save by default.
* loader: add missing flush() callsbptato2024-03-161-1/+4
| | | | | | | Seems wise to flush before e.g. reading. And unwise to enable buffering on tee() even though we disable it on startRequest()
* cgi: fix libexec dir not being setbptato2024-03-161-3/+4
|
* Clean up BufferConfigbptato2024-03-151-2/+3
| | | | | | | | It was defined in the wrong module, and unnecessarily included LoaderClientConfig. Also, referrerPolicy was not being propagated to loader clients because it was (incorrectly) in BufferConfig instead of LoaderClientConfig.
* loader: handle connections where pid/key does not matchbptato2024-03-141-1/+8
| | | | | This can easily happen if a buffer process is killed and/or a new process takes its ID.
* cgi: fix broken pipe handlingbptato2024-03-141-1/+8
| | | | | if the socket is closed before the loader could send all header data, we must destroy the parser to avoid sending a result twice.
* Move around some modulesbptato2024-03-142-2/+2
| | | | | | | | * extern -> gone, runproc absorbed by pager, others moved into io/ * display -> local/ (where else would we display?) * xhr -> html/ * move out WindowAttributes from term, so we don't depend on local from server
* pager: add "open in editor" keybinding (sE)bptato2024-03-141-10/+18
| | | | | | only for source for now, rendered document is a bit more complicated (also, get rid of useless extern/editor module)
* loader: only trap SIGTERMbptato2024-03-141-1/+1
| | | | SIGINT is trapped (well, ignored) by forkserver already.
* loader: fix crash on malformed CGI headersbptato2024-03-142-3/+2
| | | | | Setting istream to nil was preventing finishCycle from unregistering & closing it.
* loader: fix nil deref in parseHeadersbptato2024-03-131-1/+1
|
* client: fix blocking reads on container connectionbptato2024-03-122-29/+19
| | | | | | | | | | | | | | | | Sometimes, headers take a while to reach us even after the result has been sent. e.g. echo 'Cha-Control: Connected' sleep 5 echo 'Cha-Control: ControlDone' ^ this froze the UI for 5 seconds, that's certainly not what we want. Since we don't have a proper buffered reader yet, and I don't want to write another disgusting hack like BufStream, we just use a state machine to figure out how much we can read. Sounds bad, but in practice it works just fine since loader's response patterns are very simple.
* loader: remove applyHeadersbptato2024-03-122-49/+31
| | | | | | | Better compute the values we need on-demand at the call sites; this way, we can pass through content type attributes to mailcap too. (Also, remove a bug where applyResponse was called twice.)
* loader: unregister input streams on EOFbptato2024-03-121-2/+2
| | | | if recvData returns 0, it must be treated the same as a broken pipe.
* loader: rework process modelbptato2024-03-116-440/+659
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Originally we had several loader processes so that the loader did not need asynchronity for loading several buffers at once. Since then, the scope of what loader does has been reduced significantly, and with that loader has become mostly asynchronous. This patch finishes the above work as follows: * We only fork a single loader process for the browser. It is a waste of resources to do otherwise, and would have made future work on a download manager very difficult. * loader becomes (almost) fully async. Now the only sync part is a) processing commands and b) waiting for clients to consume responses. b) is a bit more problematic than a), but should not cause problems unless some other horrible bug exists in a client. (TODO: make it fully async.) This gives us a noticable improvement in CSS loading speed, since all resources can now be queried at once (even before the previous ones are connected). * Buffers now only get processes when the *connection* is finished. So headers, status code, etc. are handled by the client, and the buffer is forked when the loader starts streaming the response body. As a result, mailcap entries can simply dup2 the first UNIX domain socket connection as their stdin. This allows us to remove the ugly (and slow) `canredir' hack, which required us to send file handles on a tour accross the entire codebase. * The "cache" has been reworked somewhat: - Since canredir is gone, buffer-level requests usually start in a suspended state, and are explicitly resumed only after the client could decide whether it wants to cache the response. - Instead of a flag on Request and the URL as the cache key, we now use a global counter and the special `cache:' scheme. * misc fixes: referer_from is now actually respected by buffers (not just the pager), load info display should work slightly better, etc.
* cgi: do not eat first word of the error messagebptato2024-03-071-1/+1
| | | | whoops
* cgi: pass system error message after execl failurebptato2024-03-071-1/+2
|
* loader: fix crash on cha </dev/nullbptato2024-03-031-1/+3
| | | | | | | | | not a very useful operation, but crashing on it is definitely not the correct reaction (hyperfine does this for example. though in that case it's still better to turn it off, otherwise Chawan will pointlessly open a new buffer for it...)
* cgi: fix regression in header handlingbptato2024-03-021-5/+8
| | | | it's a good idea to use the return value, but it must substitute atEnd.
* posixstream: add readLine implementationbptato2024-03-021-6/+4
| | | | | slightly more efficient, but more importantly does not choke on NUL and weird \r\n
* loader: fix early return in handleReadbptato2024-02-272-30/+29
| | | | | | | | Ensure that a) dead outputs do not continue to get more data from istream and b) if all outputs are dead, istream is immediately closed. Also, remove that pointless loop in loadStreamRegular (it did nothing that handleRead did not).
* loader: clean up regular file loadingbptato2024-02-262-104/+105
| | | | | | | | | | | | | | | | | | | | * Get rid of sostream hack This is no longer needed, and was in fact causing loadStream to get stuck with redirects on regular files (i.e. the common case of receiving <file on stdin without a -T content type override). * Unify loading from cache and stdin regular file code paths Until now, loadFromCache was completely sync. This is not a huge problem, but it's better to make it async *and* not have two separate procedures for reading regular files. (In fact, loadFromCache had *another* bug related to its output fd not being added to outputMap.) * Extra: remove ansi2html select error handling It was broken, because it didn't handle read events before the error. Also unnecessary, since recvData breaks from the loop on n == 0.
* buffer: fix rewind with mailcap entriesbptato2024-02-253-5/+30
| | | | | | | | Cache mailcap entry output too, then delete it when the buffer can no longer read from it. (Maybe it would be useful to instead preserve it and allow viewSource for HTML output too? Hmm.)
* loader: only add output fd to outputMap map in addFdbptato2024-02-241-3/+4
| | | | | | | | It is a very bad idea to add it before that, because it could be closed for various reasons without being removed from the map. More concretely, this was causing ghost ostream fds to block istream selects in some cases.
* buffer: improve cancel, use _exit, misc cleanupsbptato2024-02-231-3/+3
| | | | | | * cancel resources on cancel() call * call _exit in signal handler (also in loader) * misc cleanups
* Replace Chakasu with Chagashibptato2024-02-222-11/+9
| | | | | | The API is horrid :( but at least it copies less. TODO: think of a better API.
* so close!bptato2024-02-151-5/+7
| | | | but I forgot to ensure the output stream gets closed. :(
* loader: fix crash on file redirection inputsbptato2024-02-152-16/+60
| | | | | | | | cha -d <some-file was crashing loader, because it was trying to register the regular file in the selector. this patch fixes the problem, but the control flow of loader looks like spaghetti now
* Various refactorings & fixesbptato2024-02-142-68/+6
| | | | | | | | * disallow Stream interface usage on non-blocking PosixStreams * do not read estream of forkserver byte-by-byte (it's slow) * do not call writeData with a zero len in formdata * do not quote numbers in mailcap quoteFile * remove some unused stuff
* loader: fix delOutput bug, remove ErrorWouldBlockbptato2024-02-131-20/+10
|
* loader: fixes & improvementsbptato2024-02-132-121/+79
| | | | | | | | * factor out pushBuffer to make loadFromCache async * fix incorrect cache path * replace rewind with loadFromCache (it does the same thing except actually works) * remove rewindImpl callback, rewind in buffer instead
* stricter typingbptato2024-02-121-3/+4
|
* Add pager.externFilterSourcebptato2024-02-121-5/+13
| | | | useful for filtering stuff through commands like rdrview
* Remove CLONE BufferSource; cache document sources in tmpdirbptato2024-02-126-89/+197
| | | | | | | | | | | | | | | | | | | | | | | At last all BufferSources are unified. To achieve the same effect as the previous CLONE source type, we now use the "fromcache" flag in Request. This *forces* the document to be streamed from the disk; if the file no longer exists for some reason, an error is returned (i.e. the document is not re-downloaded). For a document to be cached, it has to be the main document of the buffer (i.e. no additional resources requested with fetch()), and also not an x-htmloutput HTML file (for those, the original source is saved). The result is that toggleSource now always returns the actual source for e.g. markdown files, not the HTML-transformed version. Also, it is now possible to view the source of a document that is still being downloaded. buffer.sstream has almost been eliminated; it still exists, but only as a pseudo-buffer to interface with EncoderStream and DecoderStream. It no longer holds the entire source of a buffer at any point, and is cleared as soon as the buffer is completely loaded.
* simplify newLoaderBufferbptato2024-02-111-4/+3
|
* loader: significantly more efficient loadingbptato2024-02-112-98/+137
| | | | | | | | | | The previous version was running the processor on 100% because select would immediately return for writes even when no buffers to send were available. (This has been the case since I added asynchronous sending, but the previous commit put the console buffer's fd in loader too and that made the problem quite obvious.)
* Get rid of LOAD_PIPE BufferSourcebptato2024-02-112-40/+78
| | | | | Instead, use a stream: scheme and associate hostnames with file descriptors directly from the pager.
* loader: add rejectHandlebptato2024-02-101-8/+8
|
* loader: fix teebptato2024-02-103-122/+225
| | | | | | | | | | | | My eyes are bleeding, but at least there is a chance that this does what I wanted. The previous tee implementation mixed buffer and loader fds, so it was fundamentally broken. Also, it used MultiStream which makes asynchronous streaming impossible. This time we use a flat array of output handles and link to them any buffers not written to the target yet.
* loader: fixes & cleanupbptato2024-02-102-70/+43
| | | | | | | | | | | * LoaderHandle.fd is no more, we now check ostream's fd * setBlocking converted to a PosixStream method * SocketStream now sets fd variable * handle sostream/fd redirection properly * fix suspend/resume This fixes non-HTML resource loading, mostly. However, tee is still broken :/
* loader: use recvData instead of readDatabptato2024-02-091-16/+15
| | | | | | | | recvData is a new method for PosixStream that does less weird magic than readData. Also, allow duplicates in unregWrite/unregRead; it's simpler to live with them than to prevent them.
* cgi: do not register closed istreamsbptato2024-02-091-1/+2
|
* loader: fix (another) double-close bugbptato2024-02-081-4/+8
|
* loader: fix memory leakbptato2024-02-081-1/+3
|
* loader: fix double-close bugsbptato2024-02-081-3/+3
|
* loader: fix eagain in fetch, only add URL to handle in debugbptato2024-02-082-7/+12
| | | | | | * eagain was causing fetch to add unnecessary null bytes to input streams * URL is now only added to handles in debug mode
* Incremental renderingbptato2024-02-072-51/+152
| | | | | | | | | | | | Yay! Admittedly, it is not very useful in its current form, except maybe on very slow networks. The problem is that renderDocument is *slow*, so we only run it when onload fails to consume all bytes from the network in a single pass. Even then, we are guaranteed to get a FOUC, since CSS is only downloaded in finishLoad(). Well, I think it's cool, anyway.
* loader: clean up error handlingbptato2024-01-263-74/+54
| | | | | | | | | * remove pointless exception -> bool conversions; usually they were ignored anyway + exceptions are more convenient here * add EPIPE handler to raisePosixIOError * fix socketstream to use raisePosixIOError * fix socketstream sendFileHandle error handling * cgi: immediately return on file not found error