chiark / gitweb /
hash: Trivial whitespace cleanups.
[mLib] / conn.h
CommitLineData
97f65b00 1/* -*-c-*-
2 *
8656dc50 3 * $Id: conn.h,v 1.8 2004/04/08 01:36:11 mdw Exp $
97f65b00 4 *
5 * Nonblocking connect handling
6 *
a3ddb778 7 * (c) 1999 Straylight/Edgeware
97f65b00 8 */
9
10/*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of the mLib utilities library.
13 *
14 * mLib is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
18 *
19 * mLib is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
23 *
24 * You should have received a copy of the GNU Library General Public
25 * License along with mLib; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 * MA 02111-1307, USA.
28 */
29
c6e0eaf0 30#ifndef MLIB_CONN_H
31#define MLIB_CONN_H
97f65b00 32
33#ifdef __cplusplus
34 extern "C" {
35#endif
36
37/*----- Header files ------------------------------------------------------*/
38
5feb52af 39#include <sys/types.h>
40#include <sys/socket.h>
41
c6e0eaf0 42#ifndef MLIB_SEL_H
97f65b00 43# include "sel.h"
44#endif
45
46/*----- Data structures ---------------------------------------------------*/
47
48/* --- The nonblocking connect structure --- */
49
50typedef struct conn {
51 sel_file writer; /* Select listener */
52 void (*func)(int /*fd*/, void */*p*/); /* Handler function */
53 void *p; /* Argument for handler function */
54} conn;
55
56/*----- Functions provided ------------------------------------------------*/
57
5934f1ee 58/* --- @conn_fd@ --- *
59 *
60 * Arguments: @conn *c@ = pointer to connection block
61 * @sel_state *s@ = pointer to select state to attach to
62 * @int fd@ = file descriptor of socket
63 * @void (*func)(int fd, void *p) = handler function
64 * @void *p@ = argument for the handler function
65 *
66 * Returns: ---
67 *
68 * Use: Sets up a nonblocking connect job. The socket should have a
69 * connect pending for it already.
70 */
71
72void conn_fd(conn */*c*/, sel_state */*s*/, int /*fd*/,
73 void (*/*func*/)(int /*fd*/, void */*p*/),
74 void */*p*/);
75
97f65b00 76/* --- @conn_init@ --- *
77 *
78 * Arguments: @conn *c@ = pointer to connection block
79 * @sel_state *s@ = pointer to select state to attach to
5feb52af 80 * @int fd@ = file descriptor of socket to connect
81 * @struct sockaddr *dst@ = destination address
82 * @int dsz@ = size of destination address
97f65b00 83 * @void (*func)(int fd, void *p) = handler function
84 * @void *p@ = argument for the handler function
85 *
ff34c6e7 86 * Returns: Zero on success, nonzero on failure.
97f65b00 87 *
5feb52af 88 * Use: Sets up a nonblocking connect job. The socket should already
89 * be bound if you care about that sort of thing. When the
90 * connection completes, the handler function is called with the
91 * connected socket as an argument. If the connect fails rather
92 * than completes, the socket is closed, and the handler is
93 * informed of this by being passed a negative file descriptor.
94 * In either case, the select job is then removed.
97f65b00 95 */
96
ff34c6e7 97extern int conn_init(conn */*c*/, sel_state */*s*/, int /*fd*/,
98 struct sockaddr */*dst*/, int /*dsz*/,
99 void (*/*func*/)(int /*fd*/, void */*p*/),
100 void */*p*/);
97f65b00 101
102/* --- @conn_kill@ --- *
103 *
104 * Arguments: @conn *c@ = pointer to connection to dispose of
105 *
106 * Returns: ---
107 *
108 * Use: Disposes of a connection when it's not wanted any more. The
109 * connect handler function is not called.
110 */
111
112extern void conn_kill(conn */*c*/);
113
114/*----- That's all, folks -------------------------------------------------*/
115
116#ifdef __cplusplus
117 }
118#endif
119
120#endif