• Help structuring custom TCL event loop.

    From SR D@21:1/5 to All on Wed Nov 3 07:09:30 2021
    Having a hard time structuring TCL main event loop on Linux. The idea is to open up a UDP connection to a server, read commands from the script (passed in from the command line) which get sent to the server, and then read back the response. Here is how I
    currently have things structured.

    int Tcl_AppInit(Tcl_Interp *interp)
    {
    if (Tcl_Init(interp) == TCL_ERROR)
    return TCL_ERROR;

    if (MyTcl_Init(interp, &arguments) == TCL_ERROR)
    return TCL_ERROR;

    return TCL_OK;
    }

    int myLoop()
    {
    // open up a UDP socket to server and issue commands from TCL script.
    socket();
    connect();

    while (!done && foundEvent) {
    foundEvent = Tcl_DoOneEvent(TCL_ALL_EVENTS);

    // expecting to read back results from the server here.
    read(fd, buf, sizeof(buf));
    // ...
    }

    }

    int main(int argc, char* argv[])
    {
    // ...
    Tcl_Main(argc, argv, Tcl_AppInit);

    Tcl_SetMainLoop([]() { myLoop(); });
    // ...
    }

    The script issues commands which get sent via UDP from the interpreter. With the above, a connection is open, but I never get the response back from the server. In fact, I don't see that the while loop in myLoop() has even entered.

    Any thoughts about where I'm going wrong here?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ralf Fassel@21:1/5 to All on Wed Nov 3 17:11:15 2021
    * SR D <software.research.development@gmail.com>
    | int main(int argc, char* argv[])
    | {
    | // ...
    | Tcl_Main(argc, argv, Tcl_AppInit);

    | Tcl_SetMainLoop([]() { myLoop(); });
    | // ...
    | }

    --<snip-snip>--
    | Any thoughts about where I'm going wrong here?

    man Tcl_Main
    ...
    Tcl_Main does not return.

    so I *guess* you need to call Tcl_SetMainLoop() prior to Tcl_Main (never
    used that myself).

    Have you considered handling all of the UDP communication from script
    level via tcludp http://tcludp.sourceforge.net/? Seems so much easier
    to me...

    HTH
    R'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From SR D@21:1/5 to Ralf Fassel on Wed Nov 3 12:31:37 2021
    On Wednesday, November 3, 2021 at 11:11:20 AM UTC-5, Ralf Fassel wrote:
    * SR D <software.resea...@gmail.com>
    | int main(int argc, char* argv[])
    | {
    | // ...
    | Tcl_Main(argc, argv, Tcl_AppInit);

    | Tcl_SetMainLoop([]() { myLoop(); });
    | // ...
    | }

    --<snip-snip>--
    | Any thoughts about where I'm going wrong here?
    man Tcl_Main
    ...
    Tcl_Main does not return.

    so I *guess* you need to call Tcl_SetMainLoop() prior to Tcl_Main (never
    used that myself).

    Have you considered handling all of the UDP communication from script
    level via tcludp http://tcludp.sourceforge.net/? Seems so much easier
    to me...

    HTH
    R'

    Have you considered ...
    I have, but that's something I don't want users having to deal with.

    I wish swapping the order were that easy, or maybe I'm doing something wrong. So, I did swap, and will assume that's the way to go for now. I was just hoping to get confirmation I'm heading down the right path with this.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)