From: hackbard Date: Fri, 5 Nov 2004 12:15:37 +0000 (+0000) Subject: added timeout functionality X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=195f89f8c46af637b38761cb0f7a76d58eaaaa05;p=my-code%2Fapi.git added timeout functionality --- diff --git a/network/network.c b/network/network.c index 1cdd38c..c8022e5 100644 --- a/network/network.c +++ b/network/network.c @@ -18,6 +18,23 @@ int network_init(t_net *net,int outfd) { return N_SUCCESS; } +int network_set_timeout_chan(t_net *net,int chan,int read,int write) { + + struct timeval to; + socklen_t len; + + len=sizeof(struct timeval); + + to.tv_usec=0; + + to.tv_sec=read; + setsockopt(net->connection[chan].fd,SOL_SOCKET,SO_RCVTIMEO,&to,len); + to.tv_sec=write; + setsockopt(net->connection[chan].fd,SOL_SOCKET,SO_SNDTIMEO,&to,len); + + return N_SUCCESS; +} + int network_listen(t_net *net) { struct sockaddr_in addr; diff --git a/network/network.h b/network/network.h index 4f5e87e..7ef6301 100644 --- a/network/network.h +++ b/network/network.h @@ -69,6 +69,7 @@ typedef struct s_net { /* function prototypes */ int network_init(t_net *net,int outfd); +int network_set_timeout(t_net *net,int chan,int read,int write); int network_listen(t_net *net); int network_shutdown(t_net *net); int network_set_listen_port(t_net *net,in_port_t port);