sdl2/sdl2_net

Types

Version = sdl2.Version
IPaddress {...}{.bycopy.} = object
  host*: Uint32                ## ::
              ##   32-bit IPv4 host address
  port*: Uint16                ## ::
              ##   16-bit protocol port
  
IPv4 hostname resolution API
TCPsocket {...}{.incompleteStruct.} = object
UDPsocket {...}{.incompleteStruct.} = object
UDPpacket {...}{.bycopy.} = object
  channel*: cint               ## ::
               ##   The src/dst channel of the packet
  data*: ptr Uint8              ## ::
                ##   The packet data
  len*: cint                   ## ::
           ##   The length of the packet data
  maxlen*: cint                ## ::
              ##   The size of the data buffer
  status*: cint                ## ::
              ##   packet status after sending
  address*: IPaddress          ## ::
                    ##   The source/dest address of an incoming/outgoing packet
  
SocketSet {...}{.incompleteStruct.} = object
GenericSocket {...}{.bycopy.} = object
  ready*: cint
Any network socket can be safely cast to this socket type

Consts

SDLnetStd = false
SDLnetGit = false
SDLnetDL = true
SDLnetStatic = true
SDLnetSetVer = ""
SDLnetLPath = "/Users/joey/Projects/nim-sdl2/src/build/sdl2_net/.libs/libSDL2_net.a"
SDLnetPath = "/Users/joey/Projects/nim-sdl2/src/build/sdl2_net/SDL_net.h"
NET_MAJOR_VERSION = 2
NET_MINOR_VERSION = 0
NET_PATCHLEVEL = 1
INADDR_ANY = 0x00000000
INADDR_NONE = 0x00000000FFFFFFFF'i64
INADDR_LOOPBACK = 0x7F000001
INADDR_BROADCAST = 0x00000000FFFFFFFF'i64
SDLNET_MAX_UDPCHANNELS = 32
SDLNET_MAX_UDPADDRESSES = 4
DATA_ALIGNED = 0
INVALID_SOCKET = -1
SOCKET_ERROR = -1

Procs

proc linked_Version(): ptr Version {...}{.importc: "SDLNet_Linked_Version", cdecl.}
This function gets the version of the dynamically linked SDL_net library.
   it should NOT be used to fill a version structure, instead you should
   use the SDL_NET_VERSION() macro.
proc init(): cint {...}{.importc: "SDLNet_Init", cdecl.}
Initialize/Cleanup the network API
   SDL must be initialized before calls to functions in this library,
   because this library uses utility functions from the SDL library.
proc quit() {...}{.importc: "SDLNet_Quit", cdecl.}
proc resolveHost(address: ptr IPaddress; host: cstring; port: Uint16): cint {...}{.
    importc: "SDLNet_ResolveHost", cdecl.}
proc resolveIP(ip: ptr IPaddress): cstring {...}{.importc: "SDLNet_ResolveIP", cdecl.}
Resolve an ip address to a host name in canonical form.
   If the ip couldn't be resolved, this function returns NULL,
   otherwise a pointer to a static buffer containing the hostname
   is returned.  Note that this function is not thread-safe.
proc getLocalAddresses(addresses: ptr IPaddress; maxcount: cint): cint {...}{.
    importc: "SDLNet_GetLocalAddresses", cdecl.}
Get the addresses of network interfaces on this system.
   This returns the number of addresses saved in 'addresses'
proc tCP_Open(ip: ptr IPaddress): TCPsocket {...}{.importc: "SDLNet_TCP_Open", cdecl.}
Open a TCP network socket
   If ip.host is INADDR_NONE or INADDR_ANY, this creates a local server
   socket on the given port, otherwise a TCP connection to the remote
   host and port is attempted. The address passed in should already be
   swapped to network byte order (addresses returned from
   SDLNet_ResolveHost() are already in the correct form).
   The newly created socket is returned, or NULL if there was an error.
proc tCP_Accept(server: TCPsocket): TCPsocket {...}{.importc: "SDLNet_TCP_Accept", cdecl.}
Accept an incoming connection on the given server socket.
   The newly created socket is returned, or NULL if there was an error.
proc tCP_GetPeerAddress(sock: TCPsocket): ptr IPaddress {...}{.
    importc: "SDLNet_TCP_GetPeerAddress", cdecl.}
Get the IP address of the remote system associated with the socket.
   If the socket is a server socket, this function returns NULL.
proc tCP_Send(sock: TCPsocket; data: pointer; len: cint): cint {...}{.
    importc: "SDLNet_TCP_Send", cdecl.}
Send 'len' bytes of 'data' over the non-server socket 'sock'
   This function returns the actual amount of data sent.  If the return value
   is less than the amount of data sent, then either the remote connection was
   closed, or an unknown socket error occurred.
proc tCP_Recv(sock: TCPsocket; data: pointer; maxlen: cint): cint {...}{.
    importc: "SDLNet_TCP_Recv", cdecl.}
Receive up to 'maxlen' bytes of data over the non-server socket 'sock',
   and store them in the buffer pointed to by 'data'.
   This function returns the actual amount of data received.  If the return
   value is less than or equal to zero, then either the remote connection was
   closed, or an unknown socket error occurred.
proc tCP_Close(sock: TCPsocket) {...}{.importc: "SDLNet_TCP_Close", cdecl.}
Close a TCP network socket
proc allocPacket(size: cint): ptr UDPpacket {...}{.importc: "SDLNet_AllocPacket", cdecl.}
Allocate/resize/free a single UDP packet 'size' bytes long.
   The new packet is returned, or NULL if the function ran out of memory.
proc resizePacket(packet: ptr UDPpacket; newsize: cint): cint {...}{.
    importc: "SDLNet_ResizePacket", cdecl.}
proc freePacket(packet: ptr UDPpacket) {...}{.importc: "SDLNet_FreePacket", cdecl.}
proc allocPacketV(howmany: cint; size: cint): ptr ptr UDPpacket {...}{.
    importc: "SDLNet_AllocPacketV", cdecl.}
Allocate/Free a UDP packet vector (array of packets) of 'howmany' packets,
   each 'size' bytes long.
   A pointer to the first packet in the array is returned, or NULL if the
   function ran out of memory.
proc freePacketV(packetV: ptr ptr UDPpacket) {...}{.importc: "SDLNet_FreePacketV", cdecl.}
proc uDP_Open(port: Uint16): UDPsocket {...}{.importc: "SDLNet_UDP_Open", cdecl.}
Open a UDP network socket
   If 'port' is non-zero, the UDP socket is bound to a local port.
   The 'port' should be given in native byte order, but is used
   internally in network (big endian) byte order, in addresses, etc.
   This allows other systems to send to this socket via a known port.
proc uDP_SetPacketLoss(sock: UDPsocket; percent: cint) {...}{.
    importc: "SDLNet_UDP_SetPacketLoss", cdecl.}
Set the percentage of simulated packet loss for packets sent on the socket.
proc uDP_Bind(sock: UDPsocket; channel: cint; address: ptr IPaddress): cint {...}{.
    importc: "SDLNet_UDP_Bind", cdecl.}
Bind the address 'address' to the requested channel on the UDP socket.
   If the channel is -1, then the first unbound channel that has not yet
   been bound to the maximum number of addresses will be bound with
   the given address as it's primary address.
   If the channel is already bound, this new address will be added to the
   list of valid source addresses for packets arriving on the channel.
   If the channel is not already bound, then the address becomes the primary
   address, to which all outbound packets on the channel are sent.
   This function returns the channel which was bound, or -1 on error.
proc uDP_Unbind(sock: UDPsocket; channel: cint) {...}{.importc: "SDLNet_UDP_Unbind", cdecl.}
Unbind all addresses from the given channel
proc uDP_GetPeerAddress(sock: UDPsocket; channel: cint): ptr IPaddress {...}{.
    importc: "SDLNet_UDP_GetPeerAddress", cdecl.}
Get the primary IP address of the remote system associated with the
   socket and channel.  If the channel is -1, then the primary IP port
   of the UDP socket is returned -- this is only meaningful for sockets
   opened with a specific port.
   If the channel is not bound and not -1, this function returns NULL.
proc uDP_SendV(sock: UDPsocket; packets: ptr ptr UDPpacket; npackets: cint): cint {...}{.
    importc: "SDLNet_UDP_SendV", cdecl.}
Send a vector of packets to the the channels specified within the packet.
   If the channel specified in the packet is -1, the packet will be sent to
   the address in the 'src' member of the packet.
   Each packet will be updated with the status of the packet after it has
   been sent, -1 if the packet send failed.
   This function returns the number of packets sent.
proc uDP_Send(sock: UDPsocket; channel: cint; packet: ptr UDPpacket): cint {...}{.
    importc: "SDLNet_UDP_Send", cdecl.}
Send a single packet to the specified channel.
   If the channel specified in the packet is -1, the packet will be sent to
   the address in the 'src' member of the packet.
   The packet will be updated with the status of the packet after it has
   been sent.
   This function returns 1 if the packet was sent, or 0 on error.
   NOTE:
   The maximum size of the packet is limited by the MTU (Maximum Transfer Unit)
   of the transport medium.  It can be as low as 250 bytes for some PPP links,
   and as high as 1500 bytes for ethernet.
proc uDP_RecvV(sock: UDPsocket; packets: ptr ptr UDPpacket): cint {...}{.
    importc: "SDLNet_UDP_RecvV", cdecl.}
Receive a vector of pending packets from the UDP socket.
   The returned packets contain the source address and the channel they arrived
   on.  If they did not arrive on a bound channel, the the channel will be set
   to -1.
   The channels are checked in highest to lowest order, so if an address is
   bound to multiple channels, the highest channel with the source address
   bound will be returned.
   This function returns the number of packets read from the network, or -1
   on error.  This function does not block, so can return 0 packets pending.
proc uDP_Recv(sock: UDPsocket; packet: ptr UDPpacket): cint {...}{.
    importc: "SDLNet_UDP_Recv", cdecl.}
Receive a single packet from the UDP socket.
   The returned packet contains the source address and the channel it arrived
   on.  If it did not arrive on a bound channel, the the channel will be set
   to -1.
   The channels are checked in highest to lowest order, so if an address is
   bound to multiple channels, the highest channel with the source address
   bound will be returned.
   This function returns the number of packets read from the network, or -1
   on error.  This function does not block, so can return 0 packets pending.
proc uDP_Close(sock: UDPsocket) {...}{.importc: "SDLNet_UDP_Close", cdecl.}
Close a UDP network socket
proc allocSocketSet(maxsockets: cint): SocketSet {...}{.importc: "SDLNet_AllocSocketSet",
    cdecl.}
Allocate a socket set for use with SDLNet_CheckSockets()
   This returns a socket set for up to 'maxsockets' sockets, or NULL if
   the function ran out of memory.
proc addSocket(set: SocketSet; sock: GenericSocket): cint {...}{.
    importc: "SDLNet_AddSocket", cdecl.}
Add a socket to a set of sockets to be checked for available data
proc delSocket(set: SocketSet; sock: GenericSocket): cint {...}{.
    importc: "SDLNet_DelSocket", cdecl.}
Remove a socket from a set of sockets to be checked for available data
proc checkSockets(set: SocketSet; timeout: Uint32): cint {...}{.
    importc: "SDLNet_CheckSockets", cdecl.}
This function checks to see if data is available for reading on the
   given set of sockets.  If 'timeout' is 0, it performs a quick poll,
   otherwise the function returns when either data is available for
   reading, or the timeout in milliseconds has elapsed, which ever occurs
   first.  This function returns the number of sockets ready for reading,
   or -1 if there was an error with the select() system call.
proc freeSocketSet(set: SocketSet) {...}{.importc: "SDLNet_FreeSocketSet", cdecl.}
Free a set of sockets allocated by SDL_NetAllocSocketSet()
proc setError(fmt: cstring) {...}{.importc: "SDLNet_SetError", cdecl, varargs.}
Error reporting functions
proc getError(): cstring {...}{.importc: "SDLNet_GetError", cdecl.}
proc getLastError(): cint {...}{.importc: "SDLNet_GetLastError", cdecl.}
proc setLastError(err: cint) {...}{.importc: "SDLNet_SetLastError", cdecl.}