Interaction with a daemon in C ++ with sockets

I am writing a daemon that should work both in the background and take care of tasks, as well as receive input directly from the interface. I am trying to use sockets to take care of this task, however I cannot get it to work correctly, as the sockets pause the program while waiting for the connection. Is there any way around this?

I use shell wrappers provided at http://linuxgazette.net/issue74/tougher.html

Thanks for any help.

+3
source share
5 answers

, . , , - Boost Asio.

+3

. - libevent. .

, , . .

+2

, .

, ( ).

, , , , , . , :

  • Libevent.
  • glib.
  • libev.
  • :: ASIO
  • ...
+2

( ) ( ). ( ), , , , . .

, ), .

LinuxGazette - . , Beej Guide to Network Programming, API, , .. , , -, Boost:: ASIO.

+1

- .

" ++" .

while (!done)
    {
        bool workDone = false;
        // Loop over each event source or internal worker
        for each module
        {
            // If it has work to do, do some.
            if (module.hasWorkDoTo())
            {
                // Generally, do as little work as possible; e.g. process a single event for this module.
                // But tinker with this to manage priorities if need be.
                // E.g. Maybe allow the GUI to flush its queue.
                module.doSomeWork();
                workDone = true;
            }
        }
        if (!workDone)
        {
            // System idle. No Sleep for a bit so we have benign idle baheviour.
            nanosleep(...);
        }
    }
0

Source: https://habr.com/ru/post/1787338/


All Articles