Board index » delphi » SetSocketOpt & Time-out HELP me please!

SetSocketOpt & Time-out HELP me please!

hi to everyone,

I have this question about Time-out:

1.I created a socket with calling soket( ) atc. (Blocking sockets)
2.then I am setting the Socket recv time-out with setSocketOpt

    if setsockopt(FSocket, SOL_SOCKET, SO_RCVTIMEO, PChar(TimeOut),
SizeOf(TimeOut)) <> 0 then ......
this works, cause I don't get any ErrorCodes.... anyways.
btw. the Timeout is an Integer and I set the value to 60000 ms and I did set
the option for Keep-Alive too!!! both sides. Server/Client.

3. I am trying to read the data out of the socket.

    while (not Terminated ) do begin

        GetMem(buffer, BLOCKSIZE);
        ReadBytes := recv(FSocket, Buffer^, BLOCKSIZE, 0);   //I know this
is BLocking and will block the thread until there is Data

//or something goes wrong like TIME-OUT !!!!

        if ReadBytes = SOCKET_ERROR then begin
          FFeedBack(Format(FEEDBACK_FORMAT_SERV, ['Error: ['+
TransLateErrorCode(WSAGetLastError)+ ']']));
          FreeMem(buffer, BLOCKSIZE);
          if not Terminated then terminate;
      until ......

now, it works fine but I never get a time-out, but I am sure I should get
one but I didn't....(using Win 98 and sure not the WinSocket 2!!)
My older Algorithm was using Select for determining a time-out and it was
working very fine, but this won't work ??
What is the problem?? can anyone tell me what's wrong with this??

if I am supposed to use Select() in above source, should I put it before
recv() method ??
 if Select( ) = 0 then handle Time-out else
  recv( )
atc. I guess this will work fine, but I am interested to know why it won't
work as I did it?



Re:SetSocketOpt & Time-out HELP me please!

hi again,

Forget about it...
I solved the problem, that was my mistake.

instead of calling:

 if setsockopt(FSocket, SOL_SOCKET, SO_RCVTIMEO, PChar(TimeOut),
   SizeOf(TimeOut)) <> 0 then ......

I should call

 if setsockopt(FSocket, SOL_SOCKET, SO_RCVTIMEO, PChar(@TimeOut),
  SizeOf(TimeOut)) <> 0 then ......

and so, everything works fine ....


Other Threads