mirror of
https://github.com/alfishe/amiga-bootcamp.git
synced 2026-06-13 00:26:28 +00:00
Expand documentation suite: 30+ articles enriched with diagrams, code examples, and hardware details
Graphics: text_fonts (bitmap layout, styles), sprites (DMA, multiplexing), gfx_base (chipset detection), rastport (draw modes, clipping), ham_ehb (mermaid fixes), display_modes (HAM palettes) Devices: scsi (per-model interfaces, Gayle limits, CD-ROM, native vs vendor drivers), console (ANSI sequences, CON:/RAW:), parallel (CIA registers, pinout), timer (resource exhaustion), gameport (quadrature, XOR state) Libraries: workbench (WBStartup, AppWindow/Icon/MenuItem), rexxsyslib (ARexx port hosting, command parsing), diskfont (font directory, colour fonts), keymap (rawkey codes, dead keys), locale (catalogue system, date formatting), layers (ClipRect, refresh types), utility (TagItem chains), icon (DiskObject, ToolTypes), iffparse (IFF structure, ByteRun1), expansion (Zorro AutoConfig) Networking: tcp_ip_stacks (major rewrite - Amiga vs Unix architecture, SANA-II pipeline, PPP/SLIP dial-up, Ethernet cards, MiSTer), bsdsocket (pure API ref), sana2 (buffer hooks, driver requirements), protocols (all code examples). Deduplicated overlap between the three files. Toolchain: debugging (Enforcer patterns, SnoopDOS, GDB remote, kprintf checklist), sasc (pragma encoding, __saveds idioms), stormc (NEW - StormC IDE, C++, PowerPC) References: error_codes (DOS, Exec, trackdisk, Intuition error tables) Driver development: rtg_driver (Native driver analysis, P96 tuning) All 22 README indexes updated. Root README synced with stormc.md entry.
This commit is contained in:
parent
0ded078134
commit
f61c26b542
38 changed files with 6402 additions and 1065 deletions
|
|
@ -1,23 +1,39 @@
|
|||
[← Home](../README.md) · [Networking](README.md)
|
||||
|
||||
# bsdsocket.library — BSD Socket API
|
||||
# bsdsocket.library — BSD Socket API Reference
|
||||
|
||||
## Overview
|
||||
|
||||
`bsdsocket.library` is the AmigaOS implementation of the BSD socket API. It is provided by the active TCP/IP stack (AmiTCP, Miami, Roadshow) and presents a POSIX-like socket interface adapted to the Amiga's library-based architecture.
|
||||
`bsdsocket.library` is the AmigaOS implementation of the BSD socket API. It is provided by the active TCP/IP stack (AmiTCP, Miami, Roadshow). See [TCP/IP Stacks](tcp_ip_stacks.md) for how the stack architecture works and how it differs from Unix. See [Protocols](protocols.md) for working code examples.
|
||||
|
||||
---
|
||||
|
||||
## Opening
|
||||
## Per-Task Library Base
|
||||
|
||||
Unlike Unix (kernel-managed fd table), each Amiga task must open its own private `SocketBase`:
|
||||
|
||||
```c
|
||||
struct Library *SocketBase = OpenLibrary("bsdsocket.library", 4);
|
||||
if (!SocketBase) { /* no TCP/IP stack running */ }
|
||||
if (!SocketBase)
|
||||
{
|
||||
Printf("No TCP/IP stack running\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Configure per-task error variable: */
|
||||
LONG errno;
|
||||
SocketBaseTags(
|
||||
SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(LONG))), (ULONG)&errno,
|
||||
SBTM_SETVAL(SBTC_LOGTAGPTR), (ULONG)"myapp",
|
||||
TAG_DONE);
|
||||
```
|
||||
|
||||
> [!CAUTION]
|
||||
> **Never share `SocketBase` between tasks.** Each task MUST `OpenLibrary` its own copy. Sharing causes socket state corruption and random crashes. This is the #1 Amiga networking bug.
|
||||
|
||||
---
|
||||
|
||||
## Core Functions (LVO Mapping)
|
||||
## Function Table (LVO Mapping)
|
||||
|
||||
| LVO | Function | BSD Equivalent |
|
||||
|---|---|---|
|
||||
|
|
@ -36,58 +52,83 @@ if (!SocketBase) { /* no TCP/IP stack running */ }
|
|||
| −102 | `gethostbyname(name)` | `gethostbyname()` |
|
||||
| −108 | `gethostbyaddr(addr, len, type)` | `gethostbyaddr()` |
|
||||
| −114 | `getnetbyname(name)` | `getnetbyname()` |
|
||||
| −168 | `Errno()` | `errno` (returns last error) |
|
||||
| −168 | `Errno()` | `errno` |
|
||||
| −174 | `CloseSocket(sock)` | `close()` |
|
||||
| −180 | `WaitSelect(nfds, rd, wr, ex, timeout, sigmask)` | `select()` + signals |
|
||||
| −210 | `inet_addr(cp)` | `inet_addr()` |
|
||||
| −216 | `Inet_NtoA(in)` | `inet_ntoa()` |
|
||||
| −222 | `inet_makeaddr(net, host)` | `inet_makeaddr()` |
|
||||
| −252 | `getservbyname(name, proto)` | `getservbyname()` |
|
||||
| −270 | `SocketBaseTagList(tags)` | (Amiga-specific) |
|
||||
|
||||
---
|
||||
|
||||
## WaitSelect — Amiga-Enhanced select()
|
||||
|
||||
Unlike BSD `select()`, `WaitSelect` integrates with Exec signals:
|
||||
The key Amiga-specific extension: `WaitSelect` simultaneously waits on socket file descriptors **and** Exec signal bits. This replaces the need for separate threads — a single event loop can handle sockets, windows, timers, and ARexx:
|
||||
|
||||
```c
|
||||
fd_set rdset;
|
||||
FD_ZERO(&rdset);
|
||||
FD_SET(sock, &rdset);
|
||||
|
||||
ULONG sigmask = SIGBREAKF_CTRL_C; /* also wait for Ctrl-C */
|
||||
struct timeval tv = { 5, 0 }; /* 5 second timeout */
|
||||
|
||||
LONG n = WaitSelect(sock + 1, &rdset, NULL, NULL, &tv, &sigmask);
|
||||
if (n > 0 && FD_ISSET(sock, &rdset)) { /* data ready */ }
|
||||
if (sigmask & SIGBREAKF_CTRL_C) { /* user pressed Ctrl-C */ }
|
||||
LONG WaitSelect(LONG nfds,
|
||||
fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
|
||||
struct timeval *timeout,
|
||||
ULONG *sigmask);
|
||||
/* sigmask: on entry = signals to also wait for
|
||||
on exit = which signals fired */
|
||||
```
|
||||
|
||||
See [protocols.md](protocols.md) for a complete working example combining socket I/O with Intuition window events.
|
||||
|
||||
---
|
||||
|
||||
## Simple TCP Client
|
||||
## Error Handling
|
||||
|
||||
```c
|
||||
/* Amiga sockets use Errno() instead of global errno: */
|
||||
LONG sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
struct sockaddr_in addr;
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(80);
|
||||
addr.sin_addr.s_addr = inet_addr("93.184.216.34");
|
||||
|
||||
if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == 0) {
|
||||
send(sock, "GET / HTTP/1.0\r\nHost: example.com\r\n\r\n", 38, 0);
|
||||
char buf[4096];
|
||||
LONG n = recv(sock, buf, sizeof(buf) - 1, 0);
|
||||
buf[n] = 0;
|
||||
Printf("%s\n", buf);
|
||||
if (sock < 0)
|
||||
{
|
||||
LONG err = Errno();
|
||||
Printf("socket() failed: error %ld\n", err);
|
||||
}
|
||||
CloseSocket(sock);
|
||||
|
||||
/* Or set up a per-task errno pointer (recommended): */
|
||||
LONG myErrno;
|
||||
SocketBaseTags(
|
||||
SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(LONG))), (ULONG)&myErrno,
|
||||
TAG_DONE);
|
||||
/* Now myErrno is updated automatically after each call */
|
||||
```
|
||||
|
||||
### Common Error Codes
|
||||
|
||||
| Value | Name | Meaning |
|
||||
|---|---|---|
|
||||
| 48 | `EADDRINUSE` | Address already in use |
|
||||
| 60 | `ETIMEDOUT` | Connection timed out |
|
||||
| 61 | `ECONNREFUSED` | Connection refused |
|
||||
| 64 | `EHOSTDOWN` | Host is down |
|
||||
| 65 | `EHOSTUNREACH` | No route to host |
|
||||
|
||||
---
|
||||
|
||||
## Differences from BSD/POSIX Sockets
|
||||
|
||||
| Aspect | BSD/POSIX | Amiga bsdsocket.library |
|
||||
|---|---|---|
|
||||
| Close socket | `close(fd)` | `CloseSocket(sock)` — `close()` is AmigaDOS |
|
||||
| Error variable | Global `errno` | Call `Errno()` or set `SBTC_ERRNOPTR` |
|
||||
| Multiplexing | `select()` / `poll()` / `epoll()` | `WaitSelect()` — also waits on Exec signals |
|
||||
| Headers | `<sys/socket.h>` | `<proto/socket.h>` or stack-specific |
|
||||
| Lifecycle | Kernel-managed | Must `OpenLibrary`/`CloseLibrary` per task |
|
||||
| fd namespace | Shared with files | Sockets are separate from DOS file handles |
|
||||
| Multi-thread | fd shared across threads | `SocketBase` is per-task, not shareable |
|
||||
|
||||
---
|
||||
|
||||
## References
|
||||
|
||||
- NDK39: `libraries/bsdsocket.h` (stack-specific)
|
||||
- Roadshow SDK documentation
|
||||
- [sana2.md](sana2.md) — network device driver layer
|
||||
- AmiTCP SDK: `bsdsocket.h` and autodocs
|
||||
- See also: [tcp_ip_stacks.md](tcp_ip_stacks.md) — stack architecture and configuration
|
||||
- See also: [protocols.md](protocols.md) — working code examples (TCP, UDP, DNS)
|
||||
- See also: [sana2.md](sana2.md) — network device driver layer below the stack
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue