# Network.Socket.Data

Low-Level C Sockets bindings for Idris. Used by higher-level, cleverer things.
Types used by Network.Socket.Raw and Network.Socket.

Original (C) SimonJF, MIT Licensed, 2014
Modified (C) The Idris Community, 2015, 2016

BACKLOG : Int

  Backlog used within listen() call -- number of incoming calls

ByteLength : Type
EAGAIN : Int
MkSocket : (descriptor : SocketDescriptor) -> (family : SocketFamily) -> (socketType : SocketType) -> (protocolNumber : ProtocolNumber) -> Socket
MkUDPAddrInfo : (remote_addr : SocketAddress) -> (remote_port : Port) -> UDPAddrInfo
MkUDPRecvData : (remote_addr : SocketAddress) -> (remote_port : Port) -> (recv_data : String) -> (data_len : Int) -> UDPRecvData
Port : Type
ProtocolNumber : Type

  Protocol Number.

  Generally good enough to just set it to 0.

ResultCode : Type
record Socket

  The metadata about a socket

  MkSocket : (descriptor : SocketDescriptor) -> (family : SocketFamily) -> (socketType : SocketType) -> (protocolNumber : ProtocolNumber) -> Socket
  descriptor : (rec : Socket) -> SocketDescriptor
  family : (rec : Socket) -> SocketFamily
  socketType : (rec : Socket) -> SocketType
  protocolNumber : (rec : Socket) -> ProtocolNumber
data SocketAddress : Type

  Network Addresses

  IPv4Addr : Int -> Int -> Int -> Int -> SocketAddress
  IPv6Addr : SocketAddress

    Not implemented (yet)

  Hostname : String -> SocketAddress
  InvalidAddress : SocketAddress

    Used when there's a parse error

SocketDescriptor : Type

  SocketDescriptor: Native C Socket Descriptor

SocketError : Type

  SocketError: Error thrown by a socket operation

data SocketFamily : Type

  Socket Families

  The ones that people might actually use. We're not going to need US
  Government proprietary ones.

  AF_UNSPEC : SocketFamily

    Unspecified

  AF_INET : SocketFamily

    IP / UDP etc. IPv4

  AF_INET6 : SocketFamily

    IP / UDP etc. IPv6

data SocketType : Type

  Socket Types.

  NotASocket : SocketType

    Not a socket, used in certain operations

  Stream : SocketType

    TCP

  Datagram : SocketType

    UDP

  RawSocket : SocketType

    Raw sockets

interface ToCode
  toCode : ToCode a => a -> Int
record UDPAddrInfo
  MkUDPAddrInfo : (remote_addr : SocketAddress) -> (remote_port : Port) -> UDPAddrInfo
  remote_addr : (rec : UDPAddrInfo) -> SocketAddress
  remote_port : (rec : UDPAddrInfo) -> Port
record UDPRecvData
  MkUDPRecvData : (remote_addr : SocketAddress) -> (remote_port : Port) -> (recv_data : String) -> (data_len : Int) -> UDPRecvData
  remote_addr : (rec : UDPRecvData) -> SocketAddress
  remote_port : (rec : UDPRecvData) -> Port
  recv_data : (rec : UDPRecvData) -> String
  data_len : (rec : UDPRecvData) -> Int
getSocketFamily : Int -> Maybe SocketFamily
parseIPv4 : String -> SocketAddress

  Parses a textual representation of an IPv4 address into a SocketAddress