Giter Club home page Giter Club logo

mock_client's People

Contributors

gbuddappagari avatar

mock_client's Issues

test

Thanks for reply, I agree with your point. But if you see at line 154 in client-handshake.c, even though you iterate inside loop for Ipv4 address, returned from getaddrinfo, once it returns first Ip then you are coming out from loop by doing break, that means connect() will always try to connect with first address returned from getaddrinfo (even if it get fails due to some temporary network failure reason) and it will never try to do connect() with other address returned from getaddrinfo.

My proposal is something like below for dual network scenario,

#ifdef DUAL_NETWORK_ENABLE
	hints.ai_family = AF_UNSPEC; /*Ipv6 or ipv4*/ 
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_protocol = 0;	
	hints.ai_flags = AI_ADDRCONFIG;
	/* resolving host name */
	retVal = getaddrinfo(host, port, &hints, &result);
	if (retVal != 0){ 
		/* getaddrinfo FAILED */
		return -1;
	} 
	else
	{
		/* iterate all address either Ipv6 or Ipv4  returned from getaddrinfo till connect() success*/
		while(ip_is_present)
		{
					if(rp->ai_family == AF_INET)
						/* getaddrinfo resolved Ipv4 address, Try connect with IPv4 mode */
					else if(rp->ai_family == AF_INET6)
						/* getaddrinfo resolved Ipv6 address, Try connect with IPv6 mode */
					session = socket(rp->ai_family, rp->ai_socktype, 0);
			        if (session == FAILURE)
			       	   /*	FAILED to create socket, Try again with other address  */
				       continue;
	 		        else
			       		/* SUCCESS socket created successfully */
		       		       	       
				   if (connect(session, rp->ai_addr, rp->ai_addrlen) < 0)
				   {
				   		if(errno != SOME_ERRNO_CHECK) 
							/* here close socket and retry the connection*/
							return -1;
						else
							/* Retry again with other address returned from getaddrinfo */
				   }
				   else
				   {
				   		/* Connect is successfull, you can continue with handshake */
				   		break;
				   }
		}
#endif

The reason behind above code is, in my dual stack network case sometimes Ipv6 connection will get fail or refused in some network ip range. So in this case even Ipv4 mapped Ipv6 address also will get fail. If we try with Ipv4 connect then it will connect successfully.

Please check above code and provide your comments. If you feel any additional changes or improvements required then I'm ready to work on that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.