本文整理汇总了C++中TcpConnection::release方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpConnection::release方法的具体用法?C++ TcpConnection::release怎么用?C++ TcpConnection::release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpConnection
的用法示例。
在下文中一共展示了TcpConnection::release方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: event_loop
void NetWork::event_loop()
{
TRACE(__PRETTY_FUNCTION__);
//最大时间间隔是1s
int timeout = 1000;
IOEvent events[128];
while (!_stop) {
memset(events, 0, sizeof(events));
int n = _sock_event->get_events(timeout, events, 128);
for (int i = 0; i < n; i++) {
IOEvent &ev = events[i];
TcpConnection *conn = ev.conn;
conn->add_ref();
if (ev._read_ocurr)
conn->on_read_event();
if (ev._write_ocurr) {
conn->on_write_event();
}
conn->release();
}
//定时处理
time_process(time(NULL));
}
}
示例2: getStatus
int NetWork::getStatus(int handle)
{
TRACE(__PRETTY_FUNCTION__);
int status = NET_STATE_INVALID_HANDLE;
TcpConnection *conn = _online_user.getconn(handle);
if (conn != NULL) {
switch (conn->getstate()) {
case WAIT_CLOSE:
case CLOSED:
status = NET_STATE_CLOSED;
break;
//connecting 和 CRYPTREGING都认为是正在连接状态
case CONNECTING:
case CRYPTREGING:
status = NET_STATE_CONNECTING;
break;
case CONNECTED:
status = NET_STATE_CONNECTED;
break;
default:
break;
}
conn->release();
}
return status;
}
示例3: g
void NetWork::OnlineUser::clear()
{
Guard g(_mutex);
//将closing的数据清除掉
while (!_recycles.empty()) {
TcpConnection *conn = _recycles.front();
_recycles.pop_front();
conn->release();
}
}
示例4: send
//数据发送,只是投递到发送缓冲区,return 0:表示投递成功
bool NetWork::send(int handle, const char *buffer, int len)
{
bool ret = false;
TcpConnection *conn = _online_user.getconn(handle);
if (conn != NULL) {
ret = conn->deliver_data(buffer, len);
conn->release();
}
return ret;
}
示例5: make_handle
int NetWork::make_handle()
{
static int h = 0;
TcpConnection *conn = NULL;
h++;
while ((conn = _online_user.getconn(h)) != NULL) {
h++;
if (h >= MAX_INT) {
h = 0;
}
conn->release();
}
return h;
}
示例6: close
//主动关闭连接
void NetWork::close(int handle)
{
TRACE(__PRETTY_FUNCTION__);
TcpConnection *conn = _online_user.getconn(handle);
if (conn != NULL) {
//从kqueue/epoll中线拿出来,防止再触发事件,导致各种复杂耦合
_sock_event->remove_event(conn);
//判断removeconn的返回值,主线程和业务线程同时调用close时,产生conn->close重复调用
if (_online_user.removeconn(handle)) {
conn->close();
}
conn->release();
}
return;
}