On Mon, 28 Dec 2020 14:12:02 +0100, Jean SUZINEAU via fpc-pascal <fpc-pascal@lists.freepascal.org> wrote:
>Le 28/12/2020 à 13:16, Bo Berglund via fpc-pascal a écrit : >> Synchronize(CallEvent); //Supply received data in FBuffer to >> caller > >You are using TThread.Synchronize. > >In a console app, it's likely that somewhere else in your main thread >you'll need to call regularly Classes.CheckSynchronize to allow the >actual execution of CallEvent. > >In my case, linux server dll called by a 4js 4GL console program (no GUI >on linux server), I need to call regurlarly Classes.CheckSynchronize >froml 4gl through function exported by the pascal code. >If I don't do this, the CallEvent is nether called. > Where I use the fpserial class for communications over RS232 there is an "eternal" loop in the main program, which for a console program is what is really running: {$IFDEF UNIX} //What to do for system messages procedure handleSignal(signum: CInt); cdecl; begin case signum of SIGHUP : bSHup := true; SIGTERM : bSTerm := true; SIGINT : bSInt := true end; end; {$ENDIF} program //Create all objects and start processes .... {$IFDEF UNIX} //Make sure there is a signal handler fpSignal(SigTerm, SignalHandler(@handleSignal)); fpSignal(SigInt, SignalHandler(@handleSignal)); fpSignal(SigHup, SignalHandler(@handleSignal)); {$ENDIF} //Now wait for signals: While not (bSTerm or bSInt or bsHup) do //React to system signals begin //Here is where the server runs as defined elsewhere //Eternal loop to wait for system messages Sleep(1); //To not hog the CPU CheckSynchronize; //Enable events to fire off handlers end; //cleanup and exit ... end. The program is intended to run as a Linux service and so it reacts to the service manager's messages which are coming in via the handleSignal procedure. The main action is controlled by socket handlers started by the preliminaries in the main program and which are triggered by events from various sources like TCP/IP connections, timers etc. -- Bo Berglund Developer in Sweden _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal