📄 osphttp.c
字号:
OSPM_DBGNET(("MISC : osppHttpSetupAndMonitor() remove connection requested\n")); osppHttpRemoveConnection(httpconn); break; } /* * get the msginfo item from the queue */ msginfo = (OSPTMSGINFO *)OSPPListFirst( (OSPTLIST *)&(httpconn->MsgInfoList)); if (msginfo == (OSPTMSGINFO *)OSPC_OSNULL) { errorcode = OSPC_ERR_HTTP_BAD_QUEUE; OSPM_DBGERRORLOG(errorcode, "http msg queue corrupted"); } else { if(msginfo->Flags & OSPC_MSGINFO_AUDIT_TYPE) { /* set up retry delay and retry limit */ retrydelay = OSPC_AUDIT_RETRY_DELAY; retrylimit = OSPC_AUDIT_RETRY_LIMIT; } else { /* * get the current retry delay and retry limit values */ OSPPCommGetRetryDelay(comm, &retrydelay); OSPPCommGetRetryLimit(comm, &retrylimit); } attempts = 0; rollover = OSPC_FALSE; /* ----------------------------------------------------- * this loop will connect to a service point and attempt * to send a request. If the service point is unavailable, * then the next service point will be tried. If all service * points are exhausted then the list will be tried again * based on the value of retrylimit. if retrylimit is 1, * then 2 transaction attempts will be performed for each * service point until completed failed. * ------------------------------------------------------ */ while (attempts <= retrylimit && (comm->Flags & OSPC_COMM_HTTPSHUTDOWN_BIT) == 0) { errorcode = OSPC_ERR_NO_ERROR; OSPM_DBGMISC( ("MISC : osppHttpSetupAndMonitor() connected = <%s>\n", (connected == OSPC_TRUE ? "TRUE" : "FALSE"))); /* AuditURL should never be connected since audit thread * dies after every send. */ if(msginfo->Flags & OSPC_MSGINFO_AUDIT_TYPE) { /* try auditurl */ errorcode = OSPPSockConnectAuditURL(httpconn, &connected); rollover = OSPC_TRUE; attempts++; } else { if (!connected) { /* try service point list */ errorcode = OSPPSockConnectServicePoint(httpconn, &rollover, &connected); if (rollover) attempts++; } } if (connected == OSPC_TRUE && errorcode == OSPC_ERR_NO_ERROR) { errorcode = osppHttpBuildAndSend(httpconn, msginfo); /* * Successful send to service point */ if (errorcode == OSPC_ERR_NO_ERROR) { time(&httpconn->LastTransactionTime); break; } else { connected = OSPC_FALSE; } } if (rollover && retrydelay && retrylimit && attempts <= retrylimit) { OSPM_SLEEP(retrydelay); rollover = OSPC_FALSE; } OSPM_DBGNET(("MISC : attempt iteration %d limit = %d\n", attempts+1, retrylimit)); } OSPM_DBGNET(("MISC : osppHttpSetupAndMonitor() monitor exit. errorcode = %d\n", errorcode)); if (errorcode != OSPC_ERR_NO_ERROR) msginfo->ErrorCode = errorcode; if (errorcode == OSPC_ERR_NO_ERROR && attempts < retrylimit && comm->Flags & OSPC_COMM_HTTPSHUTDOWN_BIT) msginfo->ErrorCode = OSPC_ERR_HTTP_SHUTDOWN; /* * remove the processed msg from the queue */ msginfo = (OSPTMSGINFO *)OSPPListRemove( (OSPTLIST *)&(httpconn->MsgInfoList)); if (msginfo == (OSPTMSGINFO *)OSPC_OSNULL) { errorcode = OSPC_ERR_HTTP_BAD_QUEUE; OSPM_DBGERRORLOG(errorcode, "http msg queue corrupted"); } /* * decrement the number of transactions on * the queue */ httpconn->NumberOfTransactions--; OSPM_DBGNET(("MISC : osppHttpSetupAndMonitor() msg dequeued. queue = %d\n", httpconn->NumberOfTransactions)); } /* * release the mutex lock */ OSPM_MUTEX_UNLOCK(httpconn->Mutex, tmperror); assert(tmperror == OSPC_ERR_NO_ERROR); /* * now signal the application thread that * we've got a response for it. */ if (msginfo != (OSPTMSGINFO *)OSPC_OSNULL) { errorcode = OSPPMsgInfoProcessResponse(msginfo); assert(errorcode == OSPC_ERR_NO_ERROR); } } } /* * finally clean up the memory for the connection */ OSPPHttpDelete(&httpconn); OSPM_DBGEXIT(("EXIT : osppHttpSetupAndMonitor()\n"));#ifdef _WIN32 return;#else return (void *)NULL;#endif}intOSPPHttpVerifyResponse( char *ospvResponse, int *ospvResponseType){ int errorcode = OSPC_ERR_NO_ERROR; unsigned int tempIndex = 0; /* * If we have service unavailable, just return an errorcode. Don't * be concerned with response type. */ /* Before verifying the response, change all the characters * to lowercase. */ if(ospvResponse != OSPC_OSNULL) { for(tempIndex=0; tempIndex < OSPM_STRLEN((const char *)ospvResponse); tempIndex++) { *(ospvResponse + tempIndex) = (unsigned char)OSPM_TOLOWER((unsigned int)*(ospvResponse + tempIndex)); } } if (OSPM_STRSTR(ospvResponse, OSPC_HTTP_503_SERV_UNAVAIL) != (char *)OSPC_OSNULL) { errorcode = OSPC_ERR_HTTP_SERVICE_UNAVAILABLE; } else { /* * Try to determine the response type. Anything other than * 1xx or 2xx will be considered and error. */ if (OSPM_STRSTR(ospvResponse, OSPC_HTTP_100_CONTINUE) != (char *)OSPC_OSNULL) { *ospvResponseType = 100; } else { if (OSPM_STRSTR(ospvResponse, OSPC_HTTP_200_OK) != (char *)OSPC_OSNULL) { *ospvResponseType = 200; } else { errorcode = OSPC_ERR_HTTP_SERVER_ERROR; } } } return errorcode;}/* * Starts the HTTP worker thread. * This function will create the new HTTP thread responsible * for monitoring the HTTP message queue for new requests. * * return OSPC_ERR_NO_ERROR if successful, else an error code. */staticintosppHttpStartWorker( OSPTHTTP *ospvHttp) /* In - Pointer to the HTTP connection */{ int errorcode = OSPC_ERR_NO_ERROR; OSPTTHRATTR thread_attr; OSPM_DBGENTER(("ENTER: osppHttpStartWorker\n")); /* * verify HTTP pointer */ assert(ospvHttp != OSPC_OSNULL); if (errorcode == OSPC_ERR_NO_ERROR) { OSPM_THRATTR_INIT(thread_attr, errorcode); if (errorcode == OSPC_ERR_NO_ERROR) { OSPM_SETDETACHED_STATE(thread_attr, errorcode); if (errorcode == OSPC_ERR_NO_ERROR) { /* * create the new thread which will monitor the * the HTTP connection's message queue for new requests */ OSPM_CREATE_THREAD(ospvHttp->ThreadId, &thread_attr, osppHttpSetupAndMonitor, ospvHttp, errorcode); } OSPM_THRATTR_DESTROY(thread_attr); } if (errorcode != OSPC_ERR_NO_ERROR) { errorcode = OSPC_ERR_COMM_THREAD_INIT_FAILED; OSPM_DBGERRORLOG(errorcode, "thread initialization failed"); } } OSPM_DBGEXIT(("EXIT : osppHttpStartWorker\n")); return errorcode;}staticOSPTHTTP *osppHttpIdleCheck( OSPTHTTP **ospvHttpList, OSPTHTTP *ospvHttp){ OSPM_DBGENTER(("ENTER : osppHttpIdleCheck\n")); do { if (ospvHttp->NumberOfTransactions == 0) break; ospvHttp = (OSPTHTTP *)OSPPListNext((OSPTLIST *)ospvHttpList, (void *)ospvHttp); } while (ospvHttp != (OSPTHTTP *)OSPC_OSNULL && ospvHttp->NumberOfTransactions); OSPM_DBGEXIT(("EXIT : osppHttpIdleCheck\n")); return ospvHttp;}staticOSPTHTTP *osppHttpMinTransCheck( OSPTHTTP **ospvHttpList, OSPTHTTP *ospvHttp){ unsigned minimum = 0; OSPTHTTP *httpconn = OSPC_OSNULL; OSPM_DBGENTER(("ENTER : osppHttpMinTransCheck\n")); if (ospvHttp == OSPC_OSNULL) { ospvHttp = (OSPTHTTP *)OSPPListFirst((OSPTLIST *)ospvHttpList); httpconn = ospvHttp; minimum = ospvHttp->NumberOfTransactions; while (ospvHttp != (OSPTHTTP *)OSPC_OSNULL) { if (ospvHttp->NumberOfTransactions <= minimum) { httpconn = ospvHttp; minimum = ospvHttp->NumberOfTransactions; } ospvHttp = (OSPTHTTP *)OSPPListNext((OSPTLIST *)ospvHttpList, (void *)ospvHttp); } } OSPM_DBGEXIT(("EXIT : osppHttpMinTransCheck\n")); return httpconn;}staticintosppHttpSelectConnection( OSPTCOMM *ospvComm, OSPTHTTP **ospvHttp, unsigned char ospvMsgInfoType){ OSPTBOOL createnew = OSPC_FALSE; unsigned httpcount = 0, maxcount = 0; int errorcode = OSPC_ERR_NO_ERROR; OSPM_DBGENTER(("ENTER : osppHttpSelectConnection\n")); /* * HTTP selection criteria: * * a new connection will be created if one of the following * conditions is TRUE: * * number of connections == 0 * number of idle connections == 0 && * number of connections < max connections * * a connection is reused if one of the following conditions is TRUE: * * number of idle connections > 0 * number of connections == max connections */ /* * first see if any connections exist */ *ospvHttp = (OSPTHTTP *)OSPPListFirst( (OSPTLIST *)&(ospvComm->HttpConnList)); if (*ospvHttp == (OSPTHTTP *)OSPC_OSNULL) { /* no current connections */ createnew = OSPC_TRUE; } else { /*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -