📄 osphttp.c
字号:
(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; /* Before verifying the response, change all the characters * to lowercase. */ if(ospvResponse != OSPC_OSNULL) { OSPPUtilStringToLowercase(&ospvResponse); } /* * If we have service unavailable, just return an errorcode. Don't * be concerned with response type. */ 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;}staticintosppHttpMinTransCheck( OSPTHTTP **ospvHttpList, OSPTHTTP **ospvHttp, unsigned timeout){ OSPTTIME theTime = 0L; unsigned int elapsedTime = 0; unsigned int currentTime = 0; unsigned int referenceTime = 0; int errorcode = OSPC_ERR_NO_ERROR; OSPM_DBGENTER(("ENTER : osppHttpMinTransCheck\n")); /* Get a reference time */ errorcode = OSPPOSTimeGetTime(&theTime, &referenceTime); do { if (ospvHttp == OSPC_OSNULL) { /* Get the first item in the queue */ *ospvHttp = (OSPTHTTP *)OSPPListFirst((OSPTLIST *)ospvHttpList); if(*ospvHttp == OSPC_OSNULL) { errorcode = OSPC_ERR_HTTP_BAD_QUEUE; break; } /* Keep the search going until it gets to the end of the list */ while (*ospvHttp != (OSPTHTTP *)OSPC_OSNULL) { /* If this item in the list has an empty queue... */ if (&(*ospvHttp)->NumberOfTransactions == 0) { /* ...break out of the while loop with ospvHttp pointing */ /* to the item */ break; } /* ... if it is not empty, get the next item in the list */ *ospvHttp = (OSPTHTTP *)OSPPListNext((OSPTLIST *)ospvHttpList, (void *)*ospvHttp); } /* Get the current time */ errorcode = OSPPOSTimeGetTime(&theTime, ¤tTime); /* Check to make sure there are no problems... */ if(errorcode == OSPC_ERR_NO_ERROR) { /* ...if no problems, calculate the elapsed time */ elapsedTime = currentTime - referenceTime; } } else { break; } } while((*ospvHttp == OSPC_OSNULL)&&(elapsedTime < timeout)&&(errorcode == OSPC_ERR_NO_ERROR)); OSPM_DBGEXIT(("EXIT : osppHttpMinTransCheck\n")); return errorcode;}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 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -