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


C++ TcpConnection类代码示例

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


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

示例1: LOG

void 
NetServer::onLeaveUdpGroup( const NetGroupOp& op )
{
	NetGroupMap::iterator i = m_groups.find( op.groupId );

	if ( i == m_groups.end() )
	{
		LOG( FT_WARN, _T("NetServer::onLeaveUdpGroup> %d not found"), op.groupId );

		return;
	}

	TcpConnection* c = m_tcp.FindById( op.connectionId );
	
	if ( c != 0 )
	{
		c->SetGroup( 0 );
	}

	NetGroup* group = i->second;
	K_ASSERT( group != 0 );

	group->Leave( op.connectionId );

	LOG( FT_DEBUG, 
		 _T("NetServer::onLeaveUdpGroup> %d left from %d"), 
		 op.connectionId, group->GetId() );
}
开发者ID:criptych,项目名称:gamekernel,代码行数:28,代码来源:NetServer.cpp

示例2: socket

TcpConnection* TcpConnector::connect(const TcpSockAddr& addr, int &ret, long timeout) {
    int sockfd;

    ret = -1;
    sockfd = socket(addr.ai_family, SOCK_STREAM, 0);
    if (sockfd < 0) return 0L;

    if (timeout < 0)
        ret = ::connect(sockfd, (struct sockaddr*)&addr.ai_addr, addr.ai_addrlen);
    else
        ret = timeout_connect(sockfd, (struct sockaddr*)&addr.ai_addr, addr.ai_addrlen, timeout);

    if (ret < 0) {
        close(sockfd);
        return 0L;
    } else {
        TcpConnection *tcon;
        tcon = new TcpConnection;
        if (tcon->set_fd(sockfd) < 0) {
            delete tcon;
            return 0L;
        } else {
            return tcon;
        }
    }
}
开发者ID:richard-liang,项目名称:mytget,代码行数:26,代码来源:tcp.cpp

示例3: JTRACE

void
SocketConnList::drain()
{
  // First, let all the Connection prepare for drain
  ConnectionList::drain();

  // this will block until draining is complete
  KernelBufferDrainer::instance().monitorSockets(DRAINER_CHECK_FREQ);

  // handle disconnected sockets
  const map<ConnectionIdentifier, vector<char> > &discn =
    KernelBufferDrainer::instance().getDisconnectedSockets();

  map<ConnectionIdentifier, vector<char> >::const_iterator it;
  for (it = discn.begin(); it != discn.end(); it++) {
    const ConnectionIdentifier &id = it->first;
    TcpConnection *con =
      (TcpConnection *)SocketConnList::instance().getConnection(id);
    JTRACE("recreating disconnected socket") (id);

    // reading from the socket, and taking the error, resulted in an
    // implicit close().
    // we will create a new, broken socket that is not closed
    con->onError();
  }
}
开发者ID:dmtcp,项目名称:dmtcp,代码行数:26,代码来源:socketconnlist.cpp

示例4: TRACE

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));
	}

}
开发者ID:Hidebush,项目名称:podText,代码行数:26,代码来源:network.cpp

示例5: accept

TcpConnection* TcpAcceptor::accept(const TcpSockAddr& expect, int &ret, long timeout) {
    TcpConnection* conn;
    TcpSockAddr peer_sock;

    conn = accept(ret, timeout);
    if (!conn) return 0L;

    conn->get_remote_addr(peer_sock);

    if (peer_sock.ai_family == expect.ai_family) {
        if (peer_sock.ai_family == AF_INET) {
            // so dirty ~_~
            if (!memcmp(&(((struct sockaddr_in*)&(peer_sock.ai_addr))->sin_addr),
                        &(((struct sockaddr_in*)&(expect.ai_addr))->sin_addr),
                        sizeof(struct in_addr)))
                return conn;
        } else if (peer_sock.ai_family == AF_INET6) {
            // so dirty ~_~
            if (!memcmp(&(((struct sockaddr_in6*)&(peer_sock.ai_addr))->sin6_addr),
                        &(((struct sockaddr_in6*)&(expect.ai_addr))->sin6_addr),
                        sizeof(struct in6_addr)))
                return conn;
        }
    }

    delete conn;

    return 0L;
}
开发者ID:richard-liang,项目名称:mytget,代码行数:29,代码来源:tcp.cpp

示例6: runTest

    void runTest() {
        m_strategy = new OpenConnectionStrategy(this);

        m_client_listener = new ClientTcpListener(this);
        m_server_listener = new ServerTcpListener(this);

        m_evmanager = new EventManager();
        m_client = new TcpConnection(IpAddress("127.0.0.1", 9999));
        m_listener = new TcpListener();

        m_listener->listen(9999);
        m_listener->setListener(this);

        m_client->setEventManager(m_evmanager);
        m_client->setListener(m_client_listener);
        m_client->open();

        m_evmanager->registerClient(m_listener);
        m_evmanager->registerClient(m_client);

        m_evmanager->execute();

        delete m_strategy;

        delete m_client_listener;
        delete m_server_listener;

        delete m_client;
        delete m_server;
        delete m_listener;
        delete m_evmanager;
    }
