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


C++ CBaseSocket类代码示例

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


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

示例1: netlib_shutdown

bool netlib_shutdown(net_handle_t handle)
{
	CBaseSocket* pSocket = FindBaseSocket(handle);
	if (!pSocket)
		return false;

	return pSocket->Shutdown(2);
}
开发者ID:hgl888,项目名称:TeamTalk,代码行数:8,代码来源:netlib.cpp

示例2: netlib_recv

int netlib_recv(net_handle_t handle, void* buf, int len)
{
	CBaseSocket* pSocket = FindBaseSocket(handle);
	if (!pSocket)
		return NETLIB_ERROR;

	int ret = pSocket->Recv(buf, len);
	pSocket->ReleaseRef();
	return ret;
}
开发者ID:narychen,项目名称:egserv,代码行数:10,代码来源:netlib.cpp

示例3: netlib_close

int netlib_close(net_handle_t handle)
{
	CBaseSocket* pSocket = FindBaseSocket(handle);
	if (!pSocket)
		return NETLIB_ERROR;

	int ret = pSocket->Close();
	pSocket->ReleaseRef();
	return ret;
}
开发者ID:narychen,项目名称:egserv,代码行数:10,代码来源:netlib.cpp

示例4: netlib_send

int netlib_send( net_handle_t handle, void *buf, int len)
{
    CBaseSocket *pSocket = FindBaseSocket(handle);
    if( NULL == pSocket)
    {
        return NETLIB_ERROR;
    }
    int ret = pSocket->Send(buf, len);
    pSocket->ReleaseRef();
    return ret;
}
开发者ID:hgl888,项目名称:Server,代码行数:11,代码来源:netlib.cpp

示例5: FindBaseSocket

CBaseSocket* FindBaseSocket(net_handle_t fd)
{
    CBaseSocket* pSocket = NULL;
    SocketMap::iterator iter = g_socket_map.find(fd);
    if (iter != g_socket_map.end())
    {
        pSocket = iter->second;
        pSocket->AddRef();
    }
    
    return pSocket;
}
开发者ID:chenjiang3,项目名称:yosemite,代码行数:12,代码来源:BaseSocket.cpp

示例6: netlib_close

int netlib_close(net_handle_t handle)
{
	CBaseSocket* pSocket = FindBaseSocket(handle);
	if (!pSocket)
	{
		LOG__(APP, _T("can not find base socket,handle:%d"),handle);
		return NETLIB_ERROR;
	}

	int ret = pSocket->Close();
	pSocket->ReleaseRef();
	return ret;
}
开发者ID:hgl888,项目名称:TeamTalk,代码行数:13,代码来源:netlib.cpp

示例7: netlib_option

int netlib_option(net_handle_t handle, int opt, void* optval)
{
	CBaseSocket* pSocket = FindBaseSocket(handle);
	if (!pSocket)
		return NETLIB_ERROR;

	if ((opt >= NETLIB_OPT_GET_REMOTE_IP) && !optval)
		return NETLIB_ERROR;

	switch (opt)
	{
	case NETLIB_OPT_SET_CALLBACK:
		pSocket->SetCallback((callback_t)optval);
		break;
	case NETLIB_OPT_SET_CALLBACK_DATA:
		pSocket->SetCallbackData(optval);
		break;
	case NETLIB_OPT_GET_REMOTE_IP:
		*(string*)optval = pSocket->GetRemoteIP();
		break;
	case NETLIB_OPT_GET_REMOTE_PORT:
		*(uint16_t*)optval = pSocket->GetRemotePort();
		break;
	case NETLIB_OPT_GET_LOCAL_IP:
		*(string*)optval = pSocket->GetLocalIP();
		break;
	case NETLIB_OPT_GET_LOCAL_PORT:
		*(uint16_t*)optval = pSocket->GetLocalPort();
	}

	pSocket->ReleaseRef();
	return NETLIB_OK;
}
开发者ID:9618211,项目名称:TTServer,代码行数:33,代码来源:netlib.cpp

示例8: netlib_listen

int netlib_listen(const char *server_ip, uint16_t port,
                  callback_t callback, void *callback_data)
{
    CBaseSocket *pSocket = new CBaseSocket();
    if( NULL == pSocket )
    {
        return NETLIB_ERROR;
    }
    int ret = pSocket->Listen(server_ip, port, callback, callback_data);
    if( ret == NETLIB_ERROR){
        delete pSocket;
    }
    return ret;
}
开发者ID:hgl888,项目名称:Server,代码行数:14,代码来源:netlib.cpp

示例9: netlib_connect

net_handle_t netlib_connect(
		const char* server_ip, 
		uint16_t	port, 
		callback_t	callback, 
		void*		callback_data)
{
	CBaseSocket* pSocket = new CBaseSocket();
	if (!pSocket)
		return NETLIB_INVALID_HANDLE;

	net_handle_t handle = pSocket->Connect(server_ip, port, callback, callback_data);
	if (handle == NETLIB_INVALID_HANDLE)
		delete pSocket;
	return handle;
}
开发者ID:narychen,项目名称:egserv,代码行数:15,代码来源:netlib.cpp

示例10: sizeof

void CBaseSocket::_AcceptNewSocket()
{
    SOCKET fd = 0;
    sockaddr_in peer_addr;
    socklen_t addr_len = sizeof(sockaddr_in);
    char ip_str[64];
    
    while ( (fd = accept(m_socket, (sockaddr*)&peer_addr, &addr_len)) != INVALID_SOCKET )
    {
        CBaseSocket* pSocket = new CBaseSocket();
        
        uint32_t ip = ntohl(peer_addr.sin_addr.s_addr);
        uint16_t port = ntohs(peer_addr.sin_port);
        
        snprintf(ip_str, sizeof(ip_str), "%d.%d.%d.%d", ip >> 24, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, ip & 0xFF);
        
//        log("AcceptNewSocket, socket=%d from %s:%d\n", fd, ip_str, port);
        
        pSocket->SetSocket(fd);
        pSocket->SetCallback(m_callback);
        pSocket->SetCallbackData(m_callback_data);
        pSocket->SetState(SOCKET_STATE_CONNECTED);
        pSocket->SetRemoteIP(ip_str);
        pSocket->SetRemotePort(port);
        
        _SetNoDelay(fd);
        _SetNonblock(fd);
        AddBaseSocket(pSocket);
        CEventDispatch::Instance()->AddEvent(fd, SOCKET_READ | SOCKET_EXCEP);
        m_callback(m_callback_data, NETLIB_MSG_CONNECT, (net_handle_t)fd, NULL);
    }
}
开发者ID:chenjiang3,项目名称:yosemite,代码行数:32,代码来源:BaseSocket.cpp

示例11:

void Syscall::ConnOp::addSockConnect(CBaseSocket& sock, TSockAddr& addr, int port,
	const TDesC* hostname)
{
	CSO_ADD(SockConnect, addr, port, sock);
	CMySecureSocket* mss = sock.ssl();
	if(mss) {
		CSO_ADD(SecureHandshake, *mss, hostname);
	}
}
开发者ID:Felard,项目名称:MoSync,代码行数:9,代码来源:netImpl.cpp

示例12: netlib_option

int netlib_option( net_handle_t handel, int opt, void *optval)
{
    CBaseSocket *pSocket = FindBaseSocket(handel);
    if( NULL == pSocket )
    {
        return NETLIB_ERROR;
    }
    
    if((opt >= NETLIB_OPT_GET_REMOTE_IP) && !optval )
    {
        return NETLIB_ERROR;
    }
    
    switch (opt) {
        case NETLIB_OPT_SET_CALLBACK:
            pSocket->SetCallback((callback_t)optval);
            break;
        case NETLIB_OPT_SET_CALLBACK_DATA:
            pSocket->SetCallbackData(optval);
            break;
        case NETLIB_OPT_GET_REMOTE_IP:
            *(string*)optval = pSocket->GetRemoteIP();
            break;
        case NETLIB_OPT_GET_REMOTE_PORT:
            *(string*)optval = pSocket->GetRemotePort();
            break;
        case NETLIB_OPT_GET_LOCAL_IP:
            *(string*)optval = pSocket->GetLocalIP();
            break;
        case NETLIB_OPT_GET_LOCAL_PORT:
            *(string*)optval = pSocket->GetLocalPort();
            break;
        case NETLIB_OPT_SET_SEND_BUF_SIZE:
            pSocket->SetSendBufSize(*(uint32_t*)optval);
            break;
        case NETLIB_OPT_SET_RECV_BUF_SIZE:
            pSocket->SetRecvBufSize(*(uint32_t*)optval);
            break;
    }
    pSocket->ReleaseRef();
    return NETLIB_OK;
}
开发者ID:hgl888,项目名称:Server,代码行数:42,代码来源:netlib.cpp

示例13: sizeof

void CBaseSocket::_AcceptNewSocket()
{
	SOCKET fd = 0;
	sockaddr_in peer_addr;
	socklen_t addr_len = sizeof(sockaddr_in);
	char ip_str[64];
	while ( (fd = accept(m_socket, (sockaddr*)&peer_addr, &addr_len)) != INVALID_SOCKET )
	{
		CBaseSocket* pSocket = new CBaseSocket(m_pBaseServer);
		uint32_t ip = ntohl(peer_addr.sin_addr.s_addr);
		uint16_t port = ntohs(peer_addr.sin_port);

		snprintf(ip_str, sizeof(ip_str), "%d.%d.%d.%d", ip >> 24, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, ip & 0xFF);

		printf("AcceptNewSocket, socket=%d from %s:%d\n", fd, ip_str, port);

		pSocket->SetSocket(fd);
		pSocket->SetState(SOCKET_STATE_CONNECTED);
		pSocket->SetRemoteIP(ip_str);
		pSocket->SetRemotePort(port);
		pSocket->SetNotify(m_Notify);

		_SetNoDelay(fd);
		_SetNonblock(fd);
		m_pBaseServer->AddBaseSocket(pSocket);
		m_pBaseServer->AddEvent(fd, SOCKET_READ | SOCKET_EXCEP);
		m_Notify->OnConnect((net_handle_t)fd);
	}
}
开发者ID:jiephe,项目名称:ExerciseServerCode,代码行数:29,代码来源:BaseSocket.cpp

示例14: while

void CEventDispatch::StartDispatch(uint32_t wait_timeout)
{
	struct epoll_event events[1024];
	int nfds = 0;
    
	while (running)
	{
		nfds = epoll_wait(m_epfd, events, 1024, wait_timeout);
		for (int i = 0; i < nfds; i++)
		{
			int ev_fd = events[i].data.fd;
			CBaseSocket* pSocket = FindBaseSocket(ev_fd);
			if (!pSocket)
				continue;

			if (events[i].events & EPOLLIN)
			{
				//LOG__(NET,  "OnRead, socket=%d\n", ev_fd);
				pSocket->OnRead();
			}

			if (events[i].events & EPOLLOUT)
			{
				//LOG__(NET,  "OnWrite, socket=%d\n", ev_fd);
				pSocket->OnWrite();
			}

			if (events[i].events & (EPOLLPRI | EPOLLERR | EPOLLHUP))
			{
				//LOG__(NET,  "OnClose, socket=%d\n", ev_fd);
				pSocket->OnClose();
			}

			pSocket->ReleaseRef();
		}

		_CheckTimer();
		_CheckLoop();
	}
}
开发者ID:hgl888,项目名称:TeamTalk,代码行数:40,代码来源:EventDispatch.cpp

示例15: while

void CEventDispatch::StartDispatch()
{
    struct epoll_event events[1024];
    int nfds = 0;

    while (true)
    {
        nfds = epoll_wait(m_epfd, events, 1024, MIN_TIMER_DURATION);
        for (int i = 0; i < nfds; i++)
        {
            int ev_fd = events[i].data.fd;
            CBaseSocket* pSocket = FindBaseSocket(ev_fd);
            if (!pSocket)
                continue;

            if (events[i].events & EPOLLIN)
            {
                //log("OnRead, socket=%d\n", ev_fd);
                pSocket->OnRead();
            }

            if (events[i].events & EPOLLOUT)
            {
                //log("OnWrite, socket=%d\n", ev_fd);
                pSocket->OnWrite();
            }

            if (events[i].events & (EPOLLPRI | EPOLLERR | EPOLLHUP))
            {
                //log("OnClose, socket=%d\n", ev_fd);
                pSocket->OnClose();
            }

            pSocket->ReleaseRef();
        }

        _CheckTimer();
    }
}
开发者ID:houzhenggang,项目名称:TTServer-1,代码行数:39,代码来源:EventDispatch.cpp


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