comparison libgaim/network.h @ 14267:645598a4ec04

[gaim-migrate @ 16949] Change gaim_network_listen() and gaim_network_listen_range() to be cancelable. This doesn't actually help anything yet, since the gaim_upnp_functions() are not yet cancelable. But the framework is there, and the PRPLs shouldn't need any additional changes. Still to go: gaim_upnp_everything() gaim_url_fetch() gaim_srv_resolve() Let me know if there are others committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 21 Aug 2006 07:47:03 +0000
parents 60b1bc8dbf37
children 34083fe39891
comparison
equal deleted inserted replaced
14266:63ef6342db05 14267:645598a4ec04
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */ 24 */
25 #ifndef _GAIM_NETWORK_H_ 25 #ifndef _GAIM_NETWORK_H_
26 #define _GAIM_NETWORK_H_ 26 #define _GAIM_NETWORK_H_
27 27
28 /*
29 * TODO: This API needs a way to cancel pending calls to
30 * gaim_network_listen_range() and company.
31 */
32
33 #ifdef __cplusplus 28 #ifdef __cplusplus
34 extern "C" { 29 extern "C" {
35 #endif 30 #endif
36 31
37 /**************************************************************************/ 32 /**************************************************************************/
38 /** @name Network API */ 33 /** @name Network API */
39 /**************************************************************************/ 34 /**************************************************************************/
40 /*@{*/ 35 /*@{*/
36
37 typedef struct _GaimNetworkListenData GaimNetworkListenData;
41 38
42 typedef void (*GaimNetworkListenCallback) (int listenfd, gpointer data); 39 typedef void (*GaimNetworkListenCallback) (int listenfd, gpointer data);
43 40
44 /** 41 /**
45 * Converts a dot-decimal IP address to an array of unsigned 42 * Converts a dot-decimal IP address to an array of unsigned
127 * @param cb The callback to be invoked when the port to listen on is available. 124 * @param cb The callback to be invoked when the port to listen on is available.
128 * The file descriptor of the listening socket will be specified in 125 * The file descriptor of the listening socket will be specified in
129 * this callback, or -1 if no socket could be established. 126 * this callback, or -1 if no socket could be established.
130 * @param cb_data extra data to be returned when cb is called 127 * @param cb_data extra data to be returned when cb is called
131 * 128 *
132 * @return TRUE if the callback will be invoked, or FALSE if unable to obtain 129 * @return A pointer to a data structure that can be used to cancel
133 * a local socket to listen on. 130 * the pending listener, or NULL if unable to obtain a local
134 */ 131 * socket to listen on.
135 gboolean gaim_network_listen(unsigned short port, int socket_type, 132 */
136 GaimNetworkListenCallback cb, gpointer cb_data); 133 GaimNetworkListenData *gaim_network_listen(unsigned short port,
134 int socket_type, GaimNetworkListenCallback cb, gpointer cb_data);
137 135
138 /** 136 /**
139 * Opens a listening port selected from a range of ports. The range of 137 * Opens a listening port selected from a range of ports. The range of
140 * ports used is chosen in the following manner: 138 * ports used is chosen in the following manner:
141 * If a range is specified in preferences, these values are used. 139 * If a range is specified in preferences, these values are used.
159 * @param cb The callback to be invoked when the port to listen on is available. 157 * @param cb The callback to be invoked when the port to listen on is available.
160 * The file descriptor of the listening socket will be specified in 158 * The file descriptor of the listening socket will be specified in
161 * this callback, or -1 if no socket could be established. 159 * this callback, or -1 if no socket could be established.
162 * @param cb_data extra data to be returned when cb is called 160 * @param cb_data extra data to be returned when cb is called
163 * 161 *
164 * @return TRUE if the callback will be invoked, or FALSE if unable to obtain 162 * @return A pointer to a data structure that can be used to cancel
165 * a local socket to listen on. 163 * the pending listener, or NULL if unable to obtain a local
166 */ 164 * socket to listen on.
167 gboolean gaim_network_listen_range(unsigned short start, unsigned short end, 165 */
168 int socket_type, GaimNetworkListenCallback cb, gpointer cb_data); 166 GaimNetworkListenData *gaim_network_listen_range(unsigned short start,
167 unsigned short end, int socket_type,
168 GaimNetworkListenCallback cb, gpointer cb_data);
169
170 /**
171 * This can be used to cancel any in-progress listener connection
172 * by passing in the return value from either gaim_network_listen()
173 * or gaim_network_listen_range().
174 *
175 * @param listen_data This listener attempt will be canceled and
176 * the struct will be freed.
177 */
178 void gaim_network_listen_cancel(GaimNetworkListenData *listen_data);
169 179
170 /** 180 /**
171 * Gets a port number from a file descriptor. 181 * Gets a port number from a file descriptor.
172 * 182 *
173 * @param fd The file descriptor. This should be a tcp socket. The current 183 * @param fd The file descriptor. This should be a tcp socket. The current