MAOS
Multithreaded Adaptive Optics Simulator
sock.h File Reference

Functions

int socket_recv_timeout (int sock, double sec)
 
int socket_send_timeout (int sock, double sec)
 
int connect_port (const char *hostname, int port, int block, int nodelay)
 
void listen_port (uint16_t port, char *localpath, int(*respond)(int), double timeout_sec, void(*timeout_fun)(), int nodelay)
 
int socket_nopipe (int sock)
 
int socket_block (int sock, int block)
 
int bind_socket (int protocol, char *ip, uint16_t port)
 
int socket_port (int sock)
 
in_addr_t socket_peer (int sock)
 
const char * addr2name (in_addr_t s_addr)
 

Detailed Description

Routines to establish socket connection

Function Documentation

◆ socket_recv_timeout()

int socket_recv_timeout ( int  sock,
double  sec 
)

Set recv timeout in seconds

◆ socket_send_timeout()

int socket_send_timeout ( int  sock,
double  sec 
)

Set recv timeout in seconds

◆ connect_port()

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

Parameters
hostnameThe hostname can be just name or name:port.
portThe port if hostname does not include it
blockDo we block until connection is established
nodelayset TCP nodelay flag

◆ listen_port()

void listen_port ( uint16_t  port,
char *  localpath,
int(*)(int)  responder,
double  timeout_sec,
void(*)()  timeout_fun,
int  nodelay 
)

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

◆ socket_block()

int socket_block ( int  sock,
int  block 
)

Set socket to unblocking mode

◆ bind_socket()

int bind_socket ( int  protocol,
char *  ip,
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

◆ socket_port()

int socket_port ( int  sock)

determine the socket port

◆ socket_peer()

in_addr_t socket_peer ( int  sock)

determine the socket peer IP address

◆ addr2name()

const char* addr2name ( in_addr_t  s_addr)

convert in_addr_t to host name for print out