Bugs: Browse | Submit New | Admin

[#986] Read Timeout function does not work as expected

Date:
2004-10-21 20:22
Priority:
3
Submitted By:
kleinman (mdufort)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
Read Timeout function does not work as expected

Detailed description
Right now the read option does now return he the number of bytes needed is available before the timeout period. I will
always wait to timeout before returning. This behavior is not correct.

I looked at the source code for specifying timeouts and it is inconsistent with the COMMTIMEOUTS description found on
MSDN.

On MSDN the description for timeouts says: 
-----------------
If an application sets ReadIntervalTimeout and ReadTotalTimeoutMultiplier to MAXDWORD and sets ReadTotalTimeoutConstant
to a value greater than zero and less than MAXDWORD, one of the following occurs when the ReadFile function is called:

    * If there are any bytes in the input buffer, ReadFile returns immediately with the bytes in the buffer.
    * If there are no bytes in the input buffer, ReadFile waits until a byte arrives and then returns immediately.
    * If no bytes arrive within the time specified by ReadTotalTimeoutConstant, ReadFile times out

------------------
I should get this functionality whenever I use a positive value with read_timeout=(anInteger)

Looking at source code for setting the read timeout I see it is not as described by the MSDN article.

static VALUE sp_set_read_timeout(self, val)
  VALUE self, val;
{
  int timeout;
  HANDLE fh;
  COMMTIMEOUTS ctout;

  Check_Type(val, T_FIXNUM);
  timeout = FIX2INT(val);

  fh = sp_get_handle(self);
  if (GetCommTimeouts(fh, &ctout) == 0)
    rb_sys_fail(sGetCommTimeouts);

  if (timeout < 0) {
    ctout.ReadIntervalTimeout = MAXDWORD;
    ctout.ReadTotalTimeoutMultiplier = 0;
    ctout.ReadTotalTimeoutConstant = 0;
  } else if (timeout == 0) {
    ctout.ReadIntervalTimeout = MAXDWORD;
    ctout.ReadTotalTimeoutMultiplier = MAXDWORD;
    ctout.ReadTotalTimeoutConstant = MAXDWORD - 1;
  } else {
    // **************** THIS SECTION IS NOT CORRECT *************
    // ctout.ReadIntervalTimeout = timeout;
    // ctout.ReadTotalTimeoutMultiplier = 0;
    // ctout.ReadTotalTimeoutConstant = timeout;
    // *****************IF SHOULD BE ****************************
    ctout.ReadIntervalTimeout = MAXDWORD;
    ctout.ReadTotalTimeoutMultiplier = MAXDWORD;
    ctout.ReadTotalTimeoutConstant = timeout;
  }

Please advise if my assumption is correct. 
Bye - Martin

Add A Comment: Notepad

Please login


Followup

No Followups Have Been Posted

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item