gethostbyname blocking timeout

I have a Windows NT Workstation 4.0 where I use some socket applications.  There is WINS configured. The applications call the "gethostbyname()" socket function to discover the addresses of the servers.
Sometimes, the network adapter or the cable can be damaged or disconnected in my environment. When it occurs, my applications wait about 3 minutes blocked in the "gethostbyname()" socket api before the error is detected.
I wouldn't like to replace that api by WSAAsyncGetHostByName( ).
Does it exist a way I could use to reduce that timeout ?
Would it be manageable using registry ?
edsontAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

alexoCommented:
What's wrong with WSAAsyncGetHostByName()?

Oh, well...  You can use WSACancelBlockingCall() to cancel the call.  You can use WSASetBlockingHook() to install your own blocking hook.

I'd suggest running gethostbyname() in one thread while another thread waits on a timer and cancels the call on expiry.  Another sulotion is installing a blocking hook before calling gethostbyname(), that will exit after a specified amount of time.

0
edsontAuthor Commented:
My problem is that I really wouldn't like to modify a lot my aplication.
To tell you the truth, I've implemented it as a library function and it is being used in some customers. One of the customers has complained that when there is a problem like a disconnected twisted pair, his application holds for about 3 minutes in my library. I've tested my library and discovered that the "gethostbyname( )" api waits that amount of time in that situation.

I think the best solution would be modifying a "find server address" timeout parameter in the registry, if it exists.

0
alexoCommented:
There are several registry parameters that affect TCP/IP, DNS and WINS timeouts and retransmissions (I've included a list below).  You're probably sufferring from more than one.  Note however that these parametres can affect other timing issues.

I suggest you start with "WinsDownTimeout" and continue with other arguments.

Entries for TCP/IP Parameters.   This subkey is located in following Registry path:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters

DefaultTTL     REG_DWORD
Range: Seconds:      1 - 255
Default: 128
Specifies the default Time To Live (TTL) value set in the header of outgoing IP packets. The TTL determines the maximum amount of time an IP packet can live in the network without reaching its destination. This value acts as a limit on the number of routers an IP packet can pass through before being discarded.

TcpMaxConnectRetransmissions     REG_DWORD
Range: 0 - 0xFFFFFFFF
Default: 3
Determines the number of times TCP will retransmit a connect request (SYN) before aborting the attempt. The retransmission time-out is doubled with each successive retransmission in a given connect attempt. The initial time-out value is three seconds.

TcpMaxDataRetransmissions     REG_DWORD
Range: 0 - 0xFFFFFFFF
Default: 5
Determines the number of times TCP will retransmit an individual data segment (nonconnect segment) before aborting the connection. The retransmission time-out is doubled with each successive retransmission on a connection. It is reset when responses resume. The base time-out value is determined dynamically by measuring the round-trip time of the connection.

KeepAliveInterval     REG_DWORD
Range: 1 - 0xFFFFFFFF milliseconds
Default: 1000  (1 second)
Determines the interval between keep-alive retransmissions until a response is received and, once a response is received, determines the delay until the next keep-alive transmission. The connection will be aborted after the number of retransmissions specified by TcpMaxDataRetransmissions have gone unanswered.


The NetBt\Parameters subkey contains value entries for NetBt (NetBIOS over TCP/IP) common to all NetBt services. This subkey is located in following Registry path:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\NetBt\Parameters

LmhostsTimeout     REG_DWORD
Range: 1000 - 0xFFFFFFFF milliseconds
Default: 6000 (6 seconds)
Specifies the time-out value for LMHOSTS and DNS name queries. The timer has a granularity of the time-out value, so the actual time-out could be as much as twice the value.

NameSrvQueryCount     REG_DWORD    
Range: 0 - 0xFFFF
Default: 3
Determines the number of times NetBT sends a query to a WINS server for a given name without receiving a response.

NameSrvQueryTimeout     REG_DWORD
Range: 100 - 0xFFFFFFFF milliseconds
Default: 1500 (1.5 seconds)
Determines the time interval between successive name queries to WINS for a given name.

WinsDownTimeout     REG_DWORD    
Range: 1000 - 0xFFFFFFFF msec
Default: 15,000 (15 seconds)
Determines how long NetBT waits before trying to use WINS after it fails to contact any WINS server. This feature allows machines that are temporarily disconnected from the network, such as laptops, to proceed through boot processing without waiting for each WINS name registration to time out or query the servers individually.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

edsontAuthor Commented:
I'll try to use you first suggestion because modifying so many registry entries can be pretty dangerous.

0
alexoCommented:
Good luck.  Please share the results.
0
dipenpatel79Commented:
I don't prefer registry update too. Please provide Visual C++ code for getHostByName using WSAAsyncGetHostByName to support timeout? Or Please provide code for solution described above "Another sulotion is installing a blocking hook before calling gethostbyname(),".
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.