Ejemplo n.º 1
0
int NetWork::connect(const char *ip, unsigned short port, bool encrypt)
{
	int handle = -1;
	TcpConnection *conn = new TcpConnection(this);

//	if(encrypt) conn->set_encrypt();
	if (conn->connect(ip, port)) {
		if (_online_user.addconn(conn)) {
			_sock_event->add_event(conn, true, true);
			handle = conn->gethandle();
		}
	} else {
		LOGI("NetWork::connect connect fail : %s", strerror(errno));
		//如果连接失败,将底层的网络错误码的负值返回回去;
		handle = (conn->last_sys_errno() * (-1));
		delete conn;
	}

	return handle;
}