1 /* ttt-socket.c - Simple interface for creating sockets.
3 * Copyright © 2005 Carl Worth
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Author: Carl Worth <cworth@cworth.org>
22 #ifndef _TTT_SOCKET_H_
23 #define _TTT_SOCKET_H_
27 typedef void (*ttt_socket_accept_func_t) (void *closure,
28 int connected_socket);
30 /* Create a socket, bind it to the given host and port, and listen in
31 * preparation for incoming connections. See ttt_socket_accept for a
32 * way to actually accept those incoming connections.
34 * Lookup for host (e.g. /etc/hosts and DNA) and port (e.g /etc/services)
35 * will be performed if necessary.
37 * A special host value of "0.0.0.0" may be used to prepare a server
38 * socket to bind to all available addresses.
40 * Return value: The created socket as a file descriptor.
42 * Errors: If any error occurs, this function will not return.
45 ttt_socket_create_server (const char *host, const char *port);
47 /* Wait for an incoming connection on listen_socket, (which should be
48 * a valid socket on which bind and listen have already been
49 * called---see ttt_socket_create_server), then call the accept
50 * function with the closure argument and the new socket from the
54 ttt_socket_accept (int listen_socket,
55 ttt_socket_accept_func_t accept,
58 /* Performa a blocking read, until all count bytes are read from the
59 * socket to buf, which must be of size count or larger.
61 * Errors: If any errors occur, this function does not return.
64 ttt_socket_read (int socket,
68 /* Perform a blocking write, until all count bytes are written from
71 * Errors: If any errors occur, this function does not return.
74 ttt_socket_write (int socket,