Skip to content

Declare libc socket calls as Mosaad-M/tcp does - #139

Merged
winding-lines merged 1 commit into
mainfrom
tcp-abi-send-recv
Nov 16, 2026
Merged

winding-lines merged 1 commit into
mainfrom
tcp-abi-send-recv

Conversation

@winding-lines

Copy link
Copy Markdown
Contributor

Closes #134

Mojo allows one signature per C symbol in a program, so a binary importing dista and Mosaad-M/tcp or tls (so Mosaad-M/requests) failed to compile: "existing function with conflicting signature".

dista's socket code now calls libc through small helpers declared exactly as tcp declares them (Int addresses and lengths, Int32 ints): _send, _recv, _c_connect, close_fd, _setsockopt, _getsockopt, _c_poll. Behaviour, errno handling and the MSG_* flags are unchanged.

Declarations checked against tcp.mojo and tls:

  • Aligned: send, recv (the four sites in Match tcp's external_call declarations (recv) so dista links beside Mosaad-M/requests #134), and also connect, setsockopt, getsockopt, poll and getaddrinfo, which used pointer and c_uint types. close was already Int32 but had 16 separate declarations; they now call one close_fd (also used by executors.mojo and signals.mojo).
  • Already the same: socket, freeaddrinfo.
  • Not declared by tcp or tls, left alone: accept, bind, listen, getsockname, getpeername, socketpair, fcntl (tcp uses ioctl), read, write.

Tests:

  • pixi run test passes in full (default env, macOS arm64), before the new test was added.
  • New test-libc-abi declares the symbols tcp's way in the same program as dista's and uses them on a dista socket; it fails to build on main.
  • Scratch programs outside the repo (not committed): dista's Listener and Stream with Mosaad-M/tcp TcpSocket echoing a message compiles and runs (it fails to compile on main with the send/recv conflict); dista with tls.socket.TlsSocket compiles (not run to completion).

Changelog entry under Unreleased (the repo uses CHANGELOG.md, not changes/).

🤖 Generated with Claude Code

https://claude.ai/code/session_017TycszSbyw92Efu4ZeCYL6

Mojo allows one signature per C symbol in a program, so a binary importing
dista and tcp or tls failed with "existing function with conflicting
signature". send, recv, connect, close, setsockopt, getsockopt, poll and
getaddrinfo now go through helpers with tcp's types (Int addresses, Int32
ints). Adds test-libc-abi, which declares them tcp's way next to dista's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017TycszSbyw92Efu4ZeCYL6
@winding-lines
winding-lines merged commit d9c1c5c into main Nov 16, 2026
13 checks passed
@winding-lines
winding-lines deleted the tcp-abi-send-recv branch November 16, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Match tcp's external_call declarations (recv) so dista links beside Mosaad-M/requests

1 participant