> > There's probably a better way though! > > Maybe not better, but for some reasons easier to implement, at > least for me: I used a local TCP socket and Fl::add_fd() for this. > > PRO: platform independent implementation, and Fl::add_fd() works > even on Windows, where Fl::add_fd() is restricted to sockets. This > was the main argument to do it this way. Also, no threads required.
Yes: though my code was threaded anyway, so there wasn't a big cost for me in going this way. It would have been nice if Fl::add_fd() worked on pipes on WIN32 though... > CON: you need a fixed local socket number for it to work. A named > pipe would be more flexible (arbitrary NAME vs. socket NUMBER). Not quite an arbitrary name though - I had to figure out a recipe whereby the "new" process would figure out the same name as any prior process, so that it could look for the name at runtime... I made something up based on user name, the dir in which the executable resided, and, erm, some other stuff... That seems to work, and means that if two users are on the same machine they get one instance each, rather than just one instance between them. Which was what I wanted. For some sort of server process, maybe one instance for all users would be more appropriate, though? > The app first tries to connect to the socket, and if it exists, > sends a message and exits. If it doesn't exist, then this is the > first instance of the app. It creates a local server socket and > registers it with Fl::add_fd() to watch it. Whenever a new app > is started, a callback is triggered in the first instance, since > the other instance writes to the socket. The first instance then > reads the message from the socket... Yup - sounds familiar... Only I didn't have the convenience of a working Fl::add_fd() method to help out, so I have a helper thread that just blocks on the pipe, and only ever runs if there is something there to read. ******************************************************************** This email and any attachments are confidential to the intended recipient and may also be privileged. If you are not the intended recipient please delete it from your system and notify the sender. You should not copy it or use it for any purpose nor disclose or distribute its contents to any other person. ******************************************************************** _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk

