97f65b00 |
1 | /* -*-c-*- |
2 | * |
3 | * $Id: conn.h,v 1.1 1999/05/14 21:01:14 mdw Exp $ |
4 | * |
5 | * Nonblocking connect handling |
6 | * |
7 | * (c) 1999 Mark Wooding |
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 $ |
33 | * Revision 1.1 1999/05/14 21:01:14 mdw |
34 | * Integrated `select' handling bits from the background resolver project. |
35 | * |
36 | */ |
37 | |
38 | #ifndef CONN_H |
39 | #define CONN_H |
40 | |
41 | #ifdef __cplusplus |
42 | extern "C" { |
43 | #endif |
44 | |
45 | /*----- Header files ------------------------------------------------------*/ |
46 | |
47 | #ifndef SEL_H |
48 | # include "sel.h" |
49 | #endif |
50 | |
51 | /*----- Data structures ---------------------------------------------------*/ |
52 | |
53 | /* --- The nonblocking connect structure --- */ |
54 | |
55 | typedef struct conn { |
56 | sel_file writer; /* Select listener */ |
57 | void (*func)(int /*fd*/, void */*p*/); /* Handler function */ |
58 | void *p; /* Argument for handler function */ |
59 | } conn; |
60 | |
61 | /*----- Functions provided ------------------------------------------------*/ |
62 | |
63 | /* --- @conn_init@ --- * |
64 | * |
65 | * Arguments: @conn *c@ = pointer to connection block |
66 | * @sel_state *s@ = pointer to select state to attach to |
67 | * @unsigned long saddr@ = source IP address |
68 | * @unsigned short sport@ = source port |
69 | * @unsigned long daddr@ = destination IP address |
70 | * @unsigned short dport@ = destination port |
71 | * @void (*func)(int fd, void *p) = handler function |
72 | * @void *p@ = argument for the handler function |
73 | * |
74 | * Returns: --- |
75 | * |
76 | * Use: Sets up a nonblocking connect job. The source address and |
77 | * port can be zero if you don't care. When the connection |
78 | * completes, the handler function is called with the connected |
79 | * socket as an argument. If the connect fails rather than |
80 | * completes, the handler is informed of this by being passed a |
81 | * negative file descriptor. In either case, the select job is |
82 | * then removed. |
83 | */ |
84 | |
85 | extern void conn_init(conn */*c*/, sel_state */*s*/, |
86 | unsigned long /*saddr*/, |
87 | unsigned short /*sport*/, |
88 | unsigned long /*daddr*/, |
89 | unsigned long /*dport*/, |
90 | void (*/*func*/)(int /*fd*/, void */*p*/), |
91 | void */*p*/); |
92 | |
93 | /* --- @conn_kill@ --- * |
94 | * |
95 | * Arguments: @conn *c@ = pointer to connection to dispose of |
96 | * |
97 | * Returns: --- |
98 | * |
99 | * Use: Disposes of a connection when it's not wanted any more. The |
100 | * connect handler function is not called. |
101 | */ |
102 | |
103 | extern void conn_kill(conn */*c*/); |
104 | |
105 | /*----- That's all, folks -------------------------------------------------*/ |
106 | |
107 | #ifdef __cplusplus |
108 | } |
109 | #endif |
110 | |
111 | #endif |