Re: [fpc-pascal] fphttclient, no way to specify a connect timeout
El 24/02/18 a les 15:38, Dimitrios Chr. Ioannidis via fpc-pascal ha escrit: The only reliable way to enforce a connect timeout is to try to connect in non-blocking mode. Something like this ( sorry again in ssockects.pp ) for windows only, very draft code proof of concept which it works ( windows 10 here ) : Thank you but never mind: I changed my application to use synapse. Bye -- Luca ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fphttclient, no way to specify a connect timeout
Hi, Στις 24/2/2018 2:00 μμ, ο Luca Olivetti έγραψε: < snip > OK. I got it. Point taken. I don't think you did No I really did ;). The only reliable way to enforce a connect timeout is to try to connect in non-blocking mode. Something like this ( sorry again in ssockects.pp ) for windows only, very draft code proof of concept which it works ( windows 10 here ) : Procedure TInetSocket.Connect; Var A : THostAddr; addr: TInetSockAddr; Res : Integer; nb: DWord; fds: WinSock2.TFDSet; opt: LongInt = 1; len: LongInt; tv : timeval; rslt: longint; begin A := StrToHostAddr(FHost); if A.s_bytes[1] = 0 then With THostResolver.Create(Nil) do try If Not NameLookup(FHost) then raise ESocketError.Create(seHostNotFound, [FHost]); A:=HostAddress; finally free; end; addr.sin_family := AF_INET; addr.sin_port := ShortHostToNet(FPort); addr.sin_addr.s_addr := HostToNet(a.s_addr); tv.tv_sec := IOTIMEOUT div 1000; tv.tv_usec := 0; WinSock2.FD_ZERO(fds); WinSock2.FD_SET(Handle, fds); nb := 1; rslt := WinSock2.ioctlsocket(HANDLE, WinSock2.FIONBIO, @nb); writeln(IntToStr(rslt)); {$ifdef unix} Res := ESysEINTR; while (Res = ESysEINTR) do {$endif} Res := fpConnect(Handle, @addr, sizeof(addr)); if WinSock2.select(Handle, nil, @fds, nil, @tv) > 0 then begin len := SizeOf(opt); if WinSock2.FD_ISSET(Handle, FDS) then fpgetsockopt(Handle, SOL_SOCKET, SO_ERROR, @OPT, @LEN); Res := Opt; end; nb := 0; WinSock2.ioctlsocket(HANDLE, WinSock2.FIONBIO, @nb); If Not (Res<0) then if not FHandler.Connect then begin Res:=-1; CloseSocket(Handle); end; If (Res<0) then Raise ESocketError.Create(seConnectFailed, [Format('%s:%d',[FHost, FPort])]); end; regards, -- Dimitrios Chr. Ioannidis ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fphttclient, no way to specify a connect timeout
El 24/02/18 a les 13:00, Luca Olivetti ha escrit: Sure, with some combination of kernel/winsock version it could possibly work (with mine it doesn't), but then it would be just enough to set the IoTimeout in the TFpHttpClient (which I'm already doing), no need to modify ssockets.pp. Correction: it works in linux (IIRC it didn't some years ago, now it's a documented feature, see https://linux.die.net/man/7/socket) but it doesn't in windows (where the only option is to use a non-blocking socket). Unluckily enough, my current target is windows :-( Test procedure: procedure TForm1.Button1Click(Sender: TObject); var c:TFPHTTPClient; inicio: QWord; begin c:=TFPHTTPClient.Create(nil); c.IOTimeout:=500; inicio:=GetTickCount64; try memo1.lines.add(c.Get('http://192.168.10.221/')); except on e:exception do memo1.lines.add(e.Message); end; caption:=IntToStr(GetTickCount64-inicio); c.free; end; The timeout is roughly 500 ms under linux, 18-20 seconds under windows (xp/7, didn't test 10). Bye -- Luca ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fphttclient, no way to specify a connect timeout
El 24/02/18 a les 10:19, Dimitrios Chr. Ioannidis via fpc-pascal ha escrit: Hi, On 2018-02-24 03:42, Luca Olivetti wrote: El 23/02/18 a les 22:57, Dimitrios Chr. Ioannidis via fpc-pascal ha escrit: Hi Στις 23/2/2018 11:14 μμ, ο Luca Olivetti έγραψε: The TFPCustomHTTPClient calls TInetSocket.Create constructor which it calls the inherited constructor from TSocketStream. Which, since TFPHttpClient assigns a socket handler in G, it won't call connect. So the timeout set above is really done before the connect call. OK. I got it. Point taken. I don't think you did: what you are proposing is what TFpHttpClient already does, I traced it, it really does the call to SetIoTimeout before the connect call, and it doesn't work. The only reliable way to enforce a connect timeout is to try to connect in non-blocking mode. Sure, with some combination of kernel/winsock version it could possibly work (with mine it doesn't), but then it would be just enough to set the IoTimeout in the TFpHttpClient (which I'm already doing), no need to modify ssockets.pp. Bye -- Luca ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpreport rangeerrors with TFPReportColor
On Sat, 24 Feb 2018, Andreas Frieß wrote: Depending on the Information of the list here i have created some patches and an Bug-Report https://bugs.freepascal.org/view.php?id=33217 The heats of my changes is a more typesafe conversion and to use QWord for the JSON. So nothing is broken and it rangechecksafe now. Checked, and applied your patch. Many thanks. The font issue is also something we seem to have missed :/ Michael.___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpreport rangeerrors with TFPReportColor
Depending on the Information of the list here i have created some patches and an Bug-Report https://bugs.freepascal.org/view.php?id=33217 The heats of my changes is a more typesafe conversion and to use QWord for the JSON. So nothing is broken and it rangechecksafe now. - a small snippet function QWordToReportColor(AQWord: QWord):TFPReportColor; begin Result := TFPReportColor(AQWord and $); end; The second, i foung a not created Font, if you are not using Parent-Fonts. Also fixed. Thx to all who have some things more clear to me AND why. Andreas Am 22.02.2018 um 08:05 schrieb Michael Van Canneyt: On Thu, 22 Feb 2018, Andreas Frieß wrote: Another possible Problem with the definition TFPColor (fpc) record with word <> TColor (lazarus) -$7FFF-1..$7FFF <> TFPReportColor (fpreport) UInt32 So you cannot use in Lazarus the 'well known' TColors. With TColor it is also Delphi compatible. Using TColor is not an option, it is windows specific and depeds on Graphics. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fphttclient, no way to specify a connect timeout
Hi, On 2018-02-24 03:42, Luca Olivetti wrote: El 23/02/18 a les 22:57, Dimitrios Chr. Ioannidis via fpc-pascal ha escrit: Hi Στις 23/2/2018 11:14 μμ, ο Luca Olivetti έγραψε: The TFPCustomHTTPClient calls TInetSocket.Create constructor which it calls the inherited constructor from TSocketStream. Which, since TFPHttpClient assigns a socket handler in G, it won't call connect. So the timeout set above is really done before the connect call. OK. I got it. Point taken. You don't want to try to see if it works. Instead we exchange unnecessary emails. My bad. Apologies for pushing you. regards, PS: I'm sure Michael at least he'll take a look. -- Dimitrios Chr. Ioannidis ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal