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


C++ CBaseSocket::SetCallback方法代码示例

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


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

示例1: _AcceptNewSocket

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

示例2: 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

示例3: 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


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