简体   繁体   English

时间:2019-05-10标签:gsoapc ++ so_REUSEADDR

[英]c++ gsoap SO_REUSEADDR

im trying to build a multithreaded calc++ webservice. 即时通讯试图建立一个多线程的calc ++网络服务。 On basis of the original example. 在原始示例的基础上。 So i wanted to build the SO_REUSEADDR in my binary. 所以我想在我的二进制文件中构建SO_REUSEADDR。

int main(int argc, char* argv[])
{
    CalculatorService c;
    int port = atoi(argv[1]) ;
    printf("Starting to listen on port %d\n", port) ;
    c.soap->bind_flags |= SO_REUSEADDR;
    if (soap_valid_socket(c.bind( NULL, port, 100)))
    {
        CalculatorService *tc ;
        pthread_t tid;
        for (;;)
        {
            if (!soap_valid_socket(c.accept()))
                return c.error;
            tc = c.copy() ; // make a safe copy
            if (tc == NULL)
                break;
            pthread_create(&tid, NULL, (void*(*)(void*))process_request, (void*)tc);

            printf("Created a new thread %ld\n", tid) ;
        }
    }
    else 
    {
        return c.error;
    }
    printf("hi");
}


void *process_request(void *calc)
{
   pthread_detach(pthread_self());
   CalculatorService *c = static_cast<CalculatorService*>(calc) ;
   c->serve() ;
   c->destroy() ;
   delete c ;
   return NULL;
}

If i try to build this with: 如果我尝试用:

g++  -o calcmulti main.cpp stdsoap2.cpp soapC.cpp soapCalculatorService.cpp -lpthread

I get 我懂了

main.cpp: In function 'int main(int, char**)':
main.cpp:13: error: invalid use of 'struct soap'

The soap struct is in the stdsoap2.h soap结构位于stdsoap2.h中

struct SOAP_STD_API soap
{
    int bind_flags;               /* bind() SOL_SOCKET sockopt flags, e.g. set to SO_REUSEADDR to enable reuse */
}

What am i doing wrong? 我究竟做错了什么? :< <

It depends options you used using the soap2cpp generator. 这取决于您使用soap2cpp生成器使用的选项。

With -i option CalculatorService inherit from the soap structure then you should use : 使用-i选项CalculatorService从soap结构继承,则应使用:

 c.bind_flags |= SO_REUSEADDR;

With -j option CalculatorService contains a soap structure then you should use : 使用-j选项CalculatorService包含一个soap结构,则应使用:

 c.soap->bind_flags |= SO_REUSEADDR;

It seems you use the -i option considering CalculatorService contains a soap structure. 考虑到CalculatorService包含一个soap结构,您似乎使用了-i选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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