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_dispatch_func_t) (int connected_socket);
29 /* Create a socket, bind it to the given host and port, and listen in
30 * preparation for incoming connections. See ttt_socket_accept for a
31 * way to actually accept those incoming connections.
33 * Lookup for host (e.g. /etc/hosts and DNA) and port (e.g /etc/services)
34 * will be performed if necessary.
36 * A special host value of "0.0.0.0" may be used to prepare a server
37 * socket to bind to all available addresses.
39 * Return value: The created socket as a file descriptor.
41 * Errors: If any error occurs, this function will not return.
44 ttt_socket_create_server (const char *host, const char *port);
46 /* Wait for an incoming connection on listen_socket, (which should be
47 * a valid socket on which bind and listen have already been
48 * called---see ttt_socket_create_server), then call the dispatch
49 * function with the new socket from the connection.
52 ttt_socket_accept (int listen_socket, ttt_socket_dispatch_func_t dispatch);