cnping

Minimal Graphical Ping Tool
git clone https://git.sinitax.com/cnlohr/cnping
Log | Files | Refs | Submodules | README | LICENSE | sfeed.txt

commit 92bdcf452b2a2a62b8905db51be90df305c6b775
parent fc0d927dbbf36fdde198a82260ef9333ed88e680
Author: goeiecool9999 <klaas-richel@hotmail.com>
Date:   Fri, 23 Mar 2018 02:39:46 +0100

Moved the socket/connect back out of the loop

Diffstat:
Mhttping.c | 37+++++++++++++++++--------------------
1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/httping.c b/httping.c @@ -33,7 +33,7 @@ void DoHTTPing( const char * addy, double minperiod, int * seqnoptr, volatile do { struct sockaddr_in serveraddr; struct hostent *server; - int httpsock = 0; + int httpsock; int addylen = strlen(addy); char hostname[addylen+1]; memcpy( hostname, addy, addylen + 1 ); @@ -70,27 +70,24 @@ void DoHTTPing( const char * addy, double minperiod, int * seqnoptr, volatile do serveraddr.sin_family = AF_INET; memcpy((char *)&serveraddr.sin_addr.s_addr, (char *)server->h_addr, server->h_length); serveraddr.sin_port = htons(portno); - - while( 1 ) + +reconnect: + *socketptr = httpsock = socket(AF_INET, SOCK_STREAM, 0); + if (httpsock < 0) { - if( !httpsock ) - { - *socketptr = httpsock = socket(AF_INET, SOCK_STREAM, 0); - if (httpsock < 0) - { - ERRM( "Error opening socket\n" ); - return; - } - - /* connect: create a connection with the server */ - if (connect(httpsock, (struct sockaddr*)&serveraddr, sizeof(serveraddr)) < 0) - { - ERRM( "%s: ERROR connecting\n", hostname ); - goto fail; - } - } + ERRM( "Error opening socket\n" ); + return; + } + /* connect: create a connection with the server */ + if (connect(httpsock, (struct sockaddr*)&serveraddr, sizeof(serveraddr)) < 0) + { + ERRM( "%s: ERROR connecting\n", hostname ); + goto fail; + } + while( 1 ) + { char buf[8192]; int n = sprintf( buf, "HEAD %s HTTP/1.1\r\nConnection: keep-alive\r\n\r\n", eurl?eurl:"/favicon.ico" ); @@ -135,7 +132,7 @@ void DoHTTPing( const char * addy, double minperiod, int * seqnoptr, volatile do #else close( httpsock ); #endif - *socketptr = httpsock = 0; + goto reconnect; } } fail: