Documentation

Socket.Basic

Socket Type Definitions #

This module defines some basic types to be used across whole pacage:

Socket #

noncomputable def Socket.Socket :
Type
Equations

Opaque reference to underlying platform specific socket.

To create a Socket, refer to Socket.mk. Then you can manipulate the Socket using common socket functions like Socket.bind,Socket.connect, etc. For all functions available, refer to the Socket module.

NOTE: NonemptyType is used to implement Inhabited for Socket. detailed explanation

import Socket
open Socket

def main : IO Unit := do
  let s ← Socket.mk
  -- some socket operations
  s.close
noncomputable def Socket.SockAddr :
Type
Equations

Opaque reference to underlying socket address.

NOTE: Different from the C sockaddr, SockAddr also includes length.

inductive Socket.AddressFamily :
Type

Enumeration of supported address families, which is used in Socket.mk.

inductive Socket.SockType :
Type

Enumeration of supported socket types, which is used in Socket.mk.

Equations

Convert SockType to String.

inductive Socket.ShutdownHow :
Type

Enumeration of how is socket shutdown, which is used in Socket.shutdown.

@[extern lean_gethostname]

Get hostname of current machine.

Explanation: Usage of NonemptyType #

As Socket and SockAddr are implemented usinglean_external_class. NonemptyType is used to implement Inhabited for these types.

A simple example of this trick can be found here in Lean core.