2

im trying to build a multithreaded calc++ webservice. On basis of the original example. So i wanted to build the SO_REUSEADDR in my binary.

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

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? :<

mpromonet
  • 11,326
  • 43
  • 62
  • 91
user1010775
  • 361
  • 3
  • 7
  • 24

1 Answers1

1

It depends options you used using the soap2cpp generator.

With -i option CalculatorService inherit from the soap structure then you should use :

 c.bind_flags |= SO_REUSEADDR;

With -j option CalculatorService contains a soap structure then you should use :

 c.soap->bind_flags |= SO_REUSEADDR;

It seems you use the -i option considering CalculatorService contains a soap structure.

mpromonet
  • 11,326
  • 43
  • 62
  • 91