File Descriptors

References

  • http://man7.org/linux/man-pages/man2/socket.2.html
  • http://man7.org/linux/man-pages/man2/listen.2.html

Select

  • On Linux, select supports a maximum of 1024 connections
  • On Windows, some historic notes suggest 64 (per thread) is the maximum, but I think this is obsolete (winsock vs winsock2)

References

  • How to use `select properly: https://stackoverflow.com/questions/32711521/how-to-use-select-on-sockets-properly

Poll

References

  • http://man7.org/linux/man-pages/man2/poll.2.html

EPoll

References

  • 500,000 connection limit out-of-the-box: https://stackoverflow.com/questions/28735700/what-is-the-maximum-number-of-sockets-that-epoll-can-handle
  • Blocking and Non-Blocking: https://eklitzke.org/blocking-io-nonblocking-io-and-epoll
  • EPoll Explained: https://medium.com/@copyconstruct/the-method-to-epolls-madness-d9d2d6378642
  • epoll_create: https://linux.die.net/man/2/epoll_create
  • epoll_wait: http://man7.org/linux/man-pages/man2/epoll_wait.2.html
  • epoll_ctl: http://man7.org/linux/man-pages/man2/epoll_ctl.2.html

KQueue

BSD/Apple specific.

References

  • Apple documentation: https://developer.apple.com/library/content/documentation/Darwin/Conceptual/FSEvents_ProgGuide/KernelQueues/KernelQueues.html

Compared

References

  • Comparison: https://www.ulduzsoft.com/2014/01/select-poll-epoll-practical-difference-for-system-architects/
  • The C10k Problem: http://www.kegel.com/c10k.html

ENET

Platform Specific Functions

These functions are found to be defined in unix.c and win32.c. When porting enet to a new platform (or API), these must exist.

Init

Initialization functions. Out-of-the-box neither socket, select or poll need this, but an epoll implementation will.

  • intenet_initialize(void)
  • voidenet_deinitialize(void)

Misc

Miscaleneous functions. Primarily just time stuff.

  • enet_uint32enet_host_random_seed(void)
    • time(NULL);
  • enet_uint32enet_time_get(void)
    • gettimeofday
  • voidenet_time_set(enet_uint32 newTimeBase)
    • gettimeofday

Address

  • intenet_address_set_host_ip(ENetAddress * address, const char * name)
    • inet_pton or inet_aton
    • inet_pton is the modern function. It doesn’t autodetect, but it can be told to encode IPv6 addresses.
  • intenet_address_set_host(ENetAddress * address, const char * name)
    • getaddrinfo, freeaddrinfo, gethostbyname_r or gethostbyname
  • intenet_address_get_host_ip(const ENetAddress * address, char * name, size_t nameLength)
    • inet_ntop or inet_ntoa
    • inet_ntop is the modern function. It doesn’t autodetect, but it can be told to decode IPv6 addresses.
  • intenet_address_get_host(const ENetAddress * address, char * name, size_t nameLength)
    • getnameinfo, gethostbyaddr_r or gethostbyaddr

Socket

  • intenet_socket_bind(ENetSocket socket, const ENetAddress * address)
    • bind
  • intenet_socket_get_address(ENetSocket socket, ENetAddress * address)
    • getsockname
  • intenet_socket_listen(ENetSocket socket, int backlog)
    • listen
  • ENetSocketenet_socket_create(ENetSocketType type)
    • socket
  • intenet_socket_set_option(ENetSocket socket, ENetSocketOption option, int value)
    • fcntl or ioctl, setsockopt (many)
  • intenet_socket_get_option(ENetSocket socket, ENetSocketOption option, int * value)
    • getsockopt
  • intenet_socket_connect(ENetSocket socket, const ENetAddress * address)
    • connect
  • ENetSocketenet_socket_accept(ENetSocket socket, ENetAddress * address)
    • accept
  • intenet_socket_shutdown(ENetSocket socket, ENetSocketShutdown how)
    • shutdown
  • voidenet_socket_destroy(ENetSocket socket)
    • close
  • intenet_socket_send(ENetSocket socket, const ENetAddress * address, const ENetBuffer * buffers, size_t bufferCount)
    • sendmsg
  • intenet_socket_receive(ENetSocket socket, ENetAddress * address, ENetBuffer * buffers, size_t bufferCount)
    • recvmsg
  • intenet_socketset_select(ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocketSet * writeSet, enet_uint32 timeout)
    • select
  • intenet_socket_wait(ENetSocket socket, enet_uint32 * condition, enet_uint32 timeout)
    • poll or select