简体   繁体   中英

How do I (gracefully) terminate a gSOAP server?

I have gSOAP server generated from a WSDL file + a Qt GUI. The generated code works perfectly fine, except one point that causes my process to stay alive after GUI exits. (I'm deploying on Windows, so I have no signaling)

I need my GUI to stay alive (naturally) so I moved server-proxy object to a QObject -based class that the latter is moved to another QThread , and the I fire it up by an external signal. The server now runs on event-loop of its parent QObject and works fine.

The only problem is that I have no clue how to terminate server on exit. I tried tweaking generated code for server (is that really a good idea by the way?)

int MySweetService::run(int port)
{   if (!soap_valid_socket(this->soap->master) && !soap_valid_socket(this->bind(NULL, port, 100)))
        return this->soap->error;
    for (;;) // =====> Maybe here I can put my while(module_is_running_atomic_bool) ?
    {   if (!soap_valid_socket(this->accept()))
        {   if (this->soap->errnum == 0) // timeout?
                this->soap->error = SOAP_OK;
            break;
        }
        if (this->serve())
            break;
        this->destroy();
    }
    return this->soap->error;
} 

Calling soap_done(&soap) from another thread terminates blocking call to accept() and next your "serving" thread. It works for me on Windows but I doesn't on Linux - it looks like gsoap has some multitasking issue. You also need some boolean flag to let "serving" thread know that you shut it down and it's not just error in gsope.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM