当前位置: 首页>>代码示例>>C++>>正文


C++ MsgDistributor::close方法代码示例

本文整理汇总了C++中MsgDistributor::close方法的典型用法代码示例。如果您正苦于以下问题:C++ MsgDistributor::close方法的具体用法?C++ MsgDistributor::close怎么用?C++ MsgDistributor::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MsgDistributor的用法示例。


在下文中一共展示了MsgDistributor::close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: errorSocket

/******************************************************************************
Description.: print out the error message and exit
Input Value.:
Return Value:
******************************************************************************/
void errorSocket(const char *msg, int sock)
{
    errno = EBADF;
    perror(msg);
    if (!orbit)
    {
        close(sock);     
    }
    else
    {
        MsgD.close(sock, 1);
    }
    printf("[server] Connection closed. --- error\n\n");
    pthread_exit(NULL); //terminate calling thread!
}
开发者ID:avicooper1,项目名称:opencv-CPS,代码行数:20,代码来源:server-OpenCV.cpp

示例2: server_result

/******************************************************************************
Description: function for sending back the result
Input Value.:
Return Value:
******************************************************************************/
void server_result (int sock, string userID)
{
    // printf("result thread\n\n");

    int n;
    char response[BUFFER_SIZE] = "ok";
    char defMsg[BUFFER_SIZE] = "none";
    int matchedIndex;
    char sendInfo[BUFFER_SIZE];
    vector<float> coord;
    sem_t *sem_match = new sem_t(); // create a new semaphore in heap
    queue<string> *imgQueue = 0;    // queue storing the file names 

    //  Init semaphore and put the address of semaphore into map
    if (sem_init(sem_match, 0, 0) != 0)
    {
        errorSocket("ERROR semaphore init failed", sock);
    }
    // grap the lock
    pthread_mutex_lock(&sem_map_lock);
    sem_map[userID] = sem_match;
    pthread_mutex_unlock(&sem_map_lock);

    // reponse to the client
    if (!orbit)
    {
        n = write(sock, response, sizeof(response));
        if (n < 0)
        {
            error("ERROR writting to socket");
        }
    }
    else
    {
        MsgD.send(sock, response, BUFFER_SIZE);
    }

    while(!global_stop) 
    {
        sem_wait(sem_match);
        // get the address of image queue
        if (imgQueue == 0)
        {
            imgQueue = queue_map[userID];
        }

        // check if the queue is empty
        if (imgQueue->empty())
        {
            sem_map.erase(userID);
            queue_map.erase(userID);
            user_map.erase(userID);
            delete(sem_match);
            delete(imgQueue);
            sem_destroy(sem_match);
            MsgD.close(sock, 0);
            printf("[server] client disconnectted\n");
            pthread_exit(NULL); //terminate calling thread!
        }

        if (debug) printf("\n----------- start matching -------------\n");
        string file_name = imgQueue->front(); 
        if (debug) printf("file name: %s\n", file_name.c_str());
        imgQueue->pop();

        // start matching the image
        imgM.matchImg(file_name);
        matchedIndex = imgM.getMatchedImgIndex();
        if (matchedIndex == 0) 
        {   
            // write none to client
            if (!orbit) {
                if (write(sock, defMsg, sizeof(defMsg)) < 0)
                {
                   errorSocket("ERROR writting to socket", sock);
                }

            }
            else
            {
                MsgD.send(sock, defMsg, BUFFER_SIZE);
            }

            if (debug) printf("not match\n");            
        }
        else
        {
            // write index to client
            coord = imgM.calLocation();
            sprintf(sendInfo, "%d,%f,%f,%f,%f,%f,%f,%f,%f", matchedIndex, coord.at(0), coord.at(1), coord.at(2), coord.at(3), coord.at(4), coord.at(5), coord.at(6), coord.at(7));
            if (debug) printf("sendInfo: %s\n", sendInfo);
            if (!orbit)
            {
                if (write(sock, sendInfo, sizeof(sendInfo)) < 0)
                {
//.........这里部分代码省略.........
开发者ID:avicooper1,项目名称:opencv-CPS,代码行数:101,代码来源:server-OpenCV.cpp


注:本文中的MsgDistributor::close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。