本文整理汇总了C++中TCPClient::close_conn方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPClient::close_conn方法的具体用法?C++ TCPClient::close_conn怎么用?C++ TCPClient::close_conn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TCPClient
的用法示例。
在下文中一共展示了TCPClient::close_conn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
void *
receiver(void * v) {
TCPClient *client = (TCPClient*) v;
assert(client != NULL);
assert (client->get_sock() >= 0);
while (client->running) {
if (!client->running) {
break;
}
char buffer[RECEIVE_BUFFER_SIZE];
int allBytesRead = 0;
int actBytesRead = 0;
read_modes act_read_mode = client->get_read_mode();
while (allBytesRead < (RECEIVE_BUFFER_SIZE-1)) {
actBytesRead = recv(client->get_sock(), buffer, sizeof(buffer), 0);
if (actBytesRead < 0) {
// perror("receive failed!");
break;
} else if (actBytesRead == 0) {
std::cout << "connection reset.. " << std::endl;
if (allBytesRead > 0) {
buffer[allBytesRead+1] = '\0';
std::cout << "last bytes received: " << buffer << std::endl;
}
client->close_conn();
client->running = false;
return 0;
}
allBytesRead += actBytesRead;
if (act_read_mode == INCOME) {
break;
}
}
if (allBytesRead > 0) {
buffer[allBytesRead] = '\0';
std::cout << "received: " << buffer << std::endl;
}
}
return 0;
}