开发者ID:vlad-d-markin,项目名称:megachat-networklib-common,代码行数:32,代码来源:test_async_listener.cpp

示例7: JTRACE

void SocketConnList::scanForPreExisting()
{
  // FIXME: Detect stdin/out/err fds to detect duplicates.
  vector<int> fds = jalib::Filesystem::ListOpenFds();
  for (size_t i = 0; i < fds.size(); ++i) {
    int fd = fds[i];
    if (!Util::isValidFd(fd)) continue;
    if (dmtcp_is_protected_fd(fd)) continue;

    string device = jalib::Filesystem::GetDeviceName(fd);

    JTRACE("scanning pre-existing device") (fd) (device);
    if (device == jalib::Filesystem::GetControllingTerm()) {
    } else if(dmtcp_is_bq_file && dmtcp_is_bq_file(device.c_str())) {
    } else if( fd <= 2 ){
    } else if (Util::strStartsWith(device, "/")) {
    } else {
      JNOTE("found pre-existing socket... will not be restored")
        (fd) (device);
      TcpConnection* con = new TcpConnection(0, 0, 0);
      con->markPreExisting();
      add(fd, con);
    }
  }
}
开发者ID:apoorvemohan,项目名称:experiments,代码行数:25,代码来源:socketconnlist.cpp

示例8:

void *thread_fun(void *arg)
{
	TcpConnection *server = (TcpConnection*)arg;
	server->event_loop();

	return NULL;
}
开发者ID:sotter,项目名称:net-test,代码行数:7,代码来源:tcpconnection.cpp

示例9: debugf

err_t TcpServer::onAccept(tcp_pcb *clientTcp, err_t err)
{
	// Anti DDoS :-)
	if (system_get_free_heap_size() < 6500)
	{
		debugf("\r\n\r\nCONNECTION DROPPED\r\n\t(%d)\r\n\r\n", system_get_free_heap_size());
		return ERR_MEM;
	}

	#ifdef NETWORK_DEBUG
	debugf("onAccept state: %d K=%d", err, totalConnections);
	list_mem();
	#endif

	if (err != ERR_OK)
	{
		//closeTcpConnection(clientTcp, NULL);
		return err;
	}

	TcpConnection* client = createClient(clientTcp);
	if (client == NULL) return ERR_MEM;
	client->setTimeOut(timeOut);
	onClient((TcpClient*)client);

	return ERR_OK;
}
开发者ID:Hukuma23,项目名称:WS,代码行数:27,代码来源:TcpServer.cpp

示例10: LOG_WARN

bool 
ListenerWorker::onUpdateTimer(void* args)
{
    UInt32 currTime = TimeUtil::getTimeSec();

	if (currTime - mLastSecurityCheckTime >= 300000)
	{
		mLastSecurityCheckTime = currTime;

		for (Set<TcpConnection*>::Iter* iter = mMainConnectionSet.begin(); iter != NULL;)
		{
			TcpConnection* conn = iter->mValue;
			if (conn)
			{
				if (currTime - conn->getRecvTimeStamp() >= 
					CLIENT_CONNECTION_SECURITY_CHECK_INTERVAL)
				{
					LOG_WARN("Connection [%s:%u] was closed for timeout.", 
						conn->getFromIp().c_str(), conn->getFromPort());
					LYNX_DEREGISTER_RECEIVED(conn, this, &ListenerWorker::onMainReceived);
					LYNX_DEREGISTER_CONNECT_BROKEN(conn, this, &ListenerWorker::onMainDisconnected);
					conn->close();
					iter = mMainConnectionSet.erase(iter);
					XDELETE(conn);
				}
				else
				{
					iter = mMainConnectionSet.next(iter);
				}
			}
		}

        for (Set<TcpConnection*>::Iter* iter = mGMConnectionSet.begin(); iter != NULL;)
		{
			TcpConnection* conn = iter->mValue;
			if (conn)
			{
				if (currTime - conn->getRecvTimeStamp() >= 
					CLIENT_CONNECTION_SECURITY_CHECK_INTERVAL)
				{
					LOG_WARN("Connection [%s:%u] was closed for timeout.", 
						conn->getFromIp().c_str(), conn->getFromPort());
					LYNX_DEREGISTER_RECEIVED(conn, this, &ListenerWorker::onGMReceived);
					LYNX_DEREGISTER_CONNECT_BROKEN(conn, this, &ListenerWorker::onGMDisconnected);
					conn->close();
					iter = mGMConnectionSet.erase(iter);
					XDELETE(conn);
				}
				else
				{
					iter = mGMConnectionSet.next(iter);
				}
			}
		}
	}
    return true;
}
开发者ID:secondtonone1,项目名称:fingerserver,代码行数:57,代码来源:ListenerWorker.cpp

示例11: tcp_recved

err_t TcpConnection::staticOnReceive(void *arg, tcp_pcb *tcp, pbuf *p, err_t err)
{
//	debugf("Static OnReceive buf = %d", tcp_sndbuf(tcp));
	TcpConnection* con = (TcpConnection*)arg;
	err_t ret_err;
	//Serial.println("echo_recv!");

	if (con == NULL)
	{
		if (p != NULL)
		{
		  /* Inform TCP that we have taken the data. */
		  tcp_recved(tcp, p->tot_len);
		  pbuf_free(p);
		}
		closeTcpConnection(tcp);
		return ERR_OK;
	}
	else
		con->sleep = 0;

	if (err != ERR_OK /*&& err != ERR_CLSD && err != ERR_RST*/)
	{
		debugf("Received ERROR %d", err);
		/* exit and free resources, for unkown reason */
		if (p != NULL)
		{
		  /* Inform TCP that we have taken the data. */
		  tcp_recved(tcp, p->tot_len);
		  pbuf_free(p);
		}
		closeTcpConnection(tcp); // ??
		con->tcp = NULL;
		con->onError(err);
		//con->close();
		return err == ERR_ABRT ? ERR_ABRT : ERR_OK;
	}

	//if (tcp != NULL && tcp->state == ESTABLISHED) // If active
	/* We have taken the data. */
	if (p != NULL)
		tcp_recved(tcp, p->tot_len);

	err_t res = con->onReceive(p);

	if (p != NULL)
		pbuf_free(p);
	else
	{
		con->close();
		closeTcpConnection(tcp);
	}

	con->checkSelfFree();
	//debugf("<staticOnReceive");
	return res;
}
开发者ID:BorntraegerMarc,项目名称:SmingRTOS,代码行数:57,代码来源:TcpConnection.cpp

示例12: K_ASSERT

void 
NetClient::onGroupPrepare( MessagePtr m )
{
	K_ASSERT( m_groupId == 0 );
	K_ASSERT( m_selfTag == 0 );

	m_groupId = 0;
	m_selfTag = 0;

	NmGroupPrepare* gp = static_cast<NmGroupPrepare*>( m.Get() );

	TcpConnection* c = m_tcp.FindById( gp->remote );

	if ( c == 0 )
	{
		LOG( FT_WARN, 
			 _T("NetClient::onGroupPrepare> Connection %d not found"), 
			 gp->remote );

		return;
	}
	
	m_udp.Fini();

	m_groupId = gp->groupId;
	m_selfTag = gp->connectionId;

	// init udp with c as a relay connection 
	// use same ip:port as TCP connection
	bool rc = m_udp.Init( this, 
						  &m_ios, 
						  c->GetSocket()->GetAddress(), 
						  m_selfTag, 
						  gp->sl, 
						  gp->challenge, 
						  c );

	if ( !rc )
	{
		LOG( FT_WARN, _T("NetClient::onGroupPrepare> Failed to init udp") );

		return;
	}

	NmGroupPrepared* p = new NmGroupPrepared;

	p->remote 		= gp->remote;
	p->groupId 		= gp->groupId;
	p->connectionId = gp->connectionId;
	p->in 			= c->GetSocket()->GetAddress();

	m_tcp.Send( m->remote, MessagePtr( p ) );

	LOG( FT_DEBUG, _T("NetClient::onGroupPrepare> Prepared group %d connection %d"), 
		 gp->groupId, 
		 gp->connectionId );
}
开发者ID:criptych,项目名称:gamekernel,代码行数:57,代码来源:NetClient.cpp

示例13: g

void NetWork::OnlineUser::clear()
{
	Guard g(_mutex);
	//将closing的数据清除掉
	while (!_recycles.empty()) {
		TcpConnection *conn = _recycles.front();
		_recycles.pop_front();
		conn->release();
	}
}
开发者ID:Hidebush,项目名称:podText,代码行数:10,代码来源:network.cpp

示例14: staticOnError

void TcpConnection::staticOnError(void *arg, err_t err)
{
	TcpConnection* con = (TcpConnection*)arg;
	if (con == NULL) return;

	con->tcp = NULL; // IMPORTANT. No available connection after error!
	con->onError(err);
	con->checkSelfFree();
	//debugf("<staticOnError");
}
开发者ID:Werquinx,项目名称:Sming,代码行数:10,代码来源:TcpConnection.cpp

示例15: 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;
}
开发者ID:Hidebush,项目名称:podText,代码行数:12,代码来源:network.cpp


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