]> git.cworth.org Git - ttt/blobdiff - src/ttt-socket.h
2005-11-09 Carl Worth <cworth@cworth.org>
[ttt] / src / ttt-socket.h
diff --git a/src/ttt-socket.h b/src/ttt-socket.h
new file mode 100644 (file)
index 0000000..59e89a5
--- /dev/null
@@ -0,0 +1,54 @@
+/* ttt-socket.c - Simple interface for creating sockets.
+ *
+ * Copyright © 2005 Carl Worth
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Carl Worth <cworth@cworth.org>
+ */
+
+#ifndef _TTT_SOCKET_H_
+#define _TTT_SOCKET_H_
+
+#include "ttt.h"
+
+typedef void (*ttt_socket_dispatch_func_t) (int connected_socket);
+
+/* Create a socket, bind it to the given host and port, and listen in
+ * preparation for incoming connections. See ttt_socket_accept for a
+ * way to actually accept those incoming connections.
+ *
+ * Lookup for host (e.g. /etc/hosts and DNA) and port (e.g /etc/services)
+ * will be performed if necessary.
+ *
+ * A special host value of "0.0.0.0" may be used to prepare a server
+ * socket to bind to all available addresses.
+ *
+ * Return value: The created socket as a file descriptor.
+ *
+ * Errors: If any error occurs, this function will not return.
+ */
+int
+ttt_socket_create_server (const char *host, const char *port);
+
+/* Wait for an incoming connection on listen_socket, (which should be
+ * a valid socket on which bind and listen have already been
+ * called---see ttt_socket_create_server), then call the dispatch
+ * function with the new socket from the connection.
+ */
+void
+ttt_socket_accept (int listen_socket, ttt_socket_dispatch_func_t dispatch);
+
+#endif