Re: [Nagios-devel] netutils use of socket descriptor

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

Re: [Nagios-devel] netutils use of socket descriptor

Post by Guest »

This is a multi-part message in MIME format.
--------------070106070308030801070206
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 15/06/09 02:27 PM, Thomas Guyot-Sionnest wrote:
>
> A better way of doing this is to send a connect for the next ip in list
> every n miliseconds (where n is a small fraction of the timeout, you
> could for example take half of the timeout and divide it by the number
> of IP), use the first connected socket and clean up the rest.
>
>

Just for clarification I'm not necessarily saying that we should do it
this way, but that if we really want to try all IPs that's the way
(IMHO) it should be done.

The attached patch removes the useless loop. There's no real-world
testing besides the compilation/tests.

- --
Thomas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFKNqS16dZ+Kt5BchYRAvnQAJ9bB5WMc6X9VRsj6/Pb7t54T1k+UgCeIbc9
wfnCEeJR+pt7N5cEyA8N+ls=
=xpIe
-----END PGP SIGNATURE-----

--------------070106070308030801070206
Content-Type: text/plain;
name="netutils.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="netutils.patch"

diff --git a/base/netutils.c b/base/netutils.c
index 09f9453..443bc91 100644
--- a/base/netutils.c
+++ b/base/netutils.c
@@ -31,7 +31,7 @@
/* connect to a TCP socket in nonblocking fashion */
int my_tcp_connect(char *host_name, int port, int *sd, int timeout){
struct addrinfo hints;
- struct addrinfo *r,*res;
+ struct addrinfo *res;
int result;
char *port_str=NULL;
int flags=0;
@@ -52,29 +52,19 @@ int my_tcp_connect(char *host_name, int port, int *sd, int timeout){
return ERROR;
}

- /* attempt to create a socket */
- r=res;
- while(r){
-
- *sd=socket(r->ai_family,SOCK_STREAM,r->ai_protocol);
- if(*sd0)
- break;
-
- close(*sd);
- r=r->ai_next;
+ /* create a socket */
+ *sd=socket(res->ai_family,SOCK_STREAM,res->ai_protocol);
+ if(*sdai_addr,r->ai_addrlen);
+ result=connect(*sd,res->ai_addr,res->ai_addrlen);

/* immediately successful connect */
if(result==0){

--------------070106070308030801070206--





This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked