Skip to content
slaeshjag edited this page Apr 26, 2013 · 4 revisions

DARNIT_SOCKET

DARNIT_SOCKET provides a basic platform-independent wrapper for TCP-sockets. The set of calls is incomplete, and UDP is also planned for some time later.

  • DARNIT_SOCKET *d_socket_connect(const char *host, int port, void (*callback)(int ret, void *data, void *socket), void *data);
  • int d_socket_recv(DARNIT_SOCKET *sock, void *buff, int len);
  • int d_socket_recv_try(DARNIT_SOCKET *sock, void *buff, int len);
  • int d_socket_send(DARNIT_SOCKET *sock, void *buff, int len);
  • DARNIT_SOCKET *d_socket_close(DARNIT_SOCKET *sock);

d_socket_connect

DARNIT_SOCKET *d_socket_connect(const char *host, int port, void (*callback)(int ret, void *data, void *socket), void *data);

Connects to host at port port. This can be done in the background, with a callback being runned when the connection is complete or has failed.

Arguments

  • host - The hostname to connect to. Can also be a string containing the IP-address
  • port - The TCP port to connect to
  • callback - The callback function to run
  • ret - Tells callback whether or not the connection was successful (-1 on fail, 0 on success)
  • data - Any user data that the callback needs
  • socket - The socket that is used for the connection
  • data - Userdata to pass to the callback. Not used by libdarnit.

Return value

NULL on error, anything else is a valid DARNIT_SOCKET.

Clone this wiki locally