chiark / gitweb /
Infrastructure: Split the files into subdirectories.
[mLib] / sel / conn.h
CommitLineData
97f65b00 1/* -*-c-*-
97f65b00 2 *
3 * Nonblocking connect handling
4 *
a3ddb778 5 * (c) 1999 Straylight/Edgeware
97f65b00 6 */
7
d4efbcd9 8/*----- Licensing notice --------------------------------------------------*
97f65b00 9 *
10 * This file is part of the mLib utilities library.
11 *
12 * mLib is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
d4efbcd9 16 *
97f65b00 17 * mLib is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
d4efbcd9 21 *
97f65b00 22 * You should have received a copy of the GNU Library General Public
23 * License along with mLib; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 * MA 02111-1307, USA.
26 */
27
c6e0eaf0 28#ifndef MLIB_CONN_H
29#define MLIB_CONN_H
97f65b00 30
31#ifdef __cplusplus
32 extern "C" {
33#endif
34
35/*----- Header files ------------------------------------------------------*/
36
5feb52af 37#include <sys/types.h>
38#include <sys/socket.h>
39
c6e0eaf0 40#ifndef MLIB_SEL_H
97f65b00 41# include "sel.h"
42#endif
43
44/*----- Data structures ---------------------------------------------------*/
45
46/* --- The nonblocking connect structure --- */
47
48typedef struct conn {
49 sel_file writer; /* Select listener */
50 void (*func)(int /*fd*/, void */*p*/); /* Handler function */
51 void *p; /* Argument for handler function */
52} conn;
53
54/*----- Functions provided ------------------------------------------------*/
55
5934f1ee 56/* --- @conn_fd@ --- *
57 *
58 * Arguments: @conn *c@ = pointer to connection block
59 * @sel_state *s@ = pointer to select state to attach to
60 * @int fd@ = file descriptor of socket
61 * @void (*func)(int fd, void *p) = handler function
62 * @void *p@ = argument for the handler function
63 *
64 * Returns: ---
65 *
66 * Use: Sets up a nonblocking connect job. The socket should have a
67 * connect pending for it already.
68 */
69
70void conn_fd(conn */*c*/, sel_state */*s*/, int /*fd*/,
71 void (*/*func*/)(int /*fd*/, void */*p*/),
72 void */*p*/);
73
97f65b00 74/* --- @conn_init@ --- *
75 *
76 * Arguments: @conn *c@ = pointer to connection block
77 * @sel_state *s@ = pointer to select state to attach to
5feb52af 78 * @int fd@ = file descriptor of socket to connect
79 * @struct sockaddr *dst@ = destination address
80 * @int dsz@ = size of destination address
97f65b00 81 * @void (*func)(int fd, void *p) = handler function
82 * @void *p@ = argument for the handler function
83 *
ff34c6e7 84 * Returns: Zero on success, nonzero on failure.
97f65b00 85 *
5feb52af 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.
97f65b00 93 */
94
ff34c6e7 95extern int 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*/);
97f65b00 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
110extern void conn_kill(conn */*c*/);
111
112/*----- That's all, folks -------------------------------------------------*/
113
114#ifdef __cplusplus
115 }
116#endif
117
118#endif