#include "libut/ut.h" int UT_net_connect(char *name, UT_fd_cb *cb, void *data, int flags,...);
This function attempts to establish a TCP/IP socket to a particular host and port. The function also permits the source IP address and port to be specified, or these can be chosen automatically by the kernel.
The name argument is a descriptive name for the connection (which will be copied, and silently truncated if too long). This name is only used in the output of the fds control port command and in log messages.
The cb argument specifies the callback to be invoked when the connection succeeds or fails, and (in the case of success) when data from the remote side is readable. See the CALLBACK section below.
The data argument is an opaque pointer that is passed back to the callback.
The flags argument is a bitwise-OR using these pre-defined constants:
The I/O callback must have this prototype: int (UT_fd_cb)(int fd, char *name, int status, void *data);
The name and data arguments are passed to the callback exactly as they were passed to UT_net_connect(). The fd argument is the file descriptor of the socket. The status argument informs the callback of the disposition of the file descriptor using the following bits (other bits may be set and must be ignored):
When the connection is no longer needed, or the callback detects that the remote
side has closed the socket, the callback should call close(2)
and
UT_fd_unreg(2)
on the file descriptor.
The callback's return value is ignored.
If an error occurs, -1 is returned and the reason is logged. A non-negative return value indicates that a connection attempt has been initiated; it may or may not be accepted. The callback will be notified when the connection is accepted or fails.
The fds control port command displays connecting sockets, and other file descriptors.
UT_net_resolve(3), UT_fd_cntl(3), UT_net_listen(3)
Troy D. Hanson <thanson@users.sourceforge.net>