本文整理汇总了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!
}
示例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)
{
//.........这里部分代码省略.........