[fpc-pascal] socket timeout

Rainer Stratmann rainerstratmann at t-online.de
Wed Apr 17 13:01:31 CEST 2013


 On Wednesday 17 April 2013 10:22:58 you wrote:
> I thought MSG_DONTWAIT is actually the flag to switch to nonblocking mode,
> isn't it?
May be.
> As a matter of fact, the fprecv() above would get a result of -1
> and a sockterror of "Try Again", which is exactly the behavior of
> nonblocking read.
Yes it seems so.

I do always separately switch to the nonblocking mode before.
> 
> 
> 2013/4/17 Rainer Stratmann <rainerstratmann at t-online.de>
> 
> >  On Wednesday 17 April 2013 09:17:09 you wrote:
> > > Will this be a CPU hog:
> > > 
> > > t := Now;
> > > while fprecv(s, @buf, buf_len, MSG_DONTWAIT) < 0 do begin
> > > 
> > >   if Now - t > 0.00001 * timeout then Break;   // approx. <timeout>
> > 
> > seconds
> > 
> > > end;
> > > 
> > > Thanks
> > 
> > I did not read the whole thread, but that you favorite blocking mode
> > (which I
> > don't use).
> > 
> > For MSG_DONTWAIT as far I know you have to change to the nonblocking
> > mode.
> > 
> > > 2013/4/16 Luca Olivetti <luca at ventoso.org>
> > > 
> > > > Al 16/04/13 12:20, En/na Michael Schnell ha escrit:
> > > > > On 04/16/2013 11:26 AM, Xiangrong Fang wrote:
> > > > >> How can I set the connection and read/write timeout when using
> > 
> > socket
> > 
> > > > >> in free pascal?
> > > > > 
> > > > > I seem to remember that synapse can do this.
> > > > 
> > > > Only in svn and it does it this way
> > > > 
> > > > if FConnectionTimeout > 0 then
> > > > begin
> > > > 
> > > >   // connect in non-blocking mode
> > > >   b := NonBlockMode;
> > > >   NonBlockMode := true;
> > > >   SockCheck(synsock.Connect(FSocket, Sin));
> > > >   if (FLastError = WSAEINPROGRESS) OR (FLastError = WSAEWOULDBLOCK)
> > 
> > then
> > 
> > > >     if not CanWrite(FConnectionTimeout) then
> > > >     
> > > >       FLastError := WSAETIMEDOUT;
> > > >   
> > > >   NonBlockMode := b;
> > > > 
> > > > end
> > > > else
> > > > 
> > > >   SockCheck(synsock.Connect(FSocket, Sin));
> > > > 
> > > > NonBlockMode in turn uses fpIoCtl with the FIONBIO parameter,
> > > > WSAEINPROGRESS=EsysEINPROGRESS, WSAEWOULDBLOCK=EsysEWOULDBLOCK and
> > > > CanWrite  does an fpSelect
> > > > 
> > > > Bye
> > > > --
> > > > Luca
> > > > 
> > > > _______________________________________________
> > > > fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> > > > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> > 
> > _______________________________________________
> > fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> > http://lists.freepascal.org/mailman/listinfo/fpc-pascal 



More information about the fpc-pascal mailing list