📄 http_server.pc
字号:
throughput = 0; } else { throughput = (serverPtr->numBytesRecvd * 8.0 * SECOND) / (serverPtr->sessionFinish - serverPtr->sessionStart); } ctoa(throughput, throughputStr); sprintf(buf, "(%ld to %ld): conn length %s pages sent = %ld, " "bytes sent = %ld B, bytes recvd = %ld B, throughput = %s bps", serverPtr->localAddr, serverPtr->remoteAddr, timeStr, serverPtr->pagesSent, serverPtr->numBytesSent, serverPtr->numBytesRecvd, throughputStr); GLOMO_PrintStat(nodePtr, "AppHttpServer", buf);}/* * NAME: AppHttpServerFinalize. * PURPOSE: Collect statistics of a Http session. * PARAMETERS: nodePtr - pointer to the node. * serverPtr - pointer to the http server data structure. * RETURN: none. */voidAppHttpServerFinalize(GlomoNode *nodePtr, GlomoAppHttpServer *serverPtr){ if (nodePtr->appData.appStats == TRUE) { AppHttpServerPrintStats(nodePtr, serverPtr); }}/* * NAME: AppHttpServerGetHttpServer. * PURPOSE: search for a http server data structure. * PARAMETERS: appList - link list of applications, * connId - connection ID of the http server. * RETURN: the pointer to the http server data structure, * NULL if nothing found. */static GlomoAppHttpServer *AppHttpServerGetHttpServer(GlomoNode *nodePtr, int connId){ AppInfo *appList = nodePtr->appData.appPtr; GlomoAppHttpServer *httpServer; for (; appList != NULL; appList = appList->appNext) { if (appList->appType == APP_HTTP_SERVER) { httpServer = (GlomoAppHttpServer *) appList->appDetail; if (httpServer->connectionId == connId) { return httpServer; } } } return NULL;}/* * NAME: AppHttpServerRemoveHttpServer. * PURPOSE: Remove an HTTP server process that corresponds to the * given connectionId * PARAMETERS: nodePtr - pointer to the node. * closeRes - the close connection results from TCP * RETURN: none. */static void AppHttpServerRemoveHttpServer(GlomoNode *nodePtr, TransportToAppCloseResult *closeRes){ AppInfo *curApp = nodePtr->appData.appPtr; AppInfo *tempApp; GlomoAppHttpServer *serverPtr; if (curApp == NULL) return; if (curApp->appType == APP_HTTP_SERVER) { serverPtr = curApp->appDetail; assert(serverPtr); if (serverPtr->connectionId == closeRes->connectionId) {#ifdef DEBUG printf(" REMOVE 1st server.\n");#endif pc_free(serverPtr); tempApp = curApp->appNext; pc_free(curApp); nodePtr->appData.appPtr = tempApp; return; } } tempApp = curApp; curApp = curApp->appNext; while (curApp != NULL) { if (curApp->appType == APP_HTTP_SERVER) { serverPtr = curApp->appDetail; assert(serverPtr); if (serverPtr->connectionId == closeRes->connectionId) {#ifdef DEBUG printf(" REMOVE intermediate server.\n");#endif pc_free(serverPtr); tempApp->appNext = curApp->appNext; pc_free(curApp); curApp = tempApp->appNext; } else { tempApp = curApp; curApp = curApp->appNext; } } else curApp = curApp->appNext; }}/* * NAME: AppHttpServerNewHttpServer. * PURPOSE: create a new http server data structure, place it * at the beginning of the application list. * PARAMETERS: nodePtr - pointer to the node. * openResult - result of the open request. * RETRUN: the pointer to the created http server data structure, * NULL if no data structure allocated. */static GlomoAppHttpServer *AppHttpServerNewHttpServer(GlomoNode *nodePtr, TransportToAppOpenResult *openResult){ AppInfo *newApp; GlomoAppHttpServer *httpServer; newApp = (AppInfo *) pc_malloc(sizeof(AppInfo)); if (newApp == NULL) { assert(FALSE); } httpServer = (GlomoAppHttpServer *) pc_malloc(sizeof(GlomoAppHttpServer)); if (httpServer == NULL) { printf("HTTP Server: Node %ld cannot allocate memory for http server\n", nodePtr->nodeAddr); assert(FALSE); } /* * fill in connection id, etc. */ newApp->appType = APP_HTTP_SERVER; httpServer->connectionId = openResult->connectionId; httpServer->localAddr = openResult->localAddr; httpServer->remoteAddr = openResult->remoteAddr; httpServer->sessionStart = simclock(); httpServer->sessionFinish = simclock(); httpServer->sessionIsClosed = FALSE; httpServer->numBytesSent = 0; httpServer->numBytesRecvd = 0; httpServer->pagesSent = 0; newApp->appDetail = httpServer; newApp->appNext = nodePtr->appData.appPtr; nodePtr->appData.appPtr = newApp; return httpServer;}/* * NAME: AppHttpClientDeterminePrimaryReplyLength. * PURPOSE: Return the number of bytes in the primary reply * PARAMETERS: clientPtr - pointer to the client's data structure * RETURN: the number of bytes. */long AppHttpServerDeterminePrimaryReplyLength(GlomoNode *node){ extern const DoubleDistElement *HttpPrimaryReplyDistTable; extern const int HttpPrimaryReplyDistLength; double u = pc_erand(node->seed); float value; int midpoint = DoubleDistFindIndex(HttpPrimaryReplyDistTable, HttpPrimaryReplyDistLength, u);#ifdef DEBUG printf(" u = %f\n", u); printf("AppHttpClientDeterminePrimaryReplyLength(of %d) = %d\n", HttpPrimaryReplyDistLength, midpoint);#endif if (midpoint < 0) value = HttpPrimaryReplyDistTable[0].value; else value = DoubleDistEmpiricalIntegralInterpolate( HttpPrimaryReplyDistTable[midpoint].cdf, HttpPrimaryReplyDistTable[midpoint+1].cdf, HttpPrimaryReplyDistTable[midpoint].value, HttpPrimaryReplyDistTable[midpoint+1].value, u);#ifdef DEBUG printf(" midpoint = %d, value = %f\n", midpoint, value);#endif return value;}/* * NAME: AppHttpClientDetermineSecondaryReplyLength. * PURPOSE: Return the number of bytes in the secondary reply * PARAMETERS: clientPtr - pointer to the client's data structure * RETURN: the number of bytes. */long AppHttpServerDetermineSecondaryReplyLength(GlomoNode *node){ extern const DoubleDistElement *HttpSecondaryReplyDistTable; extern const int HttpSecondaryReplyDistLength; double u = pc_erand(node->seed); float value; int midpoint = DoubleDistFindIndex(HttpSecondaryReplyDistTable, HttpSecondaryReplyDistLength, u);#ifdef DEBUG printf(" u = %f\n", u); printf("AppHttpClientDetermineSecondaryReplyLength(of %d) = %d\n", HttpSecondaryReplyDistLength, midpoint);#endif if (midpoint < 0) value = HttpSecondaryReplyDistTable[0].value; else value = DoubleDistEmpiricalIntegralInterpolate( HttpSecondaryReplyDistTable[midpoint].cdf, HttpSecondaryReplyDistTable[midpoint+1].cdf, HttpSecondaryReplyDistTable[midpoint].value, HttpSecondaryReplyDistTable[midpoint+1].value, u);#ifdef DEBUG printf(" midpoint = %d, value = %f\n", midpoint, value);#endif return value;}/* * NAME: AppHttpServerSendPrimaryReply. * PURPOSE: Send the primary reply to the client. * PARAMETERS: nodePtr - pointer to the node. * serverPtr - pointer to the server's data structure. * primaryReplyLength - the length in bytes of the reply. * RETURN: none. */static void AppHttpServerSendPrimaryReply(GlomoNode *node, GlomoAppHttpServer *serverPtr, long primaryReplyLength){ char payload[MAX_APP_DATA_UNIT]; long sendSize;/* Julian: added this because 0 length packets break the sim */ if (primaryReplyLength == 0) primaryReplyLength = 1; memset(payload, 0, MAX_APP_DATA_UNIT); sendSize = MIN(primaryReplyLength, MAX_APP_DATA_UNIT); primaryReplyLength -= sendSize; serverPtr->bytesRemaining = primaryReplyLength; if (primaryReplyLength == 0) { payload[sendSize-1] = 'd'; } AppTcpSendData(node, TRANSPORT_PROTOCOL_TCP, serverPtr->connectionId, payload, sendSize);}/* * NAME: AppHttpServerSendSecondaryReply. * PURPOSE: Send the secondary reply to the client. * PARAMETERS: nodePtr - pointer to the node. * serverPtr - pointer to the server's data structure. * secondaryReplyLength - the length in bytes of the reply. * RETURN: none. */static void AppHttpServerSendSecondaryReply(GlomoNode *node, GlomoAppHttpServer *serverPtr, long secondaryReplyLength){ char payload[MAX_APP_DATA_UNIT]; long sendSize;/* Julian: added this because 0 length packets break the sim */ if (secondaryReplyLength == 0) secondaryReplyLength = 1; memset(payload, 0, MAX_APP_DATA_UNIT); sendSize = MIN(secondaryReplyLength, MAX_APP_DATA_UNIT); secondaryReplyLength -= sendSize; serverPtr->bytesRemaining = secondaryReplyLength; if (secondaryReplyLength == 0) { payload[sendSize-1] = 'd'; } AppTcpSendData(node, TRANSPORT_PROTOCOL_TCP, serverPtr->connectionId, payload, sendSize);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -