|
Time-Outs
A handle to a communications resource has an associated set of time-out
parameters that affect the behavior of read and write operations. Time-outs can cause
a ReadFile, ReadFileEx, WriteFile, or WriteFileEx operation to conclude when a time-out interval elapses, even though the
specified number of characters have not been read or written. It is not treated as
an error when a time-out occurs during a read or write operation (that is, the
read or write function's return value indicates success). The count of bytes
actually read or written is reported by ReadFile or WriteFile (or by the GetOverlappedResult or FileIOCompletionRoutine function, if the I/O was performed as an overlapped operation).
When an application opens a communications resource, the operating system sets
the resource's time-out values to the values in effect when the resource was
last used. If the communications resource has never been opened, the operating
system sets the time-out values to some default value. In either case, an
application should always determine the current time-out values after opening the
resource, and then explicitly set them to meet its requirements. To determine the
current time-out values of a communications resource, use the GetCommTimeouts function. To change the time-out values, use the SetCommTimeouts function.
Two types of time-outs are enabled by the time-out parameters. An interval
time-out occurs when the time between the receipt of any two characters exceeds a
specified number of milliseconds. Timing starts when the first character is
received and is restarted when each new character is received. A total time-out
occurs when the total amount of time consumed by a read operation exceeds a
calculated number of milliseconds. Timing starts immediately when the I/O operation
begins. Write operations support only total time-outs. Read operations support
both interval and total time-outs, which can be used separately or combined.
The time, in milliseconds, of the total time-out period for a read or write
operation is calculated by using the multiplier and constant values from the COMMTIMEOUTS structure specified in the GetCommTimeouts or SetCommTimeouts function. The following formula is used:
Timeout = (MULTIPLIER * number_of_bytes) + CONSTANT
Using both a multiplier and a constant enables the total time-out period to
vary, depending on the amount of data being requested. An application can use
only the constant by setting the multiplier to zero, or use only the multiplier by
setting the constant to zero. If both the constant and multiplier are zero,
total time-out is not used.
If all read time-out parameters are zero, read time-outs are not used, and a
read operation is not complete until the requested number of bytes have been
read or an error occurs. Similarly, if all write time-out parameters are zero, a
write operation is not completed until the requested number of bytes have been
written or an error occurs.
If the read interval time-out parameter is the MAXDWORD value and both read
total time-out parameters are zero, a read operation is completed immediately
after reading whatever characters are available in the input buffer, even if it is
empty. This is the same as the ReadComm function in previous versions of Windows.
Interval timing forces a read operation to return when there is a lull in
reception. A process using interval time-outs can set a fairly short interval
parameter, so it can respond quickly to small, isolated bursts of one or a few
characters, yet it can still collect large buffers of characters with a single call
when data is received in a steady stream.
Time-outs for a write operation can be useful when transmission is blocked by
some kind of flow control or when the SetCommBreak function has been called to suspend character transmission.
The following table summarizes the behavior of read operations based on the
values specified for total and interval time-outs.
Total
| Interval
| Behavior
| 0
| 0
| Returns when the buffer is completely filled. Time-outs are not used.
| T
| 0
| Returns when the buffer is completely filled or when T milliseconds have
elapsed since the beginning of the operation.
| 0
| Y
| Returns when the buffer is completely filled or when Y milliseconds have
elapsed between the receipt of any two characters. Timing does not begin until the
first character is received.
| T
| Y
| Returns when the buffer is completely filled or when either type of time-out
occurs.
|
Note, however, that timing is relative to the system controlling the physical
device. For a remote device such as a modem, the timing is relative to the
server system to which the modem is attached. Any network propagation delay is not
factored in. For example, a client application might specify a total time-out
that computes to be 500 milliseconds. When 500 milliseconds have elapsed at the
server, a time-out error is returned to the client. If there is a 50
milliseconds network propagation delay, the client will not be notified of the time-out
until approximately 50 milliseconds after the time-out actually occurred.
The time-out parameters affect the behavior of overlapped read and write
operations on a communications device. With overlapped I/O, the ReadFile, WriteFile, ReadFileEx, or WriteFileEx function can return before the operation has been completed. The time-out
parameters can determine when the operation has been completed.
| Last news from Greatis Software |
 |
|
Nostalgia .Net |
|
.Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes. More » |
| Recommended software for developers |
 |
|
Ultimate Pack |
|
Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price. More » |
 |
|
Form Designer .Net |
|
Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro! More » |
 |
|
Print Suite .Net |
|
Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available More » |
 |
|
Gradient Controls .Net |
|
Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available More » |
 |
|
Greatis iGrid |
|
iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors. More » |
All the contacts and projectsDmitry Vasiliev (just.dmitry)
Related LinksSoftware for Visual Studio .NET developers Software for Delphi and C++ Builder developers Software for Visual Basic 6 developers Delphi Tips&Tricks MegaDetailed.NET More Online Helps Win32 Programmer's Reference Win32 Multimedia Programmer's Reference OLE Programmer's Reference Microsoft Windows Pen API Programmer's Reference Microsoft Windows Sockets 2 Reference Microsoft Windows Telephony API (TAPI) Programmer's Reference Unix Manual Pages
|