本文整理汇总了C++中GetSocket函数的典型用法代码示例。如果您正苦于以下问题:C++ GetSocket函数的具体用法?C++ GetSocket怎么用?C++ GetSocket使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetSocket函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}
示例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");)
示例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));
}
示例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));
}
}
示例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;
}