Re: Preferred portable way to talk to a server process
"Wan-Teh Chang" <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.nspr |
|---|---|
| Message-ID | <[email protected]> |
On Tue, Jul 22, 2008 at 12:15 AM, Joachim Ziegler <[email protected]> wrote: > > Thank you for your quick and disillusioning answer. :-) > > But anyway, how do I do it then? This means that my otherwise clean NSPR > code will be polluted with #ifdef's? For some applications, NSPR can only reduce but not eliminate all the #ifdef's. There are some areas that NSPR doesn't cover or doesn't cover well. Sometimes the system APIs for that feature are so different between Unix and Windows that it's hard to define a cross-platform API that hides the differences. Sometimes users may not want to use a cross-platform API for the feature if they like the "native" way of doing something. For issuing admin commands to a server process, you have a choice to make -- the "native" way or a cross-platform way. It may make sense for you to go the "native" way, such as sending signals on Unix. For a cross-platform way, you can consider sending admin commands to a server process over a "pipe". On Unix, this pipe can be a Unix domain socket or a FIFO. On Windows, this pipe can be a named pipe. You can also use a TCP connection, which is portable and fully supported by NSPR. Using a TCP connection for server admin is actually quite common. Many home DLS/cable modem routers do this -- they listen on port 80 and you can use a web browser to perform router admin functions. > A second question: A typical server process blocks in a PR_Accept(), waiting > for clients to connect. > > The reference page says: "PR_Accept blocks the calling thread until either a > new connection is successfully accepted or an error occurs." > Now suppose that I want to shutdown the server process. How can I do that? > How can I make the process unblock and test a Boolean shutdown variable? > (Even with using signal, this would not not work according to the text cited > above.) You can set a boolean shutdown variable to true and call PR_Interrupt on the thread blocking in PR_Accept. > BTW, what's the definite reference for NSPR (yes, I am a newbie): > > http://www.mozilla.org/projects/nspr/ > > or > > http://developer.mozilla.org/en/docs/NSPR_API_Reference (the wiki) Right now it is still the former. We are migrating the former to the wiki, so the wiki actually has a lot of content. But the migration is not complete. I would check both. Wan-Teh