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