97f65b00 |
1 | /* -*-c-*- |
2 | * |
5934f1ee |
3 | * $Id: conn.h,v 1.7 2003/11/29 19:10:53 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 | |
30 | /*----- Revision history --------------------------------------------------* |
31 | * |
32 | * $Log: conn.h,v $ |
5934f1ee |
33 | * Revision 1.7 2003/11/29 19:10:53 mdw |
34 | * Declare and document @conn_fd@. |
35 | * |
ff34c6e7 |
36 | * Revision 1.6 2001/06/22 19:35:20 mdw |
37 | * Interface change to @conn_init@ -- return error rather than calling the |
38 | * function. This reduces the number of different environments the |
39 | * callback has to cope with, and the old behaviour is easily simulatable |
40 | * with the new, while simulating the new behaviour was awkward and |
41 | * painful. |
42 | * |
c6e0eaf0 |
43 | * Revision 1.5 1999/12/10 23:42:04 mdw |
44 | * Change header file guard names. |
45 | * |
9da403af |
46 | * Revision 1.4 1999/05/26 21:08:01 mdw |
47 | * Remove redundant structure member. |
48 | * |
5feb52af |
49 | * Revision 1.3 1999/05/23 12:12:46 mdw |
50 | * Interface change to make the `conn' selector useful for generic stream |
51 | * sockets rather than just IPv4 ones. |
52 | * |
a3ddb778 |
53 | * Revision 1.2 1999/05/15 10:33:32 mdw |
54 | * Fix copyright notices. |
55 | * |
97f65b00 |
56 | * Revision 1.1 1999/05/14 21:01:14 mdw |
57 | * Integrated `select' handling bits from the background resolver project. |
58 | * |
59 | */ |
60 | |
c6e0eaf0 |
61 | #ifndef MLIB_CONN_H |
62 | #define MLIB_CONN_H |
97f65b00 |
63 | |
64 | #ifdef __cplusplus |
65 | extern "C" { |
66 | #endif |
67 | |
68 | /*----- Header files ------------------------------------------------------*/ |
69 | |
5feb52af |
70 | #include <sys/types.h> |
71 | #include <sys/socket.h> |
72 | |
c6e0eaf0 |
73 | #ifndef MLIB_SEL_H |
97f65b00 |
74 | # include "sel.h" |
75 | #endif |
76 | |
77 | /*----- Data structures ---------------------------------------------------*/ |
78 | |
79 | /* --- The nonblocking connect structure --- */ |
80 | |
81 | typedef struct conn { |
82 | sel_file writer; /* Select listener */ |
83 | void (*func)(int /*fd*/, void */*p*/); /* Handler function */ |
84 | void *p; /* Argument for handler function */ |
85 | } conn; |
86 | |
87 | /*----- Functions provided ------------------------------------------------*/ |
88 | |
5934f1ee |
89 | /* --- @conn_fd@ --- * |
90 | * |
91 | * Arguments: @conn *c@ = pointer to connection block |
92 | * @sel_state *s@ = pointer to select state to attach to |
93 | * @int fd@ = file descriptor of socket |
94 | * @void (*func)(int fd, void *p) = handler function |
95 | * @void *p@ = argument for the handler function |
96 | * |
97 | * Returns: --- |
98 | * |
99 | * Use: Sets up a nonblocking connect job. The socket should have a |
100 | * connect pending for it already. |
101 | */ |
102 | |
103 | void conn_fd(conn */*c*/, sel_state */*s*/, int /*fd*/, |
104 | void (*/*func*/)(int /*fd*/, void */*p*/), |
105 | void */*p*/); |
106 | |
97f65b00 |
107 | /* --- @conn_init@ --- * |
108 | * |
109 | * Arguments: @conn *c@ = pointer to connection block |
110 | * @sel_state *s@ = pointer to select state to attach to |
5feb52af |
111 | * @int fd@ = file descriptor of socket to connect |
112 | * @struct sockaddr *dst@ = destination address |
113 | * @int dsz@ = size of destination address |
97f65b00 |
114 | * @void (*func)(int fd, void *p) = handler function |
115 | * @void *p@ = argument for the handler function |
116 | * |
ff34c6e7 |
117 | * Returns: Zero on success, nonzero on failure. |
97f65b00 |
118 | * |
5feb52af |
119 | * Use: Sets up a nonblocking connect job. The socket should already |
120 | * be bound if you care about that sort of thing. When the |
121 | * connection completes, the handler function is called with the |
122 | * connected socket as an argument. If the connect fails rather |
123 | * than completes, the socket is closed, and the handler is |
124 | * informed of this by being passed a negative file descriptor. |
125 | * In either case, the select job is then removed. |
97f65b00 |
126 | */ |
127 | |
ff34c6e7 |
128 | extern int conn_init(conn */*c*/, sel_state */*s*/, int /*fd*/, |
129 | struct sockaddr */*dst*/, int /*dsz*/, |
130 | void (*/*func*/)(int /*fd*/, void */*p*/), |
131 | void */*p*/); |
97f65b00 |
132 | |
133 | /* --- @conn_kill@ --- * |
134 | * |
135 | * Arguments: @conn *c@ = pointer to connection to dispose of |
136 | * |
137 | * Returns: --- |
138 | * |
139 | * Use: Disposes of a connection when it's not wanted any more. The |
140 | * connect handler function is not called. |
141 | */ |
142 | |
143 | extern void conn_kill(conn */*c*/); |
144 | |
145 | /*----- That's all, folks -------------------------------------------------*/ |
146 | |
147 | #ifdef __cplusplus |
148 | } |
149 | #endif |
150 | |
151 | #endif |