Beispiel #1
0
BOOL 
CLpxStreamConnection::Connect(
	CONST SOCKADDR_LPX* pRemoteAddr, 
	CONST BYTE* lpSendBuffer, 
	DWORD dwSendDataLen, 
	LPDWORD lpcbSent)
{
	_ASSERTE(INVALID_SOCKET != m_sock);

	ResetSendOverlapped();

	LPFN_CONNECTEX lpfnConnectEx = NULL;
	GUID GuidConnectEx = WSAID_CONNECTEX;
	DWORD cbRead;
	INT iResult = ::WSAIoctl(m_sock, 
		SIO_GET_EXTENSION_FUNCTION_POINTER, 
		&GuidConnectEx, 
		sizeof(GuidConnectEx),
		&lpfnConnectEx, 
		sizeof(lpfnConnectEx), 
		&cbRead,
		NULL, 
		NULL);

	if (NULL == lpfnConnectEx) {
		XTLTRACE("Cannot load ConnectEx function, error=0x%X\n", GetLastError());
		return FALSE;
	}

	BOOL fSuccess = lpfnConnectEx(
		m_sock,
		(const sockaddr*) pRemoteAddr,
		sizeof(SOCKADDR_LPX),
		(PVOID) lpSendBuffer,
		dwSendDataLen,
		lpcbSent,
		&m_ovSend);

	if (fSuccess) {
		fSuccess = ::SetEvent(m_hSentEvent);
		_ASSERTE(fSuccess);
		return TRUE;
	}

	if (ERROR_IO_PENDING != ::WSAGetLastError()) {
		XTLTRACE("CLpxStreamConnection.ConnectEx failed, socket=%p, error=0x%X\n", 
			reinterpret_cast<PVOID>(m_sock), WSAGetLastError());
		return FALSE;
	}

	return TRUE;
}
Beispiel #2
0
BOOL
CLpxStreamConnection::Send(
	DWORD cbToSend, 
	CONST BYTE* lpbData,
	DWORD dwFlags /* = 0 */)
{
	_ASSERTE(INVALID_SOCKET != m_sock);

	BOOL fSuccess = FALSE;

	ResetSendOverlapped();

	m_wsaSendBuffer.len = cbToSend;
	m_wsaSendBuffer.buf = (char*) lpbData;

	DWORD cbSent = 0;
	INT iResult = ::WSASend(
		m_sock,
		&m_wsaSendBuffer, 1,
		&cbSent, dwFlags,
		&m_ovSend, NULL);

	if (0 != iResult && WSA_IO_PENDING != ::WSAGetLastError()) {
		DBGPRT_ERR_EX(_FT("Send at sock %p (%d bytes) failed: "),
			m_sock, cbToSend);
		return FALSE;
	}

	if (0 == iResult) {
		fSuccess = ::SetEvent(m_hSentEvent);
		_ASSERTE(fSuccess);
		return TRUE;
	}

	return TRUE;
}
Beispiel #3
0
BOOL
CLpxStreamConnection::Send(
	DWORD cbToSend, 
	CONST BYTE* lpbData,
	DWORD dwFlags /* = 0 */)
{
	_ASSERTE(INVALID_SOCKET != m_sock);

	BOOL fSuccess = FALSE;

	ResetSendOverlapped();

	m_wsaSendBuffer.len = cbToSend;
	m_wsaSendBuffer.buf = (char*) lpbData;

	DWORD cbSent = 0;
	INT iResult = ::WSASend(
		m_sock,
		&m_wsaSendBuffer, 1,
		&cbSent, dwFlags,
		&m_ovSend, NULL);

	if (0 != iResult && WSA_IO_PENDING != ::WSAGetLastError()) {
		XTLTRACE("CLpxStreamConnection.Send failed, bytes=%d, socket=%p, error=0x%X\n", 
			cbToSend, reinterpret_cast<PVOID>(m_sock), WSAGetLastError());
		return FALSE;
	}

	if (0 == iResult) {
		fSuccess = ::SetEvent(m_hSentEvent);
		_ASSERTE(fSuccess);
		return TRUE;
	}

	return TRUE;
}