Re: select() always blocks non-blocking socket



Thank you Volodymyr,

I finally found out the reason for the full timeout on every server response. When the News server I am communicating with has no more data to send it simply stops the conversation so that the last select() call always waits for the entire timeout period until my program "realizes" that no more data is available. I worked around the problem by looking for termination strings like "\r\n.\r\n".

Thanks again, Olaf


"Volodymyr M. Shcherbyna" <v_scherbina@xxxxxxxxxxxxxxx> wrote in message news:%23r%23LnUSsIHA.5724@xxxxxxxxxxxxxxxxxxxxxxx
I checked your code. Your problem does not repeat on my side. If I set timeout on client side, say to 30 seconds (by setting tvTimeout.tv_sec = 30;). And the server replies with data immediately (or after 5 seconds) the select returns just after data arrives. Are you sure that the server sends you data sooner than the timeout expires?

--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
"Olaf Lahl" <olaf.lahl@xxxxxxxxxxxxxxxxxx> wrote in message news:fvnk8p$4cs$1@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,

I have simple app which sends NNTP commands like LIST or GROUP to a news server and attempts to read the server's response. My problem is, that select() will always wait for the entire timeout period event though I created a non-blocking socket. If I specify a small timeout value, select() will frequently return without any data, if I supply a large value like 5 or 10 sec, it will always wait for exactly that amount of time! Isn't the timeout parameter supposed to be a maximum value? Here is the code that does it (error checking and other code ommitted for brevity). Any idea what I'm doing wrong?

Thanks in advance, Olaf

m_Socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
connect( m_Socket, ( sockaddr* )&saServer, sizeof( saServer ) );
u_long ulIoctlBlock = 1;
ioctlsocket( m_Socket, FIONBIO, &ulIoctlBlock ); // <-- Create non-blocking socket
fd_set fdRead;
FD_ZERO( &fdRead );
FD_SET( m_Socket, &fdRead );
timeval tvTimeout;
tvTimeout.tv_sec = 5; // <-- Maximum (?) timeout value
tvTimeout.tv_usec = 0;
for ( int cbBytes = 0, nRet = SOCKET_ERROR; ; )
{
nRet = select( 1, &fdRead, NULL, NULL, &tvTimeout ); <-- Will always wait for the entire timeout period!
if ( nRet == SOCKET_ERROR )
{
break;
}
if ( nRet == 0 )
{
continue;
}
if ( ( cbBytes = recv( m_Socket, chBuffer, ulBufferSize, 0 ) ) <= 0 ) // <-- May reach this line without having read any data if timeout period is zero or too short
{
break;
}
}



.



Relevant Pages

  • Re: Is this an easy fix or complicated one?
    ... that box that opens, properties will be listed..if it isn't working, post ... >> within the required timeout. ... The server %1 did not register with DCOM within the required ... >> If the problem continues to occur, contact the program vendor. ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: RWW timing out
    ... > RWW site as: ... > - Remote Web Workplace timeout ... Restart the IIS Service or restart the SBS Server. ...
    (microsoft.public.windows.server.sbs)
  • RE: RWW timing out
    ... Thank you for posting to the SBS Newsgroup. ... - Remote Web Workplace timeout ... Restart the IIS Service or restart the SBS Server. ...
    (microsoft.public.windows.server.sbs)
  • Re: SQL/ADO (2.8) Timeout Error - Cant resolve
    ... > timeout limit. ... > server, or the code itself or various other issues. ... You can either use Network Monitor to get a sniff of network ... the stored procedure code, then launch the sp from the Access database ...
    (microsoft.public.sqlserver.clients)
  • Re: SQL/ADO (2.8) Timeout Error - Cant resolve
    ... > Server 2000 back end. ... > timeout limit. ... And I’ve used SQL Query Analyzer to run the ... I am running a stored procedure that will backup a SQL Server ...
    (microsoft.public.sqlserver.clients)