Solved

gethostbyname blocking timeout

Posted on 1998-05-19
6
1,448 Views
Last Modified: 2013-12-03
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 ?
0
Comment
Question by:edsont
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

by:alexo
ID: 1402686
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
 

Author Comment

by:edsont
ID: 1402687
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
 
LVL 11

Accepted Solution

by:
alexo earned 20 total points
ID: 1402688
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:edsont
ID: 1402689
I'll try to use you first suggestion because modifying so many registry entries can be pretty dangerous.

0
 
LVL 11

Expert Comment

by:alexo
ID: 1402690
Good luck.  Please share the results.
0
 

Expert Comment

by:dipenpatel79
ID: 20242690
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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now