about summary refs log tree commit diff stats
path: root/src/io
Commit message (Collapse)AuthorAgeFilesLines
* More strict defsbptato2025-01-141-27/+33
|
* dynstream: remove superfluous zeroMem, add sendFds/recvFdsbptato2025-01-123-26/+33
|
* buffer, dynstream: fix clone race, recvmsg/sendmsg castbptato2025-01-121-3/+3
| | | | | | | The fds must be read before the other buffer resumes execution. Also, for some reason, CMSG_SPACE/CMSG_LEN are inconsistent in their size with controllen on BSDs...
* Fix some strict defsbptato2025-01-121-5/+5
|
* bufreader, bufwriter: send all fds in one messagebptato2025-01-114-163/+72
| | | | | | | | Moves sendfd/recvfd out of C, and fixes some of its flaws too. The main one is that now all file descriptors are sent together. Also, I've decided to remove the ServerSocket after all; it's easy to add it back if it's ever needed again.
* buffer: remove server socketbptato2025-01-092-85/+18
| | | | | | | | | | | Now we just pass through a socket created in pager. This removes the need for a socket directory, and strengthens the buffer sandbox slightly. I've kept the ServerSocket code, because I want to add some form of RPC and communication between separate instances in the future. However, I don't expect this to be handled outside the main process, so I've removed the Capsicum-specific connectat/bindat code.
* dynstream: remove safeClose, add moveFdbptato2025-01-091-10/+9
| | | | | | | | | | | | | | | | | | | safeClose was originally added to prevent this bug: let fd = doSomething() # allocates fd on 0, e.g. by opening a socket let ps = newPosixStream(fd) ... discard dup2(ps.fd, STDIN_FILENO) ps.sclose() # stdin is now closed, despite the opposite intention. With safeClose called on fds that could be stdin, the goal was that stdin/stdout/stderr would never be allocated as a different file, but it was still error-prone. Enter moveFd: ps.moveFd(STDIN_FILENO) If ps is already stdin, this does nothing. If not, it dup2's ps to stdin, closes ps.fd, and sets it to stdin.
* bufstream: allow 0-width packetsbptato2025-01-092-6/+6
|
* loader: use per-process control socketsbptato2025-01-083-10/+11
| | | | | | | | | | | | | | | | | | | | | | | | Previously, each message (load, resume, passFd, etc.) would open a new connection to loader's UNIX socket, and assumed the loader was dead when the loader did not respond (ECONNREFUSED). As it turns out, this model was hopelessly broken: POSIX does not specify when a UNIX socket can refuse connections, so while it happened to work on Linux (which just blocks if it can't accept right now), FreeBSD would randomly refuse connections whenever its listen queue was full. Instead, we now take a socketpair() from the loader in addClient, and pass on one half to the client (the other half stays in loader); this is the control stream, and all messages from the specific client are sent through it. If a message includes a new stream (e.g. lcLoad), then it sends a new socketpair through the control stream. Aside from not being completely broken (and being marginally more efficient), this arrangement has several other benefits: it removes the need for authentication, almost removes the need for sockdir (now only buffers use it), and will make it easier to add async message processing in the future.
* dynstream: simplify, fix fd leakbptato2025-01-081-9/+5
|
* Try to set close-on-exec, misc cleanupbptato2025-01-041-14/+13
| | | | | | | | | | FD_CLOEXEC should hopefully get rid of bugs where buffers outlived the main process because of some stray child process keeping the canary pipe alive. It's not perfect because of the runMailcapWriteFile/runMailcapReadFile double-forks. Ideally they should be replaced with an implementation that tracks temporary files in the main process.
* default(T) -> T.default, add some strict defsbptato2024-12-172-4/+4
|
* chabookmark fixes & improvementsbptato2024-12-151-0/+2
| | | | | | | | * correct action on M-b * add external.bookmark option * move openFileExpand functionality into unquote * add menu items * update docs
* pager, mailcap: misc fixes, add prompt for global mailcapbptato2024-12-111-5/+2
| | | | | | | | | | | | | | | | | | | | | | | | In the past, Chawan would read global mailcap (/etc/mailcap, ...) too, but every now and then that would run entries that I didn't even know existed and definitely didn't intend to run. So I changed it to only use ~/.mailcap, but this meant users now had to add mailcap entries for every single mime type. At some point I also changed application/octet-stream to always save to disk, which is usually nice except when a text file is misrecognized as binary. Often times I just want to decide myself what to do. So now there are two layers. First, the global mailcap files (path as per RFC) prompt before executing. Then there is ~/.chawan/auto.mailcap (or ~/.config/chawan/auto.mailcap) which runs entries automatically. If you press shift before selecting an option in the prompt, the corresponding entry gets copied to auto.mailcap. It's also possible to type a new entry on the fly. Overall I think it's quite convenient. One unfortunate side effect is that existing users will have to migrate their entries to auto.mailcap, or redefine external.auto-mailcap to e.g. ~/.mailcap, but this seems acceptable.
* config, mailcap: remove std/streams dependency, specialize mmapbptato2024-12-051-27/+43
| | | | | | | | | | * use PosixStream/mmap for mailcap reading too; this finally lets us get rid of std/streams in the entire codebase * split up recvDataLoopOrMmap into 3 functions: one that can fall back to recvAll, one that falls back to recvDataLoop, and one that does not fall back to anything * use MAP_PRIVATE in mmap for read (we don't care if changes are propagated, as we do no changes to cached files)
* dynstream: recvDataLoopOrMmap improvementsbptato2024-12-051-38/+70
| | | | | * fall back to recvAll on ilen = -1 * handle zero-length files
* toml, config: skip copying buf, use PosixStreambptato2024-12-031-1/+5
| | | | | | | one std/streams less I used mmap for reading the user config. It shouldn't matter in any realistically sized config, but who knows.
* twtstr: add mypairsbptato2024-11-281-1/+2
| | | | | This couldn't get into system.nim for technical reasons, but it's still pretty useful when iterating over non-mutable openArrays.
* dynstream: check lseek return codebptato2024-11-171-0/+1
| | | | just in case
* js: reorganize modules, update docsbptato2024-11-152-0/+221
| | | | | | | most of it has already been moved to monoucha, and the rest fits better in other directories. also, move urimethodmap to config
* poll: fix clear()bptato2024-11-071-1/+5
| | | | | setLen(0) inside the events iterator was wrong; it should have just set all items to -1.
* dynstream: fix crash on *BSDbptato2024-11-041-1/+4
| | | | turns out fchmod on sockets only works on Linux.
* utils, types: merge some modulesbptato2024-11-031-44/+0
| | | | | * line, vector, matrix -> path * twtuni, charcategory -> twtstr
* remove an empty filebptato2024-11-021-0/+0
|
* dynstream: restrict permissions to userbptato2024-10-311-0/+1
| | | | | the man page says this isn't really portable, but it's better than nothing
* poll: nimifybptato2024-10-201-8/+22
| | | | until it's fixed upstream...
* dynstream: refactorbptato2024-10-209-224/+198
| | | | | | | | | | * consistently use cint instead of FileHandle - this was another remnant of winapi support; on posix, they are the same. * move "blocking" field to PosixStream * recvFileHandle -> recvFd, sendFileHandle -> sendFd * merge serversocket into dynstream * merge auxiliary C functions into dynstream_aux
* dynstream, serversocket: use posix instead of nativesocketsbptato2024-10-202-85/+44
| | | | | | | | | | | nativesockets is a wrapper over posix and winapi, but we don't support winapi, so we can just fall back to PosixStream instead. SocketStream remains as a constraint over PosixStream to allow sendFileHandle/recvFileHandle. As a nice side effect, we can drop some allowed syscalls from the seccomp filter.
* pager: refactor mailcap, console; misc fixesbptato2024-10-142-25/+28
| | | | | | | | | * use more PosixStream (because it has double-close checking) * factor out some common mailcap operations * move console from client to pager * fix case-insensitive mime type matching * replace convoluted fdin/fdout comparison logic (that only accidentally worked) with a boolean flag
* promise: remove newPromisebptato2024-10-101-4/+1
| | | | normal construction is enough (and it wasn't really used anyway)
* color: reduce CellColor size, misc color refactoringbptato2024-10-062-4/+4
| | | | | | * split out CSSColor from CellColor; now CellColor is just 4 bytes (which helps reduce FormatCell size) * unify color function naming (still not perfect)
* dynstream: fix memory leakbptato2024-10-041-2/+5
| | | | now I know why overloading dealloc felt wrong
* poll: reset events on errorbptato2024-10-021-1/+5
| | | | | poll will return an error if interrupted, which may leave the events in their previous state. Make sure revents is set to 0 first.
* promise: move PromiseMap to bufferbptato2024-09-291-45/+5
| | | | | It's only used there, and there's no reason for every single promise to carry two pointers to support it.
* gopher: do not depend on libcurlbptato2024-09-281-1/+7
| | | | | | | | I'm thinking of making libcurl entirely optional; let's start with the easiest part. I've added a SOCKS5 client for ALL_PROXY support; I know curl supported others too, but whatever.
* poll: unset unused fds in registerbptato2024-09-271-0/+3
|
* Fixes for FreeBSDbptato2024-09-261-1/+5
|
* dynstream: fix mmap bugsbptato2024-09-251-12/+16
| | | | ugh
* sixel: use inline background for blendingbptato2024-09-242-0/+8
| | | | still not really great, because inline background is a mess too
* Replace std/selectors with pollbptato2024-09-234-2/+49
| | | | | | | | | | | | std/selectors uses OS-specific selector APIs, which sounds good in theory (faster than poll!), but sucks for portability in practice. Sure, you can fix portability bugs, but who knows how many there are on untested platforms... poll is standard, so if it works on one computer it should work on all other ones. (I hope.) As a bonus, I rewrote the timeout API for poll, which incidentally fixes setTimeout across forks. Also, SIGWINCH should now work on all platforms (as we self-pipe instead of signalfd/kqueue magic).
* client, forkserver, dynstream: misc refactorings, fixesbptato2024-09-231-1/+1
| | | | | | * fix broken int conversion in dynstream * fix EPIPE handling in forkserver * merge fdmap and connectingContainers into loader map
* loader: mmap intermediate image files, misc refactoringbptato2024-09-222-1/+83
| | | | | | | | | | | | | | | | | | | | | | | | | | | * refactor parseHeader * optimize response blob() * add direct "to cache" mode for loader requests which sets stdout to a file, and use it for image processing * move image resizing into a separate process * mmap cache files in between processing steps when possible At last, resize is no longer a part of image decoding. Also, it feels much nicer to keep encoded image data in the same cache as everything else. The mmap operations *should* be more efficient than copying the whole RGBA data through a pipe. In practice, it only makes a difference for loading (well, now just mmapping) the encoded image into the pager, where it singlehandedly speeds up image display by 10x on my test image. For the other steps, the unfortunate fact that "tocache" must delay the next fork/exec in the pipeline until the entire image is processed seems to equal out any wins we might have gotten from skipping a single raw RGBA copy. I have tried moving the delay before the exec (it's possible with yet another pipe), but it didn't help much and made the code much uglier. (Not that tocache didn't, but I can live with this...)
* loader: fix some fd leaksbptato2024-09-021-0/+9
| | | | + be a bit more paranoid about double closes
* canvas: make sure we don't link to QJSbptato2024-09-012-131/+6
|
* canvas: move to separate CGI scriptbptato2024-09-013-37/+18
| | | | | | | | | | * stream: and passFd is now client-based, and accessible for buffers * Bitmap's width & height is now int, not uint64 * no more non-network Bitmap special case in the pager for canvas I just shoehorned it into the static image model, so it still doesn't render changes after page load. But at least now it doesn't crash the browser.
* xhr: progressbptato2024-08-131-6/+5
| | | | | | | | | | | | | * fix header case sensitivity issues -> probably still wrong as it discards the original casing. better than nothing, anyway * fix fulfill on generic promises * support standard open() async parameter weirdness * refactor loader response body reading (so bodyRead is no longer mandatory) * actually read response body still missing: response body getters
* Update monouchabptato2024-08-092-16/+17
|
* Fixes for Nim 2.2bptato2024-07-297-277/+269
| | | | | | | | | * xmlhttprequest: fix missing import * painter: generic tuple workaround * dynstream: merge module with implementations (so it will work with vtables) Not enabling vtables yet since it doesn't work with refc.
* io: remove readablestreambptato2024-07-141-32/+0
| | | | it was never implemented
* promise, container: fix nil derefsbptato2024-06-301-16/+22
|