about summary refs log tree commit diff stats
path: root/src/io
Commit message (Collapse)AuthorAgeFilesLines
* io: add BuferedWriterbptato2024-03-163-106/+178
| | | | | | | | | | 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
* Move around some modulesbptato2024-03-142-0/+43
| | | | | | | | * 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
* posixstream: do not ignore lseek resultbptato2024-03-121-1/+2
|
* io: add dynstreambptato2024-03-124-55/+92
| | | | | a new abstraction that we derive posixstream from; hopefully with time we can get rid of std/streams
* loader: rework process modelbptato2024-03-114-17/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* posixstream: add readLine implementationbptato2024-03-021-1/+18
| | | | | slightly more efficient, but more importantly does not choke on NUL and weird \r\n
* buffer, client: fix deadlock with send() callsbptato2024-02-292-1/+58
| | | | | | | | | | This is an ancient bug, but it got much easier to trigger with mouse scrolling support so it's time to fix it. (The bug itself was that since both the client and buffer ends of the controlling stream are blocking, they could get stuck when both were trying to send() data to the other end but the buffer was full. So now we set the client end to non-blocking.)
* loader: clean up regular file loadingbptato2024-02-261-1/+0
| | | | | | | | | | | | | | | | | | | | * 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.
* Replace Chakasu with Chagashibptato2024-02-221-1/+7
| | | | | | The API is horrid :( but at least it copies less. TODO: think of a better API.
* Various refactorings & fixesbptato2024-02-142-109/+53
| | | | | | | | * 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-4/+1
|
* io: remove multistream, teestreambptato2024-02-122-74/+0
| | | | unused (hopefully forever)
* Remove CLONE BufferSource; cache document sources in tmpdirbptato2024-02-122-37/+6
| | | | | | | | | | | | | | | | | | | | | | | 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.
* Get rid of LOAD_PIPE BufferSourcebptato2024-02-111-5/+0
| | | | | Instead, use a stream: scheme and associate hostnames with file descriptors directly from the pager.
* loader: fixes & cleanupbptato2024-02-102-3/+12
| | | | | | | | | | | * 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-092-0/+20
| | | | | | | | 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.
* Incremental renderingbptato2024-02-072-3/+18
| | | | | | | | | | | | 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-262-8/+17
| | | | | | | | | * 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
* Use std/* imports everywherebptato2024-01-078-16/+17
|
* Fix some casing issuesbptato2024-01-061-1/+1
|
* Compile with styleCheck:usagesbptato2023-12-281-3/+3
| | | | much better
* buffer: clean up ssock on being killedbptato2023-12-211-0/+3
| | | | | | * use signal handlers to avoid littering tmpdir with dead sockets * add connection reset error (for socketstream) * convert some imports to new style
* socketstream: get rid of emitsbptato2023-12-183-50/+75
| | | | Use .compile, as that is supported by nlvm too.
* socketstream, serversocket: portable bindUnixbptato2023-12-144-10/+50
| | | | | reimplementing it portably in Nim seems incredibly annoying, so we just use C
* reduce new() usagebptato2023-10-252-8/+9
|
* Remove runestreambptato2023-10-221-31/+0
| | | | unused
* socketstream: get rid of pointer arithmeticbptato2023-10-181-2/+4
|
* posixstream: fix buffer overflowbptato2023-09-281-1/+2
|
* buffer: simplify contentType handlingbptato2023-09-271-3/+3
| | | | | | * remove contentType member of Buffer object * add ishtml to reduce string comparisons * consistent spelling: contenttype -> contentType
* regex: copy after compilingbptato2023-09-241-25/+0
| | | | | | | | | | | | Instead of the broken attempt at making regexes zero-copy (it copied anyway), copy once and forget about it. (There have been way too many problems with the destructor approach, including the latest one where the GC would happily zero out our regexes if they were in a sequence. Maybe we can make this work once we switched to ORC. For now, it's not worth the trouble.)
* buffer: make clone fork()bptato2023-09-232-0/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Makes e.g. on-page anchor navigation near-instantaneous. Well, as instantaneous as a fork can be. In any case, it's a lot faster than loading the entire page anew. This involves duplicating open resources (file descriptors, etc.), which is not exactly trivial. For now we have a huge clone() procedure that does an ok-ish job at it, but there remains a lot of room for improvement. e.g. cloning is still broken in some cases: * As noted in the comments, TeeStream'ing the input stream for any buffer is a horrible idea, as readout in the cloned buffer now depends on the original buffer also reading from the stream. (So e.g. if you clone, then kill the old buffer without waiting for the new one to load, the new buffer gets stuck.) * Timeouts/intervals are broken in cloned buffers. The timeout module probably needs a redesign to fix this. * If you clone before connect2, the cloned buffer gets stuck. The previous solution was even worse (i.e. broken in more cases), so this is still an improvement. For example, this fixes some issues with mailcap handling (removes the "set the Content-Type of htmloutput buffers to text/html" hack), does not reload all resources, does not completely break if the buffer is cloned during loading, etc.
* response: add blob() functionbptato2023-09-171-2/+3
|
* Fix compilation with --assertions:offbptato2023-09-151-1/+2
| | | | | Remove side effects from assert statements. The flag is not used currently, but let's not depend on that.
* move around more modulesbptato2023-09-1417-1753/+620
| | | | | | | | | | * ips -> io/ * loader related stuff -> loader/ * tempfile -> extern/ * buffer, forkserver -> server/ * lineedit, window -> display/ * cell -> types/ * opt -> types/
* remove obsolete commentbptato2023-09-091-1/+0
|
* fetch: use JSDictbptato2023-09-092-43/+136
|
* loader: get rid of xdeclaredbutnotused warningbptato2023-09-071-0/+1
| | | | | sig is injected into the template body, but then never used, so we discard it.
* Fix compilation < Nim 2.0bptato2023-09-041-1/+1
| | | | Before Nim 2.0, addr could only be used with mutable variables.
* loader, data: remove stray eprintsbptato2023-09-022-4/+0
|
* loader: add data URLsbptato2023-09-014-5/+66
|
* javascript: factor out fromJSbptato2023-08-292-0/+2
|
* refactor: Result[T, JSError] -> JSResult[T]bptato2023-08-282-8/+7
|
* javascript: refactorbptato2023-08-283-4/+7
| | | | | | | Split out parts of the JS module, because it was starting to confuse the compiler a little. (Peakmem is back at 750M. Interesting.)
* Move charsets into chakasubptato2023-08-143-5/+8
| | | | Operation "modularize Chawan somewhat" part 1
* Add mailcap, mime.types & misc refactoringsbptato2023-08-1310-164/+302
| | | | | | | | * add mailcap: works with copiousoutput, needsterminal, etc. * add mime.types (only works with mailcap) * refactor pipeBuffer * remove "dispatcher" * fix bug in directory display where baseurl would not be used
* Fixes & workarounds to compile on Nim 2.0.0bptato2023-08-012-1/+4
| | | | | | | | | | | | | | * Import punycode, as it has been removed from stdlib. * Fix some syntax errors * Apparently you can no longer compare distinct pointers with nil. Add explicit comparisons with typeof(nil) instead. * htmlparser: rename _ to other, as semantics of _ have changed. (Quite a shame, it looked better with _. Oh well.) * Explicitly specify mm:refc, as the browser OOMs with orc for some reason. Confirmed to compile & run on 2.0.0, 1.6.14, 1.6.12, 1.6.10 and 1.6.8. (<1.6.8 it's broken & wontfix.)
* Improve encoding supportbptato2023-07-122-33/+63
| | | | | | | | * Use the output charset in lineedit (as w3m does) * encoder: fix broken UTF-8 encoding, use openArray instead of var seq for input queue * Add RuneStream as an in-memory interface to EncoderStream * Document display-charset config option
* Buffer search fixes & improvementsbptato2023-07-111-9/+17
| | | | | * Fix race condition in updateReadLineISearch * Disable reshape during isearch
* Add proxy supportbptato2023-07-041-0/+6
|
* Add platform object conversion to union typebptato2023-07-022-17/+48
| | | | And with that, implement Request constructor with a Request init.