chiark / gitweb /
Hack if there is no @_SC_OPEN_MAX@ or @OPEN_MAX@.
[mLib] / conn.h
1 /* -*-c-*-
2  *
3  * $Id: conn.h,v 1.5 1999/12/10 23:42:04 mdw Exp $
4  *
5  * Nonblocking connect handling
6  *
7  * (c) 1999 Straylight/Edgeware
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.5  1999/12/10 23:42:04  mdw
34  * Change header file guard names.
35  *
36  * Revision 1.4  1999/05/26 21:08:01  mdw
37  * Remove redundant structure member.
38  *
39  * Revision 1.3  1999/05/23 12:12:46  mdw
40  * Interface change to make the `conn' selector useful for generic stream
41  * sockets rather than just IPv4 ones.
42  *
43  * Revision 1.2  1999/05/15 10:33:32  mdw
44  * Fix copyright notices.
45  *
46  * Revision 1.1  1999/05/14 21:01:14  mdw
47  * Integrated `select' handling bits from the background resolver project.
48  *
49  */
50
51 #ifndef MLIB_CONN_H
52 #define MLIB_CONN_H
53
54 #ifdef __cplusplus
55   extern "C" {
56 #endif
57
58 /*----- Header files ------------------------------------------------------*/
59
60 #include <sys/types.h>
61 #include <sys/socket.h>
62
63 #ifndef MLIB_SEL_H
64 #  include "sel.h"
65 #endif
66
67 /*----- Data structures ---------------------------------------------------*/
68
69 /* --- The nonblocking connect structure --- */
70
71 typedef struct conn {
72   sel_file writer;                      /* Select listener */
73   void (*func)(int /*fd*/, void */*p*/); /* Handler function */
74   void *p;                              /* Argument for handler function */
75 } conn;
76
77 /*----- Functions provided ------------------------------------------------*/
78
79 /* --- @conn_init@ --- *
80  *
81  * Arguments:   @conn *c@ = pointer to connection block
82  *              @sel_state *s@ = pointer to select state to attach to
83  *              @int fd@ = file descriptor of socket to connect
84  *              @struct sockaddr *dst@ = destination address
85  *              @int dsz@ = size of destination address
86  *              @void (*func)(int fd, void *p) = handler function
87  *              @void *p@ = argument for the handler function
88  *
89  * Returns:     ---
90  *
91  * Use:         Sets up a nonblocking connect job.  The socket should already
92  *              be bound if you care about that sort of thing.  When the
93  *              connection completes, the handler function is called with the
94  *              connected socket as an argument.  If the connect fails rather
95  *              than completes, the socket is closed, and the handler is
96  *              informed of this by being passed a negative file descriptor.
97  *              In either case, the select job is then removed.
98  */
99
100 extern void conn_init(conn */*c*/, sel_state */*s*/, int /*fd*/,
101                       struct sockaddr */*dst*/, int /*dsz*/,
102                       void (*/*func*/)(int /*fd*/, void */*p*/),
103                       void */*p*/);
104
105 /* --- @conn_kill@ --- *
106  *
107  * Arguments:   @conn *c@ = pointer to connection to dispose of
108  *
109  * Returns:     ---
110  *
111  * Use:         Disposes of a connection when it's not wanted any more.  The
112  *              connect handler function is not called.
113  */
114
115 extern void conn_kill(conn */*c*/);
116
117 /*----- That's all, folks -------------------------------------------------*/
118
119 #ifdef __cplusplus
120   }
121 #endif
122
123 #endif