⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 http_client.pc

📁 无线网络仿真工具Glomosim2.03
💻 PC
📖 第 1 页 / 共 3 页
字号:
long AppHttpClientDeterminePrimaryRequestLength(    GlomoAppHttpClient *clientPtr){    extern const DoubleDistElement *HttpPrimaryRequestDistTable;    extern const int HttpPrimaryRequestDistLength;    double u = pc_erand(clientPtr->seed);    float value;    int midpoint = DoubleDistFindIndex(HttpPrimaryRequestDistTable,                                       HttpPrimaryRequestDistLength,                                       u);#ifdef DEBUG    printf("    u = %f\n", u);    printf("AppHttpClientDeterminePrimaryRequestLength(of %d) = %d\n",           HttpPrimaryRequestDistLength, midpoint);#endif    if (midpoint < 0)        value = HttpPrimaryRequestDistTable[0].value;    else        value = DoubleDistEmpiricalIntegralInterpolate(                HttpPrimaryRequestDistTable[midpoint].cdf,                HttpPrimaryRequestDistTable[midpoint+1].cdf,                HttpPrimaryRequestDistTable[midpoint].value,                HttpPrimaryRequestDistTable[midpoint+1].value, u);#ifdef DEBUG    printf("    midpoint = %d, value = %f\n", midpoint, value);#endif    return value;}/* * NAME:        AppHttpClientSendPrimaryRequest. * PURPOSE:     Send the primary request of the given size to the server. * PARAMETERS:  clientPtr - pointer to the client's data structure * RETURN:      none. */void AppHttpClientSendPrimaryRequest(GlomoNode *node,                                     GlomoAppHttpClient *clientPtr,                                      long primaryRequestLength){    char payload[MAX_APP_DATA_UNIT];    long sendSize;    if (primaryRequestLength == 0)        primaryRequestLength = 1;    memset(payload, 0, MAX_APP_DATA_UNIT);    sendSize = MIN(primaryRequestLength, MAX_APP_DATA_UNIT);    primaryRequestLength -= sendSize;    clientPtr->stats.itemRequestBytes = primaryRequestLength;    if (primaryRequestLength == 0)    {        payload[sendSize-1] = 'p';        clientPtr->state = WAIT_PRIMARY_RESPONSE;        AppHttpClientSendWaitReplyTimer(node,            clientPtr, WAIT_PRIMARY_REPLY_TIMER);    }    else        clientPtr->state = XMIT_PRIMARY_REQUEST;    AppTcpSendData(node, TRANSPORT_PROTOCOL_TCP,                    clientPtr->connectionId, payload, sendSize);}/* * NAME:        AppHttpClientSendSecondaryRequest. * PURPOSE:     Send the secondary request of the given size to the server. * PARAMETERS:  clientPtr - pointer to the client's data structure * RETURN:      none. */void AppHttpClientSendSecondaryRequest(GlomoNode *node,                                     GlomoAppHttpClient *clientPtr,                                     long secondaryRequestLength){    char payload[MAX_APP_DATA_UNIT];    long sendSize;    if (secondaryRequestLength == 0)        secondaryRequestLength = 1;    memset(payload, 0, MAX_APP_DATA_UNIT);    sendSize = MIN(secondaryRequestLength, MAX_APP_DATA_UNIT);    secondaryRequestLength -= sendSize;    clientPtr->stats.itemRequestBytes = secondaryRequestLength;    if (secondaryRequestLength == 0)    {        payload[sendSize-1] = 's';        clientPtr->state = WAIT_SECONDARY_RESPONSE;        AppHttpClientSendWaitReplyTimer(node,            clientPtr, WAIT_SECONDARY_REPLY_TIMER);    }    else        clientPtr->state = XMIT_SECONDARY_REQUEST;    AppTcpSendData(node, TRANSPORT_PROTOCOL_TCP,                   clientPtr->connectionId, payload, sendSize);}/* * NAME:        AppHttpClientInit.  * PURPOSE:     Initialize a Http session.  * PARAMETERS:  nodePtr - pointer to the node,  *              serverAddrs - addresses of the servers to choose from, *              numServerAddrs - number of addresses in above array, *              startTime - the time to start the first connection *              thresh - maximum time before deciding the connection is done . * RETURN:      none.  */voidAppHttpClientInit(GlomoNode *nodePtr, NODE_ADDR *serverAddrs,                   long numServerAddrs, clocktype startTime,                  clocktype thresh){    GlomoAppHttpClient *clientPtr;    NODE_ADDR serverAddr;    long i;#ifdef DEBUG    printf("#%ld: AppHttpClientInit()\n", nodePtr->nodeAddr);#endif    clientPtr = AppHttpClientNewHttpClient(nodePtr);                                            if (clientPtr == NULL)    {        printf("HTTP Client: Node %ld cannot allocate "               "new http client\n", nodePtr->nodeAddr);        assert(FALSE);    }    clientPtr->threshhold = thresh;    clientPtr->servers = serverAddrs;    clientPtr->num_servers = numServerAddrs;    clientPtr->Zipf_constant = 0.0;    clientPtr->seed = nodePtr->seed;    // Compute new Zipf value (a constant which is a little expensive to    // recompute for every invocation).    for (i = 1; i <= clientPtr->num_servers; i++)     {        clientPtr->Zipf_constant += (1.0 / (double) i);    }#ifdef DEBUG    printf("  Zipf constant = %f\n", clientPtr->Zipf_constant);#endif    clientPtr->stats.itemRequestBytes = 0;    clientPtr->stats.pageItems = 0;#ifdef DEBUG    printf("  Servers: ");    for (i = 0; i < clientPtr->num_servers; i++)        printf(" %ld ", clientPtr->servers[i]);    printf("\n");#endif    serverAddr = AppHttpClientSelectNewServer(clientPtr);    clientPtr->remoteAddr = serverAddr;    clientPtr->documentsOnCurrentServer =         AppHttpClientConsecutiveDocumentRetrievals(clientPtr);#ifdef DEBUG    printf("    Request %d documents on server address %ld\n",           clientPtr->documentsOnCurrentServer, serverAddr);#endif    AppTcpOpenConnectionWithPriority(nodePtr,                                      TRANSPORT_PROTOCOL_TCP,                                      APP_HTTP_CLIENT,                                     serverAddr,                                      (short)APP_HTTP_SERVER,                                     clientPtr->uniqueId,                                      startTime,                                      NON_REAL_TIME);}/* * NAME:        AppHttpClientPrintStats. * PURPOSE:     Prints statistics of a Http session. * PARAMETERS:  nodePtr - pointer to the node.  *              clientPtr - pointer to the http client data structure. * RETURN:      none. */static voidAppHttpClientPrintStats(GlomoNode *nodePtr, GlomoAppHttpClient *clientPtr){    char buf[GLOMO_MAX_STRING_LENGTH];    char clockStr[GLOMO_MAX_STRING_LENGTH];    sprintf(buf, "(appId %ld): Number of connections = %ld",            clientPtr->uniqueId, clientPtr->numSessions);    GLOMO_PrintStat(nodePtr, "AppHttpClient", buf);    if (clientPtr->numSessions == 0)        return;    ctoa(clientPtr->avgSessionLength, clockStr);    sprintf(buf, "(appId %ld): Avg connection length = %s",            clientPtr->uniqueId, clockStr);    GLOMO_PrintStat(nodePtr, "AppHttpClient", buf);    sprintf(buf, "(appId %ld): Avg num of pages per connection = %ld",            clientPtr->uniqueId,             (clientPtr->numPages / clientPtr->numSessions));    GLOMO_PrintStat(nodePtr, "AppHttpClient", buf);    sprintf(buf, "(appId %ld): Avg num bytes recvd per conn = %ld",            clientPtr->uniqueId,            (clientPtr->numBytesRecvd / clientPtr->numSessions));    GLOMO_PrintStat(nodePtr, "AppHttpClient", buf);    sprintf(buf, "(appId %ld): Avg num bytes sent per conn = %ld",            clientPtr->uniqueId,            (clientPtr->numBytesSent / clientPtr->numSessions));    GLOMO_PrintStat(nodePtr, "AppHttpClient", buf);}   /* * NAME:        AppHttpClientFinalize. * PURPOSE:     Collect statistics of a Http session. * PARAMETERS:  nodePtr - pointer to the node.  *              clientPtr - pointer to the http client data structure. * RETURN:      none. */voidAppHttpClientFinalize(GlomoNode *nodePtr, GlomoAppHttpClient *clientPtr){    if (nodePtr->appData.appStats == TRUE)    {        clocktype sum;        sum  = clientPtr->avgSessionLength * clientPtr->numSessions;        clientPtr->sessionFinish = simclock();        sum += (clientPtr->sessionFinish - clientPtr->sessionStart);        clientPtr->numSessions++;        clientPtr->avgSessionLength = sum / clientPtr->numSessions;        AppHttpClientPrintStats(nodePtr, clientPtr);    }}/* * NAME:        AppHttpClientGetHttpClient. * PURPOSE:     search for a http client data structure.  * PARAMETERS:  nodePtr - pointer to the node.  *              connId - connection ID of the http client.  * RETURN:      the pointer to the http client data structure, *              NULL if nothing found. */static GlomoAppHttpClient *AppHttpClientGetHttpClient(GlomoNode *nodePtr, int connId){    AppInfo *appList = nodePtr->appData.appPtr;    GlomoAppHttpClient *httpClient;        for (; appList != NULL; appList = appList->appNext)     {        if (appList->appType == APP_HTTP_CLIENT)        {            httpClient = (GlomoAppHttpClient *) appList->appDetail;            if (httpClient->connectionId == connId)            {                return httpClient;            }        }    }    return NULL;}/* * NAME:        AppHttpClientUpdateHttpClient. * PURPOSE:     update existing http client data structure by including  *              connection id. * PARAMETERS:  nodePtr - pointer to the node. *              openResult - result of the open request. * RETRUN:      the pointer to the created http client data structure, *              NULL if no data structure allocated. */static GlomoAppHttpClient *AppHttpClientUpdateHttpClient(GlomoNode *nodePtr,                            TransportToAppOpenResult *openResult){    char clockStr[GLOMO_MAX_STRING_LENGTH];    AppInfo *appList = nodePtr->appData.appPtr;    GlomoAppHttpClient *tmpHttpClient = NULL;    GlomoAppHttpClient *httpClient = NULL;    for (; appList != NULL; appList = appList->appNext)    {        if (appList->appType == APP_HTTP_CLIENT)        {            tmpHttpClient = (GlomoAppHttpClient *) appList->appDetail;            #ifdef DEBUG                printf("HTTP Client: Node %ld comparing uniqueId "                       "%ld with %ld\n", nodePtr->nodeAddr,                       tmpHttpClient->uniqueId, openResult->uniqueId);            #endif            if (tmpHttpClient->uniqueId == openResult->uniqueId)            {                httpClient = tmpHttpClient;                break;            }        }    }    if (httpClient == NULL)    {        assert(FALSE);    }    httpClient->connectionId = openResult->connectionId;    httpClient->localAddr = openResult->localAddr;    httpClient->remoteAddr = openResult->remoteAddr;    httpClient->sessionStart = simclock();    httpClient->sessionFinish = simclock();    httpClient->sessionIsClosed = FALSE;    #ifdef DEBUG        printf("HTTP Client: Node %ld updating http "               "client struture\n", nodePtr->nodeAddr);        printf("    connectionId = %d\n", httpClient->connectionId);        printf("    localAddr = %d\n", httpClient->localAddr);        printf("    remoteAddr = %d\n", httpClient->remoteAddr);    #endif    return httpClient;}/* * NAME:        AppHttpClientNewHttpClient. * PURPOSE:     create a new http client data structure, place it *              at the beginning of the application list.  * PARAMETERS:  nodePtr - pointer to the node. * RETURN:      the pointer to the created http client data structure, * */static GlomoAppHttpClient *AppHttpClientNewHttpClient(GlomoNode *nodePtr){    AppInfo *newApp;    GlomoAppHttpClient *httpClient;    newApp = (AppInfo *) pc_malloc(sizeof(AppInfo));    if (newApp == NULL)     {        assert(FALSE);    }    httpClient = (GlomoAppHttpClient *) pc_malloc(sizeof(GlomoAppHttpClient));    if (httpClient == NULL)     {        assert(FALSE);    }    newApp->appType = APP_HTTP_CLIENT;      httpClient->connectionId = -1;    httpClient->uniqueId = nodePtr->appData.uniqueId++;    httpClient->localAddr = nodePtr->nodeAddr;    httpClient->remoteAddr = ANY_DEST;    httpClient->itemSizeLeft = 0;    httpClient->numBytesSent = 0;    httpClient->numBytesRecvd = 0;    httpClient->numSessions = 0;    httpClient->numPages = 0;    httpClient->avgSessionLength = 0;    #ifdef DEBUG        printf("HTTP Client: Node %ld creating new http "               "client struture\n", nodePtr->nodeAddr);        printf("    connectionId = %d\n", httpClient->connectionId);        printf("    localAddr = %d\n", httpClient->localAddr);    #endif    newApp->appDetail = httpClient;    newApp->appNext = nodePtr->appData.appPtr;     nodePtr->appData.appPtr = newApp;    return httpClient;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -