Re: [fpc-pascal] fphttclient, no way to specify a connect timeout
El 23/02/18 a les 22:57, Dimitrios Chr. Ioannidis via fpc-pascal ha escrit: Hi Στις 23/2/2018 11:14 μμ, ο Luca Olivetti έγραψε: yes, it does (in procedure TFPCustomHTTPClient.ConnectToServer) FSocket:=TInetSocket.Create(AHost,APort,G); try if FIOTimeout<>0 then FSocket.IOTimeout:=FIOTimeout; <- FSocket.Connect; except FreeAndNil(FSocket); Raise; end; please follow the call stack. 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. Bye -- Luca ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] C header to Pascal , what is the type of ENUM?
Am 23.02.2018 um 16:06 schrieb Dennis: > In C > ENUM_BEGIN( RetCode ) TA-Lib has very weird macros. It should expand to "enum class RetCode" (so it's actually C++), making this an int or unsigned int (depending on the compiler). Should be a Longword on >32bit compilers then. And (MvC will be disappointed if I wouldn't say it): don't translate as a Pascal enum unless you know what you're doing. -- Regards, Martok Ceterum censeo b32079 esse sanandam. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fcl-web - html web modules
2018-02-23 19:36 GMT-03:00 Michael Van Canneyt : > > What is not clear ? There are several samples available that show their > use ? > > Also the WIKI has some pages about it > http://wiki.freepascal.org/fcl-web > > There are some articles > https://idefix.freepascal.org/~michael/articles/ > > see the web1 and web2 and webserver articles. > > I think Web2 explains what you need. According to your article, "Session support is introduced by TSessionHTTPModule". However, TFPHTMLModule descends from TCustomHTMLModule. TCustomHTMLModule descends from TCustomHTTPModule. Then, there is no session support for TFPHTMLModule. Another point: using TFPHTMLModule, request are handled by the module itself through the OnGetContent event, not by the actions. In the other words, the request never is transferred to the actions. *procedure TCustomHTMLModule.HandleRequest(ARequest: TRequest; AResponse: TResponse);* *Var* * FWriter : THTMLWriter;* * B : Boolean;* * M : TMemoryStream;* *begin* * FDocument := CreateDocument;* * Try* *FWriter:=CreateWriter(FDocument);* *Try* * B:=False;* * If Assigned(OnGetContent) then* *OnGetContent(Self,ARequest,FWriter,B);* * If Not B then* *Raise EHTMLError.Create(SErrRequestNotHandled);* * If (AResponse.ContentStream=Nil) then* *begin* *M:=TMemoryStream.Create;* *AResponse.ContentStream:=M;* *end;* * FDocument.SaveToStream(AResponse.ContentStream);* *Finally* * FreeAndNil(FWriter);* *end;* * Finally* *FreeAndNil(FDocument);* * end;* *end;* ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fcl-web - html web modules
On Fri, 23 Feb 2018, African Wild Dog wrote: Hello, How to use action and sessions with HTML Web Modules? What is not clear ? There are several samples available that show their use ? Also the WIKI has some pages about it http://wiki.freepascal.org/fcl-web There are some articles https://idefix.freepascal.org/~michael/articles/ see the web1 and web2 and webserver articles. I think Web2 explains what you need. It seems fcl-web is an incomplete work. How can i help? Is there any list of incomplete implementations/to-do works? Basic FCL-Web is very complete and in production use in many applications. The only "incomplete" domain is pageproducer and friends (all things 'Producer'). This was an early attempt at mimicking early Delphi web classes, an approach which I have since abandoned. But the JSON-RPC or Ext.Direct JSON RPC mechanism and data exhange mechanism and related things work very well in production since 7+ years. If you have specific questions not answered in the above info, ask and I will do my best to answer. Michael. ___ 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 Στις 23/2/2018 11:14 μμ, ο Luca Olivetti έγραψε: yes, it does (in procedure TFPCustomHTTPClient.ConnectToServer) FSocket:=TInetSocket.Create(AHost,APort,G); try if FIOTimeout<>0 then FSocket.IOTimeout:=FIOTimeout; <- FSocket.Connect; except FreeAndNil(FSocket); Raise; end; please follow the call stack. The TFPCustomHTTPClient calls TInetSocket.Create constructor which it calls the inherited constructor from TSocketStream. So just before the FSocket.Connect, the above code assigns the internal TSocketStream's FIOTimeout field ( as the TInetSocket is a descendant ) the value from the TFPCustomHTTPClient's FIOTimeout field. Now the folowing addition in the procedure TInetSocket.Connect uses the parents (TSocketStream) private procedure SetIOTimeout and FIOTimeout field to setup the socket timeout option. ssockets.pp line 979 addr.sin_family := AF_INET; addr.sin_port := ShortHostToNet(FPort); addr.sin_addr.s_addr := HostToNet(a.s_addr); SetIOTimeout(FIOTimeout); < {$ifdef unix} Res:=ESysEINTR; While (Res=ESysEINTR) do {$endif} Res:=fpConnect(Handle, @addr, sizeof(addr)); It works because the option is set after the socket is created and before the socket connect call. Of course this is a hack/workaround because if you need different timeouts for connect and receive then you need in the onconnect event handler to change the TFPCustomHTTPClient's FIOTimeout field again for the receive timeout . AFAIK I'm sure Michael will solved it in a more elegant way than my 30 min code review Just try it and tell me if it works. 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 23/02/18 a les 19:34, Dimitrios Chr. Ioannidis via fpc-pascal ha escrit: Hi, Στις 23/2/2018 8:24 μμ, ο Luca Olivetti έγραψε: El 23/02/18 a les 18:51, Dimitrios Chr. Ioannidis via fpc-pascal ha escrit: copy the ssockets.pp from \packages\fcl-net\src dir to your project dir and add the following line SetIOTimeout(FIOTimeout); to Procedure TInetSocket.Connect; like this fphttpclient already does that before calling connect and it doesn't work. emm it doesn't do that ... yes, it does (in procedure TFPCustomHTTPClient.ConnectToServer) FSocket:=TInetSocket.Create(AHost,APort,G); try if FIOTimeout<>0 then FSocket.IOTimeout:=FIOTimeout; <- FSocket.Connect; except FreeAndNil(FSocket); Raise; end; Bye -- Luca ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] fcl-web - html web modules
Hello, How to use action and sessions with HTML Web Modules? It seems fcl-web is an incomplete work. How can i help? Is there any list of incomplete implementations/to-do works? Regards ___ 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, Στις 23/2/2018 8:24 μμ, ο Luca Olivetti έγραψε: El 23/02/18 a les 18:51, Dimitrios Chr. Ioannidis via fpc-pascal ha escrit: copy the ssockets.pp from \packages\fcl-net\src dir to your project dir and add the following line SetIOTimeout(FIOTimeout); to Procedure TInetSocket.Connect; like this fphttpclient already does that before calling connect and it doesn't work. emm it doesn't do that ... did you tried it ... ;) 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 23/02/18 a les 18:51, Dimitrios Chr. Ioannidis via fpc-pascal ha escrit: copy the ssockets.pp from \packages\fcl-net\src dir to your project dir and add the following line SetIOTimeout(FIOTimeout); to Procedure TInetSocket.Connect; like this fphttpclient already does that before calling connect and it doesn't work. As Michael said, the socket must be put in non-blocking mode during the connection. This is how synapse does it (but I see that ssockets has no provision for toggling between blocking/non-blocking mode): 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)); 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, Στις 23/2/2018 5:17 μμ, ο Michael Van Canneyt έγραψε: On Fri, 23 Feb 2018, Luca Olivetti wrote: Hello, the TFpHttpClient has an IoTimeout property, which in turn sets the IOTimeout of its FSocket (TInetSocket), however there's no way to set a connection timeout. I see that even overriding the SocketHandler wouldn't change that, since it's connect is only called *after* the fpconnect call succeeds. Also, I see no way to interrupt a pending connect from another thread. < snip > This is on my todo list. Unfortunately, the way sockets work, this means putting the socket in non-blocking mode, call connect, and then use select or some other means to wait till the socket is done with the connect, and then put the socket again in blocking mode. try this : copy the ssockets.pp from \packages\fcl-net\src dir to your project dir and add the following line SetIOTimeout(FIOTimeout); to Procedure TInetSocket.Connect; like this Procedure TInetSocket.Connect; Var A : THostAddr; addr: TInetSockAddr; Res : Integer; 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); SetIOTimeout(FIOTimeout); {$ifdef unix} Res:=ESysEINTR; While (Res=ESysEINTR) do {$endif} Res:=fpConnect(Handle, @addr, sizeof(addr)); 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; It works for me 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
On Fri, 23 Feb 2018, Luca Olivetti wrote: Hello, the TFpHttpClient has an IoTimeout property, which in turn sets the IOTimeout of its FSocket (TInetSocket), however there's no way to set a connection timeout. I see that even overriding the SocketHandler wouldn't change that, since it's connect is only called *after* the fpconnect call succeeds. Also, I see no way to interrupt a pending connect from another thread. My problem is that I'm using it in a thread, and, when I terminate the application, in case the host is not responding/not available, I have to wait the roughly 30 seconds that it takes for the connect to timeout. I had the same problem with synapse, but there it has been solved several years ago by introducing a connection timeout (besides, I can abort a socket operation from another thread, though it only works under windows). This is on my todo list. Unfortunately, the way sockets work, this means putting the socket in non-blocking mode, call connect, and then use select or some other means to wait till the socket is done with the connect, and then put the socket again in blocking mode. So not something to be quickly done in 10 minutes... Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] C header to Pascal , what is the type of ENUM?
In C ENUM_BEGIN( RetCode ) /* 0 */ ENUM_DEFINE( TA_SUCCESS, Success ), /* No error */ /* 1 */ ENUM_DEFINE( TA_LIB_NOT_INITIALIZE, LibNotInitialize ), /* TA_Initialize was not sucessfully called */ /* 2 */ ENUM_DEFINE( TA_BAD_PARAM, BadParam ), /* A parameter is out of range */ /* 3 */ ENUM_DEFINE( TA_ALLOC_ERR, AllocErr ), /* Possibly out-of-memory */ /* 4 */ ENUM_DEFINE( TA_GROUP_NOT_FOUND, GroupNotFound ), /* 5 */ ENUM_DEFINE( TA_FUNC_NOT_FOUND, FuncNotFound ), /* 6 */ ENUM_DEFINE( TA_INVALID_HANDLE, InvalidHandle ), /* 7 */ ENUM_DEFINE( TA_INVALID_PARAM_HOLDER, InvalidParamHolder ), /* 8 */ ENUM_DEFINE( TA_INVALID_PARAM_HOLDER_TYPE, InvalidParamHolderType ), /* 9 */ ENUM_DEFINE( TA_INVALID_PARAM_FUNCTION, InvalidParamFunction ), /* 10 */ ENUM_DEFINE( TA_INPUT_NOT_ALL_INITIALIZE, InputNotAllInitialize ), /* 11 */ ENUM_DEFINE( TA_OUTPUT_NOT_ALL_INITIALIZE, OutputNotAllInitialize ), /* 12 */ ENUM_DEFINE( TA_OUT_OF_RANGE_START_INDEX, OutOfRangeStartIndex ), /* 13 */ ENUM_DEFINE( TA_OUT_OF_RANGE_END_INDEX, OutOfRangeEndIndex ), /* 14 */ ENUM_DEFINE( TA_INVALID_LIST_TYPE, InvalidListType ), /* 15 */ ENUM_DEFINE( TA_BAD_OBJECT, BadObject ), /* 16 */ ENUM_DEFINE( TA_NOT_SUPPORTED, NotSupported ), /* 5000 */ ENUM_DEFINE( TA_INTERNAL_ERROR, InternalError ) = 5000, /* 0x */ ENUM_DEFINE( TA_UNKNOWN_ERR, UnknownErr ) = 0x ENUM_END( RetCode ) The function in C is TA_RetCode TA_EMA( int startIdx, int endIdx, const double inReal[], int optInTimePeriod, /* From 2 to 10 */ int *outBegIdx, int *outNBElement, double outReal[] ); my question is, what should the type of TA_RetCode be in Pascal? Word (2 byte) or LongWord (4 bytes)? In short, is this pascal translation correct? function TA_EMA(startIdx, endIdx : integer; const inReal : PDouble; optInTimePeriod : integer; var utBegIdx, outNBElement : integer; outReal : PDouble ) : Word;stdcall; external 'ta_func.dll'; Note: the dll is 64-bit windows but I am not sure whether int should translate to Integer or Int64 in Pascal. Dennis ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Better way to convert short string to pchar?
> On Feb 23, 2018, at 6:51 PM, Marco van de Voort wrote: > > When creating the content of name append #0 (name:=whateverexpression+#0 ); , > then do > result = glGetUniformLocation(programID, @name[1]); Thanks now I remember. That was driving me crazy. Regards, Ryan Joseph ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Better way to convert short string to pchar?
In our previous episode, Ryan Joseph said: > I would like short strings so I can do concatenation easily but I need to > pass pchar to a C function. Is there anyway to do this on the stack instead > of allocating a string each time? I feel like it was possible to do some type > casting but I don?t remember how. > > pname := StrAlloc(Length(name) + 1); > StrPCopy(pname, name); > result := glGetUniformLocation(programID, pname); > StrDispose(pname); When creating the content of name append #0 (name:=whateverexpression+#0 ); , then do result = glGetUniformLocation(programID, @name[1]); Of course this reduces the maximum length of the shortstring by one. In Paleo times I've seen TP frameworks that always allocated an extra char field in records after the shortstring, so that a #0 could always be appended, even if the string was max. But the best way is to design out shortstrings. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] fphttclient, no way to specify a connect timeout
Hello, the TFpHttpClient has an IoTimeout property, which in turn sets the IOTimeout of its FSocket (TInetSocket), however there's no way to set a connection timeout. I see that even overriding the SocketHandler wouldn't change that, since it's connect is only called *after* the fpconnect call succeeds. Also, I see no way to interrupt a pending connect from another thread. My problem is that I'm using it in a thread, and, when I terminate the application, in case the host is not responding/not available, I have to wait the roughly 30 seconds that it takes for the connect to timeout. I had the same problem with synapse, but there it has been solved several years ago by introducing a connection timeout (besides, I can abort a socket operation from another thread, though it only works under windows). Bye -- Luca ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Is this the correct way to configure fpc for multiple arm-embedded subarchs?
I am doing something similar to what you are doing, see below I also needed to create a softlink so that fpc can call ppcrossarm, it expects to call ppcarm By using 'INSTALL_UNITDIR' there is no need to copy files at the end. You will need to do a little tweak in fpc.cfg, after this it is transparent to handle the different subarchs, at least for arm and mipsel ;-) Now I can use fpc to select matching arch/subarch and Lazarus works just fine. Michael fpc-cfg change: # searchpath for units and other system dependent things #ifdef embedded -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/$fpcsubarch -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/$fpcsubarch/* -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/$fpcsubarch/rtl #else -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/* -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/rtl #endif --- snip Buildscript: CROSSOPT="-O1 -gw2 -dDEBUG" #CROSSOPT="-O1 -gw2 -dDEBUG -godwarfcpp" SUBARCH=armv6m make clean buildbase CROSSINSTALL=1 OS_TARGET=embedded CPU_TARGET=arm SUBARCH=$SUBARCH CROSSOPT="$CROSSOPT" BINUTILSPREFIX=arm-none-eabi- || exit 1 make installbase CROSSINSTALL=1 OS_TARGET=embedded CPU_TARGET=arm SUBARCH=$SUBARCH CROSSOPT="$CROSSOPT" BINUTILSPREFIX=arm-none-eabi- INSTALL_UNITDIR=/usr/local/lib/fpc/3.1.1/units/arm-embedded/$SUBARCH/rtl || exit 1 #mv /usr/local/lib/fpc/3.1.1/ppcrossarm /usr/local/lib/fpc/3.1.1/ppcrossarm-$SUBARCH SUBARCH=armv7m make clean buildbase CROSSINSTALL=1 OS_TARGET=embedded CPU_TARGET=arm SUBARCH=$SUBARCH CROSSOPT="$CROSSOPT" BINUTILSPREFIX=arm-none-eabi- || exit 1 make installbase CROSSINSTALL=1 OS_TARGET=embedded CPU_TARGET=arm SUBARCH=$SUBARCH CROSSOPT="$CROSSOPT" BINUTILSPREFIX=arm-none-eabi- INSTALL_UNITDIR=/usr/local/lib/fpc/3.1.1/units/arm-embedded/$SUBARCH/rtl || exit 1 #mv /usr/local/lib/fpc/3.1.1/ppcrossarm /usr/local/lib/fpc/3.1.1/ppcrossarm-$SUBARCH SUBARCH=armv7em make clean buildbase CROSSINSTALL=1 OS_TARGET=embedded CPU_TARGET=arm SUBARCH=$SUBARCH CROSSOPT="$CROSSOPT" BINUTILSPREFIX=arm-none-eabi- || exit 1 make installbase CROSSINSTALL=1 OS_TARGET=embedded CPU_TARGET=arm SUBARCH=$SUBARCH CROSSOPT="$CROSSOPT" BINUTILSPREFIX=arm-none-eabi- INSTALL_UNITDIR=/usr/local/lib/fpc/3.1.1/units/arm-embedded/$SUBARCH/rtl || exit 1 #cp /usr/local/lib/fpc/3.1.1/ppcrossarm /usr/local/lib/fpc/3.1.1/ppcrossarm-$SUBARCH ln -sf /usr/local/lib/fpc/3.1.1/ppcrossarm /usr/local/bin/ppcarm Am 22.02.18 um 21:35 schrieb Christo: On Mon, 2017-12-04 at 08:22 +0100, Michael Ring wrote: Hi Florian! I would like to work on this patch, can you share it with me? Thank you, Michael Am 03.12.17 um 19:05 schrieb Florian Klämpfl: Am 29.11.2017 um 06:36 schrieb Christo: On Sun, 2017-11-26 at 17:19 +0100, Michael Ring wrote: I am looking for an easy way to have all cortex-m compilers available at the same time to be able to do automated building/testing There is a similar problem with the AVR target having several subarchitectures. One option I think is to have a subarch defined by the compiler, then it would be easy to lay out the compiled unit structure in fpc.cfg according to subarch. I've made an attempt at adding a subarch define to my local compiler source for AVR, but haven't developed the idea further. I'm not a compiler dev so there may be better options. Subarch directories are imo the best solution, I have a half-backen patch for this, not yet finished though. I've made a script file (attached) that iterates through the different subarchitectures available for the AVR compiler, calls make and then moves the compiled units to a subdirectory. I think the logic of this script should be moved to the existing rtl makefile so that all subarchitectures for a target gets generated and sorted in one go. Of course then the default fpc.cfg ideally needs to be updated to reflect the subarch folder structure for ARM and AVR. I'm putting this out there hoping that someone familiar with the topic and makefile syntax can help with a patch for FPC. ___ 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