stdlib: ファイル I/O と fd 汎用 read/write/close (#33)#116
Merged
Conversation
Design for issue #33. Replace socket-only tcp_read/tcp_write/tcp_close with fd-generic read/write/close backed by read(2)/write(2)/close(2), and add file_open(path, mode). The EAGAIN+park path naturally handles sockets (nonblocking) and files (no EAGAIN) without fd-type branching. tcp_listen/tcp_accept stay as socket-specific open operations. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Lift the EAGAIN+park structure from the old tcp_read/tcp_write into io.c using read(2)/write(2), add close(2) and file_open. Remove rw_tcp_read/rw_tcp_write/rw_tcp_close (superseded). tcp_listen/accept stay in tcp.c. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ile_open Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
tcp_read/tcp_write/tcp_closeを、fd 汎用のread/write/close(POSIXread(2)/write(2)/close(2)ベース)に統合file_open(path: string, mode: string) -> int("r"/"w"/"a"、失敗時は負の fd)を追加read/write/closeで書けるCloses #33
なぜ
tcp_read/tcp_write/tcp_closeは実はソケット専用の操作ではなく、read(2)/write(2)/close(2)は任意の fd に使える汎用 syscall。これを汎用化したうえでfile_openを足すだけで、ファイル I/O が最小コードで手に入る。設計の核心
runtime を
recv/sendからread(2)/write(2)に変え、EAGAINのとき fiber 上なら netpoller に park する。EAGAINを返すので park(既存の netpoller 連携)read(2)でEAGAINを返さないのでそのまま同期 readこれにより fd 種別を判定する分岐コードなしで、ソケットとファイルが同一コードパスで両対応する。
tcp_listen/tcp_acceptはソケット固有なのでそのまま残す。組み込み関数
file_open(path: string, mode: string) -> intread(fd: int, max: int) -> Byteswrite(fd: int, b: Bytes) -> intclose(fd: int) -> int