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


C++ TranslateSocketError函数代码示例

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


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

示例1: TranslateSocketError

//------------------------------------------------------------------------------
//
// SetBlocking()
//
//------------------------------------------------------------------------------
bool TDSocket::SetBlocking(void)
{
	i32 nCurFlags;

#if WIN32
	nCurFlags = 0;

	if (ioctlsocket(m_socket, FIONBIO, (ULONG *)&nCurFlags) != 0)
	{
		return false;
	}
#else
	if ((nCurFlags = fcntl(m_socket, F_GETFL)) < 0)
	{
		TranslateSocketError();
		return false;
	}

	nCurFlags &= (~O_NONBLOCK);

	if (fcntl(m_socket, F_SETFL, nCurFlags) != 0)
	{
		TranslateSocketError();
		return false;
	}
#endif
	m_bIsBlocking = true;

	return true;
}
开发者ID:DiaosiDev,项目名称:tdengine_cocos2dx_demo,代码行数:35,代码来源:TDSocket.cpp

示例2: TranslateSocketError

//------------------------------------------------------------------------------
//
// SetNonblocking()
//
//------------------------------------------------------------------------------
bool CSimpleSocket::SetNonblocking(void)
{
    int32  nCurFlags;

#if WIN32
    nCurFlags = 1;

    if (ioctlsocket(m_socket, FIONBIO, (ULONG *)&nCurFlags) != 0)
    {
        TranslateSocketError();
        return false;
    }
#else
    if ((nCurFlags = fcntl(m_socket, F_GETFL)) < 0)
    {
        TranslateSocketError();
        return false;
    }

    nCurFlags |= O_NONBLOCK;

    if (fcntl(m_socket, F_SETFL, nCurFlags) != 0)
    {
        TranslateSocketError();
        return false;
    }
#endif

    m_bIsBlocking = false;

    return true;
}
开发者ID:CozaNostra,项目名称:objectscript,代码行数:37,代码来源:SimpleSocket.cpp

示例3: memset

//------------------------------------------------------------------------------
//
// ConnectUDP() -
//
//------------------------------------------------------------------------------
bool CActiveSocket::ConnectUDP(const char *pAddr, uint16 nPort)
{
    bool           bRetVal = false;
    struct in_addr stIpAddress;

    //------------------------------------------------------------------
    // Pre-connection setup that must be preformed
    //------------------------------------------------------------------
    memset(&m_stServerSockaddr, 0, sizeof(m_stServerSockaddr));
    m_stServerSockaddr.sin_family = AF_INET;

    if ((m_pHE = GETHOSTBYNAME(pAddr)) == NULL)
    {
#ifdef WIN32
        TranslateSocketError();
#else
        if (h_errno == HOST_NOT_FOUND)
        {
            SetSocketError(SocketInvalidAddress);
        }
#endif
        return bRetVal;
    }

    memcpy(&stIpAddress, m_pHE->h_addr_list[0], m_pHE->h_length);
    m_stServerSockaddr.sin_addr.s_addr = stIpAddress.s_addr;

    if ((int32)m_stServerSockaddr.sin_addr.s_addr == CSimpleSocket::SocketError)
    {
        TranslateSocketError();
        return bRetVal;
    }

    m_stServerSockaddr.sin_port = htons(nPort);

    //------------------------------------------------------------------
    // Connect to address "xxx.xxx.xxx.xxx"    (IPv4) address only.
    //
    //------------------------------------------------------------------
    m_timer.Initialize();
    m_timer.SetStartTime();

    if (connect(m_socket, (struct sockaddr*)&m_stServerSockaddr, sizeof(m_stServerSockaddr)) != CSimpleSocket::SocketError)
    {
        bRetVal = true;
    }

    TranslateSocketError();

    m_timer.SetEndTime();

    return bRetVal;
}
开发者ID:AndrewMeadows,项目名称:bullet3,代码行数:58,代码来源:ActiveSocket.cpp

示例4: memset

//------------------------------------------------------------------------------
//
// ConnectRAW() -
//
//------------------------------------------------------------------------------
bool TDSocket::ConnectRAW(const char *pAddr, i16 nPort)
{
	bool           bRetVal = false;
	struct in_addr stIpAddress;
	//------------------------------------------------------------------
	// Pre-connection setup that must be preformed					 
	//------------------------------------------------------------------
	memset(&m_stServerSockaddr, 0, sizeof(m_stServerSockaddr));
	m_stServerSockaddr.sin_family = AF_INET;

	hostent * pHE = NULL;
	if ((pHE = GETHOSTBYNAME(pAddr)) == NULL)
	{
#ifdef WIN32
		TranslateSocketError();
#else
		if (h_errno == HOST_NOT_FOUND)
		{
			SetSocketError(SocketInvalidAddress);
		}
#endif
		return bRetVal;
	}

	memcpy(&stIpAddress, pHE->h_addr_list[0], pHE->h_length);
	m_stServerSockaddr.sin_addr.s_addr = stIpAddress.s_addr;

	if ((i32)m_stServerSockaddr.sin_addr.s_addr == TDSocket::SocketError)
	{
		TranslateSocketError();
		return bRetVal;
	}

	m_stServerSockaddr.sin_port = htons(nPort);

	//------------------------------------------------------------------
	// Connect to address "xxx.xxx.xxx.xxx"	(IPv4) address only.  
	// 
	//------------------------------------------------------------------

	if (connect(m_socket, (struct sockaddr*)&m_stServerSockaddr, sizeof(m_stServerSockaddr)) != TDSocket::SocketError)
	{
		bRetVal = true;
	}

	TranslateSocketError();


	return bRetVal;
}
开发者ID:DiaosiDev,项目名称:tdengine_cocos2dx_demo,代码行数:55,代码来源:TDSocket.cpp

示例5: sizeof

//------------------------------------------------------------------------------
//
// SetReceiveTimeout()
//
//------------------------------------------------------------------------------
bool TDSocket::SetReceiveTimeout(i32 nRecvTimeoutSec, i32 nRecvTimeoutUsec)
{
	bool bRetVal = true;

	void* ptimeout = NULL;
#if WIN32
	int timeout = nRecvTimeoutSec * 1000 + nRecvTimeoutUsec / 1000;
	ptimeout = &timeout;
#else
	m_stRecvTimeout.tv_sec = nRecvTimeoutSec;
	m_stRecvTimeout.tv_usec = nRecvTimeoutUsec;
	ptimeout = &m_stRecvTimeout;
#endif
	//--------------------------------------------------------------------------
	// Sanity check to make sure the options are supported!					
	//--------------------------------------------------------------------------
	if (SETSOCKOPT(m_socket, SOL_SOCKET, SO_RCVTIMEO, ptimeout,
		sizeof(struct timeval)) == TDSocket::SocketError)
	{
		bRetVal = false;
		TranslateSocketError();
	}

	return bRetVal;
}
开发者ID:DiaosiDev,项目名称:tdengine_cocos2dx_demo,代码行数:30,代码来源:TDSocket.cpp

示例6: while

//------------------------------------------------------------------------------
//
// SendFile() - stands-in for system provided sendfile				
//
//------------------------------------------------------------------------------
i32 TDSocket::SendFile(i32 nOutFd, i32 nInFd, off_t *pOffset, i32 nCount)
{
	i32  nOutCount = TDSocket::SocketError;

	static char szData[SOCKET_SENDFILE_BLOCKSIZE];
	i32       nInCount = 0;

	if (LSEEK(nInFd, *pOffset, SEEK_SET) == -1)
	{
		return -1;
	}

	while (nOutCount < nCount)
	{
		nInCount = (nCount - nOutCount) < SOCKET_SENDFILE_BLOCKSIZE ? (nCount - nOutCount) : SOCKET_SENDFILE_BLOCKSIZE;

		if ((READ(nInFd, szData, nInCount)) != (i32)nInCount)
		{
			return -1;
		}

		if ((SEND(nOutFd, szData, nInCount, 0)) != (i32)nInCount)
		{
			return -1;
		}

		nOutCount += nInCount;
	}

	*pOffset += nOutCount;

	TranslateSocketError();

	return nOutCount;
}
开发者ID:DiaosiDev,项目名称:tdengine_cocos2dx_demo,代码行数:40,代码来源:TDSocket.cpp

