2014-01-21 1 views
1

메신저에서 다중 스레드 calC++ webservice를 빌드하려고합니다. 원래 예제를 기반으로합니다. 그래서 저는 바이너리에서 SO_REUSEADDR을 만들고 싶습니다.C++ gsoap 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; 
} 

내가 이것을 구축하려고하면 :

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

내가 얻을

main.cpp: In function 'int main(int, char**)': 
main.cpp:13: error: invalid use of 'struct 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 */ 
} 

어떻게 생각에 잘못하고있는거야? : <

답변

0

soap2cpp 생성기를 사용하여 사용한 옵션에 따라 다릅니다. 비누 구조에서 상속 CalculatorService -i 옵션을

당신은 사용해야

c.bind_flags |= SO_REUSEADDR; 

을 CalculatorService는 비누 구조를 포함 -j 옵션을 다음 사용한다 :

c.soap->bind_flags |= SO_REUSEADDR; 

그것은 당신을 보인다 CalculatorService에는 비누 구조가 포함되어 있으므로 -i 옵션을 사용하십시오.