![]() |
MAOS
Multithreaded Adaptive Optics Simulator
|
Data Structures | |
| struct | listen_opt_t |
Functions | |
| int | socket_recv_timeout (int sock, long sec) |
| int | socket_send_timeout (int sock, long sec) |
| int | connect_port (const char *hostname, int port, int block, int nodelay) |
| void | listen_port (listen_opt_t opt) |
| void | listen_port_add (int sock, short events, int(*handler)(struct pollfd *, int), const char *caller) |
| void | listen_port_del (int sock, int toclose, const char *caller) |
| int | socket_nopipe (int sock) |
| int | socket_block (int sock, int block) |
| int | bind_socket (int protocol, const char *ipaddr, uint16_t port) |
| int | socket_port (int sock) |
| in_addr_t | socket_peer (int sock) |
| const char * | addr2name (in_addr_t s_addr) |
Routines to establish socket connection
| struct listen_opt_t |
| int socket_recv_timeout | ( | int | sock, |
| long | sec ) |
Set recv timeout in seconds
| int socket_send_timeout | ( | int | sock, |
| long | sec ) |
Set recv timeout in seconds
| int connect_port | ( | const char * | hostname, |
| int | port, | ||
| int | block, | ||
| int | nodelay ) |
Connect to a host at port. If hostname already includes port after :, port is ignored. hostname may start with / to indicate a local UNIX port
| hostname | The hostname can be just name or name:port. |
| port | The port if hostname does not include it |
| block | Do we block until connection is established |
| nodelay | set TCP nodelay flag |
| void listen_port | ( | listen_opt_t | opt | ) |
Open a port and listen to it. Calls respond(sock) to handle data. If timeout_fun is not NULL, it will be called when 1) connection is establed/handled, 2) every timeout_sec if timeout_sec>0. This function only return at error. if localpath is not null and start with /, open the local unix port also if localpath is not null and contains ip address, only bind to that ip address
| void listen_port_add | ( | int | sock, |
| short | events, | ||
| int(* | handler )(struct pollfd *, int), | ||
| const char * | name ) |
Add a socket to the pollfd array for event monitoring.
| sock | The socket file descriptor to add. |
| events | The events to monitor (e.g., POLLIN, POLLOUT). |
| handler | The function to handle events on this socket (can be NULL for internal handling). |
| name | A descriptive name for this socket (for debugging/logging). |
If the socket is already present, updates its handler and name if necessary. Allocates memory for new entries as needed.
| void listen_port_del | ( | int | sock, |
| int | toclose, | ||
| const char * | caller ) |
Remove a socket from the pollfd array, optionally closing it.
| sock | The socket file descriptor to remove; if -2, remove all sockets. |
| toclose | If nonzero, close the socket(s) before removing. |
| caller | A string indicating the caller for logging/debugging purposes. |
This function does not close the socket if toclose is zero. If sock is -2, all sockets are removed.
| int socket_block | ( | int | sock, |
| int | block ) |
Set socket to unblocking mode
| int bind_socket | ( | int | protocol, |
| const char * | ipaddr, | ||
| uint16_t | port ) |
make a server port and bind to localhost on all addresses. protocl is usually SOCK_DGRAM or SOCK_STREAM. ip is usually zero. if port is 0, will bind an assigned port
| int socket_port | ( | int | sock | ) |
determine the socket port
| in_addr_t socket_peer | ( | int | sock | ) |
determine the socket peer IP address
| const char * addr2name | ( | in_addr_t | s_addr | ) |
convert in_addr_t to host name for print out