示例7: SetSocketError

//------------------------------------------------------------------------------
//
// Send() - Send data on a valid socket
//
//------------------------------------------------------------------------------
int32 CPassiveSocket::Send(const uint8 *pBuf, size_t bytesToSend)
{
    SetSocketError(SocketSuccess);
    m_nBytesSent = 0;

    switch(m_nSocketType)
    {
       case CSimpleSocket::SocketTypeUdp:
        {
            if (IsSocketValid())
            {
                if ((bytesToSend > 0) && (pBuf != NULL))
                {
                    m_timer.Initialize();
                    m_timer.SetStartTime();

                    m_nBytesSent = SENDTO(m_socket, pBuf, bytesToSend, 0, (const sockaddr *)&m_stClientSockaddr, sizeof(m_stClientSockaddr));

                    m_timer.SetEndTime();

                    if (m_nBytesSent == CSimpleSocket::SocketError)
                    {
                        TranslateSocketError();
                    }
                }
            }
            break;
        }
       default:
           CSimpleSocket::Send(pBuf, bytesToSend);
           break;
    }

    return m_nBytesSent;
}
开发者ID:karate362,项目名称:RoboNavi,代码行数:40,代码来源:PassiveSocket.cpp

示例8: FD_ZERO

//------------------------------------------------------------------------------
//
// Select()
//
//------------------------------------------------------------------------------
bool TDSocket::Select(i32 nTimeoutSec, i32 nTimeoutUSec)
{
	bool            bRetVal = false;
	struct timeval *pTimeout = NULL;
	struct timeval  timeout;
	i32           nNumDescriptors = -1;
	i32           nError = 0;

	FD_ZERO(&m_errorFds);
	FD_ZERO(&m_readFds);
	FD_ZERO(&m_writeFds);
	FD_SET(m_socket, &m_errorFds);
	FD_SET(m_socket, &m_readFds);
	FD_SET(m_socket, &m_writeFds);

	//---------------------------------------------------------------------
	// If timeout has been specified then set value, otherwise set timeout
	// to NULL which will block until a descriptor is ready for read/write
	// or an error has occurred.
	//---------------------------------------------------------------------
	if ((nTimeoutSec >= 0) || (nTimeoutUSec >= 0))
	{
		timeout.tv_sec = nTimeoutSec;
		timeout.tv_usec = nTimeoutUSec;
		pTimeout = &timeout;
	}

	nNumDescriptors = SELECT(m_socket + 1, &m_readFds, &m_writeFds, &m_errorFds, pTimeout);
	//    nNumDescriptors = SELECT(m_socket+1, &m_readFds, NULL, NULL, pTimeout);

	//----------------------------------------------------------------------
	// Handle timeout
	//----------------------------------------------------------------------
	if (nNumDescriptors == 0)
	{
		SetSocketError(TDSocket::SocketTimedout);
	}
	//----------------------------------------------------------------------
	// If a file descriptor (read/write) is set then check the
	// socket error (SO_ERROR) to see if there is a pending error.
	//----------------------------------------------------------------------
	else if ((FD_ISSET(m_socket, &m_readFds)) || (FD_ISSET(m_socket, &m_writeFds)))
	{
		i32 nLen = sizeof(nError);

		if (GETSOCKOPT(m_socket, SOL_SOCKET, SO_ERROR, &nError, &nLen) == 0)
		{
			errno = nError;

			if (nError == 0)
			{
				bRetVal = true;
			}
		}

		TranslateSocketError();
	}

	return bRetVal;
}
开发者ID:DiaosiDev,项目名称:tdengine_cocos2dx_demo,代码行数:65,代码来源:TDSocket.cpp

示例9: SetSocketError

//------------------------------------------------------------------------------
//
// Send() - Send data on a valid socket via a vector of buffers.
//
//------------------------------------------------------------------------------
i32 TDSocket::Send(const struct iovec *sendVector, i32 nNumItems)
{
	SetSocketError(SocketSuccess);
	m_nBytesSent = 0;

	if ((m_nBytesSent = WRITEV(m_socket, sendVector, nNumItems)) == TDSocket::SocketError)
	{
		TranslateSocketError();
	}

	return m_nBytesSent;
}
开发者ID:DiaosiDev,项目名称:tdengine_cocos2dx_demo,代码行数:17,代码来源:TDSocket.cpp

示例10: pgwin32_recv

int
pgwin32_recv(SOCKET s, char *buf, int len, int f)
{
	WSABUF		wbuf;
	int			r;
	DWORD		b;
	DWORD		flags = f;

	if (pgwin32_poll_signals())
		return -1;

	wbuf.len = len;
	wbuf.buf = buf;

	r = WSARecv(s, &wbuf, 1, &b, &flags, NULL, NULL);
	if (r != SOCKET_ERROR && b > 0)
		/* Read succeeded right away */
		return b;

	if (r == SOCKET_ERROR &&
		WSAGetLastError() != WSAEWOULDBLOCK)
	{
		TranslateSocketError();
		return -1;
	}

	/* No error, zero bytes (win2000+) or error+WSAEWOULDBLOCK (<=nt4) */

	if (pgwin32_waitforsinglesocket(s, FD_READ | FD_CLOSE | FD_ACCEPT,
									INFINITE) == 0)
		return -1;

	r = WSARecv(s, &wbuf, 1, &b, &flags, NULL, NULL);
	if (r == SOCKET_ERROR)
	{
		TranslateSocketError();
		return -1;
	}
	return b;
}
开发者ID:berkeley-cs186,项目名称:course-fa07,代码行数:40,代码来源:socket.c

示例11: pgwin32_socket

/*
 * Create a socket, setting it to overlapped and non-blocking
 */
SOCKET
pgwin32_socket(int af, int type, int protocol)
{
	SOCKET		s;
	unsigned long on = 1;

	s = WSASocket(af, type, protocol, NULL, 0, WSA_FLAG_OVERLAPPED);
	if (s == INVALID_SOCKET)
	{
		TranslateSocketError();
		return INVALID_SOCKET;
	}

	if (ioctlsocket(s, FIONBIO, &on))
	{
		TranslateSocketError();
		return INVALID_SOCKET;
	}
	errno = 0;

	return s;
}
开发者ID:FilipinOTech,项目名称:postgres,代码行数:25,代码来源:socket.c

示例12: SetSocketError

//------------------------------------------------------------------------------
//
// Accept() - 
//
//------------------------------------------------------------------------------
CActiveSocket *CPassiveSocket::Accept(uint32_t timeout_sec)
{
    uint32_t         nSockLen;
	std::auto_ptr<CActiveSocket> ClientSocket;
    SOCKET         socket = CSimpleSocket::SocketError;

    if (m_nSocketType != CSimpleSocket::SocketTypeTcp) {
        SetSocketError(CSimpleSocket::SocketProtocolError);
        return 0;
    }

    ClientSocket.reset (new CActiveSocket(m_compress_, m_nSocketType));

    //--------------------------------------------------------------------------
    // Wait for incoming connection.
    //--------------------------------------------------------------------------
    CSocketError socketErrno = SocketSuccess;
    nSockLen = sizeof(m_stClientSockaddr);
    do {
        errno = 0;
		if (!Select (timeout_sec, 0))
			return 0;

		socket = accept(m_socket, (struct sockaddr *)&m_stClientSockaddr, (socklen_t *)&nSockLen);
        if (socket != -1) {
            ClientSocket->SetSocketHandle(socket);
            ClientSocket->TranslateSocketError();
            socketErrno = ClientSocket->GetSocketError();
            socklen_t nSockLen = sizeof(struct sockaddr);

            //-------------------------------------------------------------
            // Store client and server IP and port information for this
            // connection.
            //-------------------------------------------------------------
            getpeername(m_socket, (struct sockaddr *)&ClientSocket->m_stClientSockaddr, &nSockLen);
            memcpy((void *)&ClientSocket->m_stClientSockaddr, (void *)&m_stClientSockaddr, nSockLen);

            memset(&ClientSocket->m_stServerSockaddr, 0, nSockLen);
            getsockname(m_socket, (struct sockaddr *)&ClientSocket->m_stServerSockaddr, &nSockLen);
        }
        else {
            TranslateSocketError();
            socketErrno = GetSocketError();
        }
    } while (socketErrno == CSimpleSocket::SocketInterrupted);
    
    if (socketErrno != CSimpleSocket::SocketSuccess)
		return 0;

	return ClientSocket.release ();
}
开发者ID:ApusApp,项目名称:xdeltalib,代码行数:56,代码来源:passive_socket.cpp

示例13: pgwin32_send

int
pgwin32_send(SOCKET s, char *buf, int len, int flags)
{
	WSABUF		wbuf;
	int			r;
	DWORD		b;

	if (pgwin32_poll_signals())
		return -1;

	wbuf.len = len;
	wbuf.buf = buf;

	r = WSASend(s, &wbuf, 1, &b, flags, NULL, NULL);
	if (r != SOCKET_ERROR && b > 0)
		/* Write succeeded right away */
		return b;

	if (r == SOCKET_ERROR &&
		WSAGetLastError() != WSAEWOULDBLOCK)
	{
		TranslateSocketError();
		return -1;
	}

	/* No error, zero bytes (win2000+) or error+WSAEWOULDBLOCK (<=nt4) */

	if (pgwin32_waitforsinglesocket(s, FD_WRITE | FD_CLOSE) == 0)
		return -1;

	r = WSASend(s, &wbuf, 1, &b, flags, NULL, NULL);
	if (r == SOCKET_ERROR)
	{
		TranslateSocketError();
		return -1;
	}
	return b;
}
开发者ID:alecclarke,项目名称:postgresql-8.1.4,代码行数:38,代码来源:socket.c

示例14: pgwin32_send

int
pgwin32_send(SOCKET s, const void *buf, int len, int flags)
{
	WSABUF		wbuf;
	int			r;
	DWORD		b;

	if (pgwin32_poll_signals())
		return -1;

	wbuf.len = len;
	wbuf.buf = (char *) buf;

	/*
	 * Readiness of socket to send data to UDP socket may be not true: socket
	 * can become busy again! So loop until send or error occurs.
	 */
	for (;;)
	{
		r = WSASend(s, &wbuf, 1, &b, flags, NULL, NULL);
		if (r != SOCKET_ERROR && b > 0)
			/* Write succeeded right away */
			return b;

		if (r == SOCKET_ERROR &&
			WSAGetLastError() != WSAEWOULDBLOCK)
		{
			TranslateSocketError();
			return -1;
		}

		if (pgwin32_noblock)
		{
			/*
			 * No data sent, and we are in "emulated non-blocking mode", so
			 * return indicating that we'd block if we were to continue.
			 */
			errno = EWOULDBLOCK;
			return -1;
		}

		/* No error, zero bytes (win2000+) or error+WSAEWOULDBLOCK (<=nt4) */

		if (pgwin32_waitforsinglesocket(s, FD_WRITE | FD_CLOSE, INFINITE) == 0)
			return -1;
	}

	return -1;
}
开发者ID:FilipinOTech,项目名称:postgres,代码行数:49,代码来源:socket.c

示例15: pgwin32_accept

SOCKET
pgwin32_accept(SOCKET s, struct sockaddr * addr, int *addrlen)
{
	SOCKET		rs;

	/*
	 * Poll for signals, but don't return with EINTR, since we don't handle
	 * that in pqcomm.c
	 */
	pgwin32_poll_signals();

	rs = WSAAccept(s, addr, addrlen, NULL, 0);
	if (rs == INVALID_SOCKET)
	{
		TranslateSocketError();
		return INVALID_SOCKET;
	}
	return rs;
}
开发者ID:FilipinOTech,项目名称:postgres,代码行数:19,代码来源:socket.c


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