3 * Nonblocking connect handling
5 * (c) 1999 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the mLib utilities library.
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.
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.
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,
35 /*----- Header files ------------------------------------------------------*/
37 #include <sys/types.h>
38 #include <sys/socket.h>
44 /*----- Data structures ---------------------------------------------------*/
46 /* --- The nonblocking connect structure --- */
49 sel_file writer; /* Select listener */
50 void (*func)(int /*fd*/, void */*p*/); /* Handler function */
51 void *p; /* Argument for handler function */
54 /*----- Functions provided ------------------------------------------------*/
56 /* --- @conn_fd@ --- *
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
66 * Use: Sets up a nonblocking connect job. The socket should have a
67 * connect pending for it already.
70 void conn_fd(conn */*c*/, sel_state */*s*/, int /*fd*/,
71 void (*/*func*/)(int /*fd*/, void */*p*/),
74 /* --- @conn_init@ --- *
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
84 * Returns: Zero on success, nonzero on failure.
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.
95 extern int conn_init(conn */*c*/, sel_state */*s*/, int /*fd*/,
96 struct sockaddr */*dst*/, int /*dsz*/,
97 void (*/*func*/)(int /*fd*/, void */*p*/),
100 /* --- @conn_kill@ --- *
102 * Arguments: @conn *c@ = pointer to connection to dispose of
106 * Use: Disposes of a connection when it's not wanted any more. The
107 * connect handler function is not called.
110 extern void conn_kill(conn */*c*/);
112 /*----- That's all, folks -------------------------------------------------*/