| 107 * This function is useful, for example, if you wanted to write a telnet |
109 * This function is useful, for example, if you wanted to write a telnet |
| 108 * server as a Gaim plugin, and you HAD to listen on port 23. Why anyone |
110 * server as a Gaim plugin, and you HAD to listen on port 23. Why anyone |
| 109 * would want to do that is beyond me. |
111 * would want to do that is beyond me. |
| 110 * |
112 * |
| 111 * This opens a listening port. The caller will want to set up a watcher |
113 * This opens a listening port. The caller will want to set up a watcher |
| 112 * of type GAIM_INPUT_READ on the returned fd. It will probably call |
114 * of type GAIM_INPUT_READ on the fd returned in cb. It will probably call |
| 113 * accept in the callback, and then possibly remove the watcher and close |
115 * accept in the watcher callback, and then possibly remove the watcher and close |
| 114 * the listening socket, and add a new watcher on the new socket accept |
116 * the listening socket, and add a new watcher on the new socket accept |
| 115 * returned. |
117 * returned. |
| 116 * |
118 * |
| 117 * @param port The port number to bind to. Must be greater than 0. |
119 * @param port The port number to bind to. Must be greater than 0. |
| 118 * @param socket_type The type of socket to open for listening. |
120 * @param socket_type The type of socket to open for listening. |
| 119 * This will be either SOCK_STREAM for TCP or SOCK_DGRAM for UDP. |
121 * This will be either SOCK_STREAM for TCP or SOCK_DGRAM for UDP. |
| |
122 * @param cb The callback to be invoked when the port to listen on is available. |
| |
123 * The file descriptor of the listening socket will be specified in |
| |
124 * this callback, or -1 if no socket could be established. |
| |
125 * @param cb_data extra data to be returned when cb is called |
| 120 * |
126 * |
| 121 * @return The file descriptor of the listening socket, or -1 if |
127 * @return TRUE if the callback will be invoked, or FALSE if unable to obtain |
| 122 * no socket could be established. |
128 * a local socket to listen on. |
| 123 */ |
129 */ |
| 124 int gaim_network_listen(unsigned short port, int socket_type); |
130 gboolean gaim_network_listen(unsigned short port, int socket_type, |
| |
131 GaimNetworkListenCallback cb, gpointer cb_data); |
| 125 |
132 |
| 126 /** |
133 /** |
| 127 * Opens a listening port selected from a range of ports. The range of |
134 * Opens a listening port selected from a range of ports. The range of |
| 128 * ports used is chosen in the following manner: |
135 * ports used is chosen in the following manner: |
| 129 * If a range is specified in preferences, these values are used. |
136 * If a range is specified in preferences, these values are used. |
| 130 * If a non-0 values are passed to the function as parameters, these |
137 * If a non-0 values are passed to the function as parameters, these |
| 131 * values are used. |
138 * values are used. |
| 132 * Otherwise a port is chosen at random by the kernel. |
139 * Otherwise a port is chosen at random by the kernel. |
| 133 * |
140 * |
| 134 * This opens a listening port. The caller will want to set up a watcher |
141 * This opens a listening port. The caller will want to set up a watcher |
| 135 * of type GAIM_INPUT_READ on the returned fd. It will probably call |
142 * of type GAIM_INPUT_READ on the fd returned in cb. It will probably call |
| 136 * accept in the callback, and then possibly remove the watcher and close |
143 * accept in the watcher callback, and then possibly remove the watcher and close |
| 137 * the listening socket, and add a new watcher on the new socket accept |
144 * the listening socket, and add a new watcher on the new socket accept |
| 138 * returned. |
145 * returned. |
| 139 * |
146 * |
| 140 * @param start The port number to bind to, or 0 to pick a random port. |
147 * @param start The port number to bind to, or 0 to pick a random port. |
| 141 * Users are allowed to override this arg in prefs. |
148 * Users are allowed to override this arg in prefs. |
| 142 * @param end The highest possible port in the range of ports to listen on, |
149 * @param end The highest possible port in the range of ports to listen on, |
| 143 * or 0 to pick a random port. Users are allowed to override this |
150 * or 0 to pick a random port. Users are allowed to override this |
| 144 * arg in prefs. |
151 * arg in prefs. |
| 145 * @param socket_type The type of socket to open for listening. |
152 * @param socket_type The type of socket to open for listening. |
| 146 * This will be either SOCK_STREAM for TCP or SOCK_DGRAM for UDP. |
153 * This will be either SOCK_STREAM for TCP or SOCK_DGRAM for UDP. |
| |
154 * @param cb The callback to be invoked when the port to listen on is available. |
| |
155 * The file descriptor of the listening socket will be specified in |
| |
156 * this callback, or -1 if no socket could be established. |
| |
157 * @param cb_data extra data to be returned when cb is called |
| 147 * |
158 * |
| 148 * @return The file descriptor of the listening socket, or -1 if |
159 * @return TRUE if the callback will be invoked, or FALSE if unable to obtain |
| 149 * no socket could be established. |
160 * a local socket to listen on. |
| 150 */ |
161 */ |
| 151 int gaim_network_listen_range(unsigned short start, unsigned short end, |
162 gboolean gaim_network_listen_range(unsigned short start, unsigned short end, |
| 152 int socket_type); |
163 int socket_type, GaimNetworkListenCallback cb, gpointer cb_data); |
| 153 |
164 |
| 154 /** |
165 /** |
| 155 * Gets a port number from a file descriptor. |
166 * Gets a port number from a file descriptor. |
| 156 * |
167 * |
| 157 * @param fd The file descriptor. This should be a tcp socket. The current |
168 * @param fd The file descriptor. This should be a tcp socket. The current |