8,909
社区成员




UINT CTCOServerDlg::GsoapThread(void *param)
{
CTCOServerDlg *dlg = (CTCOServerDlg*)param;
soap_init2(&soap, SOAP_IO_KEEPALIVE, SOAP_IO_KEEPALIVE);
//soap.send_timeout = 30; //
//soap.recv_timeout = 30;
soap.accept_timeout = 300; //连接超时 300s
soap.max_keep_alive = 100;
soap.keep_alive = TRUE;
soap.tcp_keep_alive = TRUE;
DWORD tid;
HANDLE hThread;
SOAP_SOCKET m, s;
m = soap_bind(&soap, NULL, 9999, BACKLOG);
if (!soap_valid_socket(m)){
dlg->WriteLog(_T("soap bind error!"));
}
else
dlg->WriteLog(_T("soap bind ok, Listening on port: 9999"));
for (;;) {
s = soap_accept(&soap);
if (!soap_valid_socket(s)) {
if (soap.errnum) {
soap_print_fault(&soap, stderr);
exit(1);
}
dlg->WriteLog(_T("server timed out"));
continue;
}
dlg->WriteLog(_T(" socket [%d] connect from IP: [%d.%d.%d.%d]"), s, (soap.ip >> 24) & 0xFF, (soap.ip >> 16) & 0xFF, (soap.ip >> 8) & 0xFF, soap.ip & 0xFF);
tsoap = soap_copy(&soap); // make a safe copy
if (!tsoap) break;
hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)process_request, tsoap, 0, &tid);
if (hThread == NULL) {
dlg->WriteLog(_T("can not create a thread for SOAP request processing.\n"));
exit(-1);
}
}
soap_done(&soap);
return 0;
}
/*************************************************************************************************************************************************************************/
DWORD WINAPI process_request(LPVOID* soap) {
((struct soap*)soap)->recv_timeout = 30; // Timeout after 30 second stall on recv
((struct soap*)soap)->send_timeout = 10; // Timeout after 10 second stall on send
soap_serve((struct soap*)soap);
soap_destroy((struct soap*)soap);
soap_end((struct soap*)soap);
soap_free((struct soap*)soap);
return 0;
}
int ns__exec(struct soap *soap, wstring in, wstring* out)
{
if (!soap->userid || !soap->passwd || strcmp(soap->userid, "ats") || strcmp(soap->passwd, "ats123"))
return 401;// HTTP authentication required
//执行函数
.......................
}