Adam Viaud — iOS/macOS engineer SWIFT · 2026
← All labs

LAB 002 · PROTON VPN

States that compile.

The browser cannot expose POSIX sockets, but it can make the real ownership model tangible: every arrow consumes one value and unlocks a narrower, valid API.

SocketOwnership.swift TYPE CHECKED
Protocol
START Socket<TCP, Closed>
  • connect(to:)
  • bind(to:)
  • close()

Only operations valid for a closed socket exist here.

OPENED Socket<TCP, Opened>
  • send(_:)
  • recv()
  • split()
  • close()

The closed value has been consumed. It cannot be reused.

SocketSendHalf<TCP> SocketRecvHalf<TCP>
  • send(_:)
  • recv()
  • close()

Independent, noncopyable ownership. Each half shuts down its direction when released.

Sample usage follows the current state
CLOSED
CLOSED

Browser boundary: this teaches the real public types without simulating network access the browser does not have.