• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ GetSocket函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: SetIpRecvTTL

bool Socket::SetIpRecvTTL(bool x)
{
	int optval = x ? 1 : 0;
	if (setsockopt(GetSocket(), IPPROTO_IP, IP_RECVTTL, (char *)&optval, sizeof(optval)) == -1)
	{
		Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_RECVTTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
		return false;
	}
	return true;
}
开发者ID:Omniasoft,项目名称:BellPi,代码行数:10,代码来源:Socket.cpp


示例2: GetSocket

BOOL CXMMTCtrl::SendCode(short nIndex, short bCode) 
{
	if( bCode == CODE_CUSTOMSESSION ) return FALSE;
	int r = FALSE;
	CCSocket *pSocket = GetSocket(nIndex);
	if( pSocket ){
		BYTE b = BYTE(bCode);
		r = SendBuf(pSocket, &b, sizeof(b));
	}
	return r;
}
开发者ID:ja7ude,项目名称:XMMT,代码行数:11,代码来源:XMMTCtl.cpp


示例3: sizeof

bool ConnectionDescriptor::GetPeername (struct sockaddr *s)
{
	bool ok = false;
	if (s) {
		socklen_t len = sizeof(*s);
		int gp = getpeername (GetSocket(), s, &len);
		if (gp == 0)
			ok = true;
	}
	return ok;
}
开发者ID:alltom,项目名称:easyget,代码行数:11,代码来源:ed.cpp


示例4: ReConnectAsync

int32_t CSSLClientAsync::ReConnectAsync()
{
    int32_t nErrorCode = 0;
    if (S_INVALID_SOCKET == GetSocket())
    {
        _InitSocket();
        InitSSL(GetCertFile().c_str(), GetKeyFile().c_str(), GetKeyPassword().c_str());
        nErrorCode = ConnectAsync(GetRemoteIP(), GetRemotePort());
    }
    return nErrorCode;
}
开发者ID:shiwei0124,项目名称:common_code,代码行数:11,代码来源:ssl_client_async.cpp


示例5: UnInitSSL

void CSSLClientAsync::_Close()
{
    if (m_ssl)
    {
        UnInitSSL();
    }
    if (GetSocket() != S_INVALID_SOCKET)
    {
        if (m_pio)
        {
            m_pio->Remove_Handler(this);
        }
        SetSSLConnectStatus(FALSE);
        S_CloseSocket(GetSocket());
        SOCKET_IO_WARN("close ssl socket, sock %d, real sock: %d.", GetSocketID(), GetSocket());
        m_socket = S_INVALID_SOCKET;
        DoClose(GetSocketID());
        _ClearSendBuffer();
    }
}
开发者ID:shiwei0124,项目名称:common_code,代码行数:20,代码来源:ssl_client_async.cpp


示例6: Attach

bool UdpSocket::Open(SocketAddress& ad)
{
	if (GetSocket() == INVALID_SOCKET)
	{
		Attach(CreateSocket(ad.GetFamily(), SOCK_DGRAM, "udp"));
	}
	if (GetSocket() != INVALID_SOCKET)
	{
		SetNonblocking(true);
		if (connect(GetSocket(), ad, ad) == -1)
		{
			Handler().LogError(this, "connect", Errno, StrError(Errno), LOG_LEVEL_FATAL);
			SetCloseAndDelete();
			return false;
		}
		SetConnected();
		return true;
	}
	return false;
}
开发者ID:f059074251,项目名称:interested,代码行数:20,代码来源:UdpSocket.cpp


示例7: GetSocket

///////////////////////////////////////////////////////////////////////////////
/// @fn CConnection::Stop
/// @description Stops the socket and cancels the timeout timer. Does not
///   need to be called on a listening connection (ie one that has had
///   Start() called on it.
/// @pre Any initialized CConnection object.
/// @post The underlying socket is closed and the message timeout timer is
///        cancelled.
///////////////////////////////////////////////////////////////////////////////
void CConnection::Stop()
{
    Logger.Debug << __PRETTY_FUNCTION__ << std::endl;
    ProtocolMap::iterator sit;
    for(sit = m_protocols.begin(); sit != m_protocols.end(); sit++)
    {
        (*sit).second->Stop();
    }   
    Logger.Debug << __PRETTY_FUNCTION__ << std::endl;
    GetSocket().close();
}
开发者ID:akella84,项目名称:FREEDM,代码行数:20,代码来源:CConnection.cpp


示例8: sizeof

/** Returns local port number for bound socket file descriptor. */
port_t Socket::GetSockPort()
{
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
	if (IsIpv6())
	{
		struct sockaddr_in6 sa;
		socklen_t sockaddr_length = sizeof(struct sockaddr_in6);
		if (getsockname(GetSocket(), (struct sockaddr *)&sa, (socklen_t*)&sockaddr_length) == -1)
			memset(&sa, 0, sizeof(sa));
		return ntohs(sa.sin6_port);
	}
#endif
#endif
	struct sockaddr_in sa;
	socklen_t sockaddr_length = sizeof(struct sockaddr_in);
	if (getsockname(GetSocket(), (struct sockaddr *)&sa, (socklen_t*)&sockaddr_length) == -1)
		memset(&sa, 0, sizeof(sa));
	return ntohs(sa.sin_port);
}
开发者ID:amirkrifa,项目名称:BitHoc,代码行数:21,代码来源:socket.cpp


示例9: memset

/**	@fn	HPR_INT32 CTCPClient::Connect(const char* szIP, HPR_INT32 nPort)
*	@brief 
*	@param[in] szIP 
*	@param[in] nPort 
*	@return	
*/
HPR_INT32 CTCPClient::Connect( const char* szIP, HPR_INT32 nPort )
{
	HPR_INT32 nErrorCode = LIB_DEV_PROXY_ERROR_OK;
	HPR_ADDR_T addr;
	memset(&addr, 0, sizeof(HPR_ADDR_T));
	HPR_MakeAddrByString(AF_INET, szIP, nPort, &addr);
	if (HPR_ConnectWithTimeOut(GetSocket(), &addr, 5000) != 0)
	{
		nErrorCode = LIB_DEV_PROXY_ERROR_CONNECT;
	}
	return nErrorCode;
}
开发者ID:Strongc,项目名称:util_code,代码行数:18,代码来源:tcp_client.cpp


示例10: GetSocket

void CItem::StopTimerBasedOnWearExpireEvent()
{
	if (!m_pkTimerBasedOnWearExpireEvent)
		return;

	int remain_time = GetSocket(ITEM_SOCKET_REMAIN_SEC) - event_processing_time(m_pkTimerBasedOnWearExpireEvent) / passes_per_sec;

	SetSocket(ITEM_SOCKET_REMAIN_SEC, remain_time);
	event_cancel(&m_pkTimerBasedOnWearExpireEvent);

	ITEM_MANAGER::instance().SaveSingleItem(this);
}
开发者ID:ronniwe,项目名称:Varios,代码行数:12,代码来源:item.cpp


示例11: Handler

/** send to connected address */
void UdpSocket::SendBuf(const char *data, size_t len, int flags)
{
	if (!IsConnected())
	{
		Handler().LogError(this, "SendBuf", 0, "not connected", LOG_LEVEL_ERROR);
		return;
	}
	if ((m_last_size_written = send(GetSocket(), data, (int)len, flags)) == -1)
	{
		Handler().LogError(this, "send", Errno, StrError(Errno), LOG_LEVEL_ERROR);
	}
}
开发者ID:f059074251,项目名称:interested,代码行数:13,代码来源:UdpSocket.cpp


示例12: OnLine

    void OnLine(const std::string& line) {
#ifdef ENABLE_DETACH
        if (g_b_detach2 && !IsDetach())
        {
            m_line = line;
            if (!Detach())
            {
                fprintf(stderr, "\nDetach failed\n");
            }
            return;
        }
        DEB(printf("fd %d OnLine; %s\n", GetSocket(), Handler().IsSlave() ? "slave" : "master");)
开发者ID:JerkWisdom,项目名称:zpublic,代码行数:12,代码来源:echoserver.cpp


示例13: resolver

	void Client::Connect(const std::string& ip, int port)
	{
		tcp::resolver resolver(ioService);
		tcp::resolver::query query(ip, std::to_string(port));

		auto endpointIt = resolver.resolve(query);

		boost::system::error_code ec;

		auto newConn = Connection::create(ioService);
		boost::asio::async_connect(newConn->GetSocket(), endpointIt, std::bind(&Client::OnConnect, this, newConn, _1, _2));
	}
开发者ID:skyser2003,项目名称:FG-Network,代码行数:12,代码来源:FGClient.cpp


示例14: GetSocket

///////////////////////////////////////////////////////////////////////////////
/// CConnection::HandleResend
/// @description: After being called, this method sends up WINDOWSIZE messages
///   to retry delievery.
/// @pre: Initialized CConnection.
/// @post: Upto WINDOWSIZE messages are rewritten to the channel.
///////////////////////////////////////////////////////////////////////////////
void CConnection::HandleResend()
{
    Logger::Debug << __PRETTY_FUNCTION__ << std::endl;
    SlidingWindow<QueueItem>::iterator sit;
    sit = m_queue.begin();   
 
    for(unsigned int i=0; sit != m_queue.end() && i < GetWindowSize(); i++,sit++ )
    {
        GetSocket().get_io_service().post(
        boost::bind(&CConnection::HandleSend, this,(*sit).second));
    }
}
开发者ID:lfqt5,项目名称:FREEDM,代码行数:19,代码来源:CConnection.cpp


示例15: NetIoBuffer

bool NetSocket::PostRecv()
{
    _netStatus.fetch_or(NET_STATUS_RECV_PENDING);

    NetIoBuffer* recvOP = new NetIoBuffer(NetCompletionOP::OP_READ);
    recvOP->Reset(GetSocket());

    MemoryBlock* buffer = recvOP->Alloc(MAX_PACKET_SIZE);

    WSABUF wbuf;
    wbuf.buf = buffer->GetData();
    wbuf.len = buffer->GetDataLen();

    DWORD flags = 0;
    int rc = WSARecv(
        GetSocket(),
        &wbuf,
        1,
        NULL,
        &flags,
        &(recvOP->ol),
        NULL
    );

    if (rc == SOCKET_ERROR)
    {
        int error = WSAGetLastError();
        if (error != WSA_IO_PENDING)
        {
            delete recvOP;

            DebugPrint("PostRecv: WSARecv* failed: %s", SocketGetErrorString(error).c_str());
            Disconnect(NET_CTYPE_SYSTEM);

            return false;
        }
    }

    return true;
}
开发者ID:goopymoon,项目名称:RefLib,代码行数:40,代码来源:reflib_net_socket.cpp


示例16: GetSocket

bool LRTGroupSession::Connect(const std::string addr, int port)
{
    m_addr = addr;
    m_port = port;
    OS_Error err = GetSocket()->Connect(SocketUtils::ConvertStringToAddr(m_addr.c_str()), m_port);
    if (err == OS_NoErr || err == EISCONN) {
        m_connectingStatus = 1;
        return true;
    } else {
        LE("%s ERR:%d\n", __FUNCTION__, err);
        return false;
    }
}
开发者ID:BoYuanZjq,项目名称:Teameeting-MsgServer,代码行数:13,代码来源:LRTGroupSession.cpp


示例17: CreateConnection

void UdpSocket::DropMulticastMembership(const std::string& group, const std::string& local_if, int if_index)
{
	if (GetSocket() == INVALID_SOCKET)
	{
		CreateConnection();
	}
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
	if (IsIpv6())
	{
		struct ipv6_mreq x;
		struct in6_addr addr;
		if (Utility::u2ip( group, addr ))
		{
			x.ipv6mr_multiaddr = addr;
			x.ipv6mr_interface = if_index;
			if (setsockopt(GetSocket(), IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, (char *)&x, sizeof(struct ipv6_mreq)) == -1)
			{
				Handler().LogError(this, "DropMulticastMembership(ipv6)", Errno, StrError(Errno), LOG_LEVEL_WARNING);
			}
		}
		return;
	}
#endif
#endif
	struct ip_mreq x; // ip_mreqn
	ipaddr_t addr;
	if (Utility::u2ip( group, addr ))
	{
		memcpy(&x.imr_multiaddr.s_addr, &addr, sizeof(addr));
		Utility::u2ip( local_if, addr);
		memcpy(&x.imr_interface.s_addr, &addr, sizeof(addr));
//		x.imr_ifindex = if_index;
		if (setsockopt(GetSocket(), SOL_IP, IP_DROP_MEMBERSHIP, (char *)&x, sizeof(struct ip_mreq)) == -1)
		{
			Handler().LogError(this, "DropMulticastMembership(ipv4)", Errno, StrError(Errno), LOG_LEVEL_WARNING);
		}
	}
}
开发者ID:f059074251,项目名称:interested,代码行数:39,代码来源:UdpSocket.cpp


示例18: Handler

int SctpSocket::Open(SocketAddress& ad)
{
	if (!ad.IsValid())
	{
		Handler().LogError(this, "SctpSocket", -1, "invalid address", LOG_LEVEL_ERROR);
		return -1;
	}
	if (GetSocket() == INVALID_SOCKET)
	{
		Attach(CreateSocket(ad.GetFamily(), m_type, "sctp"));
	}
	if (GetSocket() != INVALID_SOCKET)
	{
		if (!SetNonblocking(true))
		{
			return -1;
		}
		int n = connect(GetSocket(), ad, ad);
		if (n == -1)
		{
			// check error code that means a connect is in progress
#ifdef _WIN32
			if (Errno == WSAEWOULDBLOCK)
#else
			if (Errno == EINPROGRESS)
#endif
			{
				Handler().LogError(this, "connect: connection pending", Errno, StrError(Errno), LOG_LEVEL_INFO);
				SetConnecting( true ); // this flag will control fd_set's
			}
			else
			{
				Handler().LogError(this, "SctpSocket", -1, "connect() failed", LOG_LEVEL_ERROR);
			}
		}
		return n;
	}
	return -1;
}
开发者ID:BornHunter,项目名称:CGSF,代码行数:39,代码来源:SctpSocket.cpp


示例19: sizeof

void PacketHandlerCL::HandleSelectServer(ServerSocketCL* socket
    , const void* data, int length) {
    const auto req = static_cast<const SelectServerCL*>(data);
    ::printf("SelectServer: userId[%lld] serverId[%d]\n", req->m_userId, req->m_serverId);

    SelectServerLC rsp;

    const auto userId = req->m_userId;
    User* user = UserManager::Instance().GetUser(userId);
    if (NS_MZ::IsNull(user)) {
        rsp.m_authCode = -1;
        socket->m_packeter.SendData(rsp.COMMAND, &rsp, sizeof(rsp));
        return;
    }

    const auto serverId = req->m_serverId;
    const auto serverGroup = g_serverApp->m_serverGroupManager.GetServerGroup(serverId);
    if (NS_MZ::IsNull(serverGroup)) {
        rsp.m_authCode = -2;
        socket->m_packeter.SendData(rsp.COMMAND, &rsp, sizeof(rsp));
        return;
    }

    const auto status = serverGroup->GetStatus();
    if (status == 0) {
        rsp.m_authCode = -3;
        socket->m_packeter.SendData(rsp.COMMAND, &rsp, sizeof(rsp));
        return;
    }

    const auto address = serverGroup->SelectRandomAddress();
    if (NS_MZ::IsNull(address)) {
        rsp.m_authCode = -4;
        socket->m_packeter.SendData(rsp.COMMAND, &rsp, sizeof(rsp));
        return;
    }

    static NS_MZ_SHARE::Random s_random;
    const auto authCode = s_random.GetRangeInt(1000000, 1000000000);

    rsp.m_authCode = authCode;
    rsp.m_address = *address;
    socket->m_packeter.SendData(rsp.COMMAND, &rsp, sizeof(rsp));

    UserCandidateLM reqLM;
    reqLM.m_userId = userId;
    reqLM.m_authCode = authCode;
    serverGroup->GetSocket()->m_packeter.SendData(reqLM.COMMAND, &reqLM, sizeof(reqLM));

    UserManager::Instance().RemoveUser(userId);
}
开发者ID:Metazion,项目名称:MetazionWorld,代码行数:51,代码来源:PacketHandlerCL.cpp


示例20: GetSocket

void ChatServerConnection::OnReceive(const char *pBuffer, uint32 nSize)
{
	if (pBuffer) {
		// Compose server message (we use the string copy constructor to ensure that there's a correct terminating zero)
		const String sMessage = GetSocket().GetSocketAddress().GetHost() + ": '" + String(pBuffer, true, nSize-1) + '\''; // -1 = excluding the terminating zero

		// Write the message into the log and start a new line
		System::GetInstance()->GetConsole().Print(sMessage + '\n');

		// Send message to all clients
		for (uint32 i=0; i<GetHost().GetConnections().GetNumOfElements(); i++)
			GetHost().GetConnections().Get(i)->Send(sMessage.GetASCII(), sMessage.GetLength()+1);	// +1 so we also send the terminating zero
	}
}
开发者ID:Tank-D,项目名称:potential-octo-dubstep,代码行数:14,代码来源:ChatServerConnection.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ GetSocketID函数代码示例发布时间:2022-05-30
下一篇:
C++ GetSockName函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap