]> git.cworth.org Git - ttt/blob - src/ttt-socket.h
2005-11-09 Carl Worth <cworth@cworth.org>
[ttt] / src / ttt-socket.h
1 /* ttt-socket.c - Simple interface for creating sockets.
2  *
3  * Copyright © 2005 Carl Worth
4  *
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)
8  * any later version.
9  *
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.
14  *
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.
18  *
19  * Author: Carl Worth <cworth@cworth.org>
20  */
21
22 #ifndef _TTT_SOCKET_H_
23 #define _TTT_SOCKET_H_
24
25 #include "ttt.h"
26
27 typedef void (*ttt_socket_dispatch_func_t) (int connected_socket);
28
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.
32  *
33  * Lookup for host (e.g. /etc/hosts and DNA) and port (e.g /etc/services)
34  * will be performed if necessary.
35  *
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.
38  *
39  * Return value: The created socket as a file descriptor.
40  *
41  * Errors: If any error occurs, this function will not return.
42  */
43 int
44 ttt_socket_create_server (const char *host, const char *port);
45
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.
50  */
51 void
52 ttt_socket_accept (int listen_socket, ttt_socket_dispatch_func_t dispatch);
53
54 #endif