Ejemplo n.º 1
0
BOOL
CNdasEventMonitor::Initialize()
{
	//
	// Initialize routine is reentrant one.
	//

	//
	// Auto-reset waitable timer
	//
	if (INVALID_HANDLE_VALUE == m_hHeartbeatMonitorTimer) {
		m_hHeartbeatMonitorTimer = ::CreateWaitableTimer(NULL, FALSE, NULL);
	}

	if (INVALID_HANDLE_VALUE == m_hHeartbeatMonitorTimer) {
		DBGPRT_ERR_EX(_FT("Timer creation failed: "));
		return FALSE;
	}

	if (NULL == m_hLogDeviceSetChangeEvent) {
		m_hLogDeviceSetChangeEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
	}

	if (NULL == m_hLogDeviceSetChangeEvent) {
		DBGPRT_ERR_EX(_FT("Logical device set change event creation failed: "));
		return FALSE;
	}

	return CTask::Initialize();
}
Ejemplo n.º 2
0
BOOL
CNdasEventPublisher::AcceptNewConnection()
{
	CLIENT_DATA* pClientData = NULL;

	pClientData = new CLIENT_DATA;
	::ZeroMemory(pClientData, sizeof(CLIENT_DATA));

	if (NULL == pClientData) {
		DBGPRT_ERR_EX(_FT("Out of memory: "));
		return FALSE;
	}

	pClientData->overlapped.hEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
	if (NULL == pClientData->overlapped.hEvent) {
		// Unable to create an event
		DBGPRT_ERR_EX(_FT("Creating an event failed: "));
		delete pClientData;
		return FALSE;
	}

	pClientData->hPipe = CreatePipeInstance(&pClientData->overlapped);
	if (INVALID_HANDLE_VALUE == pClientData->hPipe) {
		// Unable to create a pipe instance
		DBGPRT_ERR_EX(_FT("Creating the pipe instance failed: "));
		::CloseHandle(pClientData->overlapped.hEvent);
		pClientData->overlapped.hEvent = NULL;
		delete pClientData;
		return FALSE;
	}

	m_PipeData.push_back(pClientData);

	return TRUE;
}
Ejemplo n.º 3
0
DWORD
CNdasIXServer::OnTaskStart()
{
	DBGPRT_INFO(_FT("Starting NdasIXServer.\n"));

	CLpxDatagramServer m_dgs;
	BOOL fSuccess = m_dgs.Initialize();
	if (!fSuccess) {
		DBGPRT_ERR_EX(_FT("CNdasIXServer init failed: "));
		return 255;
	}

	fSuccess = m_dgs.Receive(
		this,
		m_usListenPort,
		INFOX_MAX_DATAGRAM_PKT_SIZE,
		m_hTaskTerminateEvent);

	if (!fSuccess) {
		DBGPRT_ERR_EX(_FT("Listening IXServer at port %d failed: "), m_usListenPort);
		return 255;
	}

	return 0;
}
Ejemplo n.º 4
0
BOOL
CLpxStreamListener::GetAcceptResult(
	OUT SOCKADDR_LPX* lpLocalAddr,
	OUT SOCKADDR_LPX* lpRemoteAddr, 
	OUT LPDWORD lpcbReceived, 
	OUT CONST BYTE** ppbData, 
	OUT LPDWORD lpdwFlags /* = NULL */)
{
	BOOL fSuccess = ::WSAGetOverlappedResult(
		m_sock,
		&m_ovReceive,
		lpcbReceived,
		TRUE,
		lpdwFlags);

	if (!fSuccess) {
		DBGPRT_ERR_EX(_FT("WSAGetOverlappedResult failed: "));
		return FALSE;
	}

	*ppbData = (CONST BYTE*) m_wsaReceiveBuffer.buf;

	SOCKADDR_LPX *pLocalAddr, *pRemoteAddr;
	INT iLocalAddrLen, iRemoteAddrLen;

	LPFN_GETACCEPTEXSOCKADDRS lpfnAcceptExSockaddrs = NULL;
	GUID GuidAcceptExSockaddrs = WSAID_GETACCEPTEXSOCKADDRS;
	DWORD cbRead;
	INT iResult = ::WSAIoctl(m_sock, 
		SIO_GET_EXTENSION_FUNCTION_POINTER, 
		&GuidAcceptExSockaddrs, 
		sizeof(GuidAcceptExSockaddrs),
		&lpfnAcceptExSockaddrs, 
		sizeof(lpfnAcceptExSockaddrs), 
		&cbRead,
		NULL, 
		NULL);

	if (NULL == lpfnAcceptExSockaddrs) {
		DBGPRT_ERR_EX(_FT("Cannot load AcceptEx function: "));
		return FALSE;
	}

	lpfnAcceptExSockaddrs(
		m_wsaReceiveBuffer.buf, 
		m_wsaReceiveBuffer.len,
		sizeof(SOCKADDR_LPX) + 16,
		sizeof(SOCKADDR_LPX) + 16,
		(sockaddr**) &pLocalAddr,
		&iLocalAddrLen,
		(sockaddr**) &pRemoteAddr,
		&iRemoteAddrLen);

	*lpLocalAddr = *pLocalAddr;
	*lpRemoteAddr = *pRemoteAddr;

	return TRUE;
}
Ejemplo n.º 5
0
BOOL 
WINAPI
NdasDmGetVolumeNumberOfDriveLetter(int drvno, ULONG *vol) 
{
	BOOL	bret = FALSE ;
	HANDLE	volMgr ;
	TCHAR	volName[] = _T("\\\\.\\A:") ;
	VOLUME_NUMBER VN ;
	ULONG	retsz ;

	//
	//	fix volume name
	//
	volName[4] += (TCHAR)drvno ;
	DBGPRT_INFO(_FT("DOS device name: %s\n"), volName);

	//
	//	open the volume manager
	//
	volMgr = CreateFile(volName,
		GENERIC_READ |  GENERIC_WRITE,
		FILE_SHARE_READ | FILE_SHARE_WRITE,
		NULL,
		OPEN_EXISTING,
		FILE_ATTRIBUTE_NORMAL,
		NULL) ;
	if(volMgr == INVALID_HANDLE_VALUE) {
		DBGPRT_ERR_EX(_FT("CreateFile(%s) failed: "), volName);
		return FALSE ;
	}


	bret = DeviceIoControl(
		volMgr, 
		IOCTL_VOLUME_QUERY_VOLUME_NUMBER, 
		NULL,                           // lpInBuffer
		0,								// size of input buffer
		(LPVOID) &VN,                   // output buffer
		(DWORD) sizeof(VN),             // size of output buffer
		&retsz,							// number of bytes returned
		NULL							// OVERLAPPED structure
		) ;
	if(bret == FALSE) {
		DBGPRT_ERR_EX(_FT("DeviceIoControl(IOCTL_VOLUME_QUERY_VOLUME_NUMBER) failed: "));
		goto cleanup ;
	}

	DBGPRT_INFO(_FT("Volume Number:%d\n"), VN.VolumeNumber );
	DBGPRT_INFO(_FT("Volume Manager Name:%ws\n"), VN.VolumeManagerName );
	*vol = VN.VolumeNumber ;

cleanup:
	if(volMgr != 0 && volMgr != INVALID_HANDLE_VALUE) CloseHandle(volMgr) ;

	return bret ;
}
Ejemplo n.º 6
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) {
		DBGPRT_ERR_EX(_FT("Cannot load ConnectEx function: "));
		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()) {
		DBGPRT_ERR_EX(_FT("ConnectEx at sock %p failed: "), m_sock);
		return FALSE;
	}

	return TRUE;
}
Ejemplo n.º 7
0
BOOL GetLocalLpxAddressList(
	IN SOCKET s,
	IN DWORD cbBuffer,
	OUT LPSOCKET_ADDRESS_LIST lpBuffer,
	OUT LPDWORD pcbBytesReturned)
{
	_ASSERTE(INVALID_SOCKET != s);
	_ASSERTE(!IsBadWritePtr(lpBuffer, cbBuffer));

	INT iError = WSAIoctl(
		s,
		SIO_ADDRESS_LIST_QUERY,
		NULL, 
		0,
		lpBuffer,
		cbBuffer,
		pcbBytesReturned,
		NULL,
		NULL);

	if (iError != 0) {
		DBGPRT_ERR_EX(_FT("SIO_ADDRESS_LIST_QUERY failed: "));
		return FALSE;
	}

	return TRUE;
}
Ejemplo n.º 8
0
BOOL
CLpxAsyncSocket::_GetRecvResult( 
	OUT LPDWORD lpcbReceived, 
	OUT BYTE** ppbData, 
	OUT LPDWORD lpdwFlags /* = NULL */)
{
	DWORD cbReceived = 0;
	DWORD dwFlags = 0;

	BOOL fSuccess = ::WSAGetOverlappedResult(
		m_sock,
		&m_ovReceive,
		&cbReceived,
		TRUE,
		&dwFlags);
	
	if (!fSuccess)
	{
		DBGPRT_ERR_EX(_FT("WSAGetOverlappedResult failed: "));
		return FALSE;
	}

	*ppbData = (BYTE*)m_wsaReceiveBuffer.buf;
	if (lpcbReceived) *lpcbReceived = cbReceived;
	if (lpdwFlags) *lpdwFlags = dwFlags;

	return TRUE;
}
Ejemplo n.º 9
0
BOOL 
CLpxAsyncSocket::AllocRecvBuf(DWORD cbSize)
{
	if (cbSize > m_wsaReceiveBuffer.len) {

		if (NULL != m_wsaReceiveBuffer.buf) {
			m_wsaReceiveBuffer.buf = (char*) ::HeapReAlloc(
				::GetProcessHeap(),
				HEAP_ZERO_MEMORY,
				m_wsaReceiveBuffer.buf,
				cbSize);
		} else {
			m_wsaReceiveBuffer.buf = (char*) ::HeapAlloc(
				::GetProcessHeap(),
				HEAP_ZERO_MEMORY,
				cbSize);
		}

		if (NULL == m_wsaReceiveBuffer.buf) {
			DBGPRT_ERR_EX(_FT("Allocating RecvBuf %d bytes failed: "), cbSize);
			m_wsaReceiveBuffer.len = 0;
			return FALSE;
		}

		m_wsaReceiveBuffer.len = cbSize;
	}

	return TRUE;
}
Ejemplo n.º 10
0
BOOL
CNdasLogicalDevice::Unplug()
{
	BOOL fSuccess(FALSE);

	ximeta::CAutoLock autolock(this);

	DBGPRT_INFO(_FT("Unplugging %s\n"), ToString());

	if (m_status == NDAS_LOGICALDEVICE_STATUS_NOT_INITIALIZED) 
	{
		::SetLastError(NDASHLPSVC_ERROR_NDAS_LOGICALDEVICE_NOT_INITIALIZED);
		return FALSE;
	}

	if (m_status != NDAS_LOGICALDEVICE_STATUS_MOUNTED &&
		m_status != NDAS_LOGICALDEVICE_STATUS_MOUNT_PENDING &&
		m_status != NDAS_LOGICALDEVICE_STATUS_UNMOUNT_PENDING) 
	{
		::SetLastError(NDASHLPSVC_ERROR_NDAS_LOGICALDEVICE_NOT_MOUNTED);
		return FALSE;
	}

	//
	// Remove target ejects the disk and the volume.
	//

	fSuccess = LsBusCtlRemoveTarget(m_NdasScsiLocation.SlotNo);
	if (!fSuccess) {
		DBGPRT_WARN_EX(_FT("LsBusCtlRemoveTarget failed: "));
	}

	// Intentional break
	::Sleep(100);

	//
	// BUG:
	// What happened when RemoveTarget succeeded and 
	// Unplugging LANSCSI port is failed?
	//

	fSuccess = LsBusCtlUnplug(m_NdasScsiLocation.SlotNo);
	if (!fSuccess) 
	{
		DBGPRT_ERR_EX(_FT("LsBusCtlUnplug failed: "));
		// last error from lsbusctl unplug
		return FALSE;
	}

	//
	// Change the status to unmounted
	//
	SetStatus(NDAS_LOGICALDEVICE_STATUS_UNMOUNTED);

	DBGPRT_INFO(_FT("Unplugged successfully at slot %s.\n"),
		CNdasScsiLocation(m_NdasScsiLocation).ToString());

	return TRUE;

}
Ejemplo n.º 11
0
BOOL
CNdasEventPublisher::SendVersionInfo(HANDLE hPipe, LPOVERLAPPED lpOverlapped)
{
	const DWORD cbMessage = sizeof(NDAS_EVENT_MESSAGE);
	NDAS_EVENT_MESSAGE msgVersion = {0};

	msgVersion.MessageSize = cbMessage;
	msgVersion.EventType = NDAS_EVENT_TYPE_VERSION_INFO;
	msgVersion.VersionInfo.MajorVersion = NDAS_EVENT_VERSION_MAJOR;
	msgVersion.VersionInfo.MinorVersion = NDAS_EVENT_VERSION_MINOR;

	DWORD cbWritten(0);
	
	BOOL fSuccess = ::WriteFile(
		hPipe, 
		&msgVersion,
		cbMessage,
		&cbWritten,
		lpOverlapped);

	if (!fSuccess && ERROR_IO_PENDING != ::GetLastError()) {
		DBGPRT_ERR_EX(_FT("Writing an initial version event failed: "));
		return FALSE;
	}

	return TRUE;
}
Ejemplo n.º 12
0
BOOL 
WINAPI
NdasDmGetScsiPortNumberOfDisk(
	IN DWORD dwPhysicalDiskNumber, 
	OUT LPDWORD lpdwScsiPortNumber)
{
	_ASSERTE(!IsBadWritePtr(lpdwScsiPortNumber, sizeof(DWORD)));

	//
	//	make up Physical Drive Name
	//

	TCHAR szDiskDevicePath[_MAX_PATH + 1];

	HRESULT hr = ::StringCchPrintf(
		szDiskDevicePath, 
		_MAX_PATH + 1, 
		_T("\\\\.\\PHYSICALDRIVE%d"),
		dwPhysicalDiskNumber);

	_ASSERT(SUCCEEDED(hr));

	DBGPRT_INFO(_FT("Disk Device Path:%s\n"), szDiskDevicePath);

	//
	//	open the disk device
	//

	DBGPRT_TRACE(_FT("CreateFile(%s)\n"), szDiskDevicePath);

	HANDLE hDisk = ::CreateFile(
		szDiskDevicePath,
        GENERIC_READ |  GENERIC_WRITE,
		FILE_SHARE_READ | FILE_SHARE_WRITE,
		NULL,
		OPEN_EXISTING,
		FILE_ATTRIBUTE_NORMAL,
		NULL);

	if (INVALID_HANDLE_VALUE == hDisk) {
		DBGPRT_ERR_EX(_FT("CreateFile(%s) failed: "), szDiskDevicePath);
		return FALSE;
	}

	//
	// Get SCSI Port Number of the Disk
	//

	BOOL fSuccess = NdasDmGetScsiPortNumberOfDisk(hDisk, lpdwScsiPortNumber);
	if (!fSuccess) {
		DBGPRT_ERR(_FT("NdasDmGetScsiPortNumberOfDisk(%s) failed.\n"),
			szDiskDevicePath);
		(VOID) ::CloseHandle(hDisk);
		return FALSE;
	}

	(VOID) ::CloseHandle(hDisk);
	return TRUE;
}
Ejemplo n.º 13
0
BOOL
CNdasLogicalDevice::Initialize()
{
	ximeta::CAutoLock autolock(this);

	if (NDAS_LOGICALDEVICE_STATUS_NOT_INITIALIZED != m_status) {
		// Already initialized
		return TRUE;
	}

	if (NULL == m_hDisconnectedEvent) {
		m_hDisconnectedEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
		if (NULL == m_hDisconnectedEvent) {
			DBGPRT_ERR_EX(_FT("Disconnect event creation failed: "));
			return FALSE;
		}
	}

	if (NULL == m_hAlarmEvent) {
		m_hAlarmEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
		if (NULL == m_hAlarmEvent) {
			DBGPRT_ERR_EX(_FT("Alarm event creation failed: "));
			::CloseHandle(m_hDisconnectedEvent);
			return FALSE;
		}
	}

	ACCESS_MASK lastMountAccess = GetLastMountAccess();

	BOOL fRiskyMountFlag = GetRiskyMountFlag();

	if (fRiskyMountFlag) {
		m_fRiskyMount = fRiskyMountFlag;
	}

	if ((lastMountAccess > 0) && !IsRiskyMount()) {
		SetMountOnReady(lastMountAccess, FALSE);
	}

	SetStatus(NDAS_LOGICALDEVICE_STATUS_UNMOUNTED);

	DBGPRT_INFO(_FT("Logical Device %d initialized successfully.\n"), m_logicalDeviceId);

	return TRUE;
}
Ejemplo n.º 14
0
BOOL
CNdasDevice::InvalidateUnitDevice(DWORD dwUnitNo)
{
	ximeta::CAutoLock autoLock(this);

	DBGPRT_INFO(_FT("%s: Invalidating Unit Device %d\n"), ToString(), dwUnitNo);

	if (dwUnitNo >= MAX_NDAS_UNITDEVICE_COUNT) 
	{
		DBGPRT_INFO(_T("%s: Invalid Unit No: %d\n"), ToString(), dwUnitNo);
		::SetLastError(ERROR_INVALID_PARAMETER);
		return FALSE;
	}

	if (NDAS_DEVICE_STATUS_CONNECTED != GetStatus()) 
	{
		DBGPRT_INFO(_T("%s: Non-connected device ignored\n"), ToString());
		return FALSE;
	}

	BOOL fSuccess = UpdateDeviceInfo();
	if (!fSuccess)
	{
		DBGPRT_ERR_EX(_T("%s: Device is not available.\n"), ToString());
		return FALSE;
	}

	fSuccess = DestroyUnitDevice(dwUnitNo);
	if (!fSuccess) 
	{
		DBGPRT_ERR_EX(_FT("%s: Destroying unit device (%d) failed: "), ToString(), dwUnitNo);
		return FALSE;
	}

	fSuccess = CreateUnitDevice(dwUnitNo);
	if (!fSuccess) 
	{
		DBGPRT_ERR_EX(_FT("%s: Creating unit device (%d) failed: "), ToString(), dwUnitNo);
		return FALSE;
	}

	DBGPRT_INFO(_FT("%s: Unit Device (%d) recreated\n"), ToString(), dwUnitNo);

	return TRUE;
}
Ejemplo n.º 15
0
BOOL 
CNdasDeviceHeartbeatListener::Initialize()
{
	BOOL fSuccess = m_dgramServer.Initialize();
	if (!fSuccess) 
	{
		DBGPRT_ERR_EX(_FT("CLpxDatagramServer init failed: "));
		return FALSE;
	}
	return CTask::Initialize();
}
Ejemplo n.º 16
0
BOOL
CLpxAsyncSocket::ShutDown(INT nHow)
{
	_ASSERTE(INVALID_SOCKET != m_sock);

	INT iResult = ::shutdown(m_sock, nHow);
	if (0 != iResult) {
		DBGPRT_ERR_EX(_FT("Shutting down a sock %p failed: "), m_sock);
		return FALSE;
	}
	return TRUE;
}
Ejemplo n.º 17
0
BOOL 
CNdasLogicalDevice::GetSharedWriteInfo(
	LPBOOL lpbSharedWrite, LPBOOL lpbPrimary)
{
	if (lpbSharedWrite) {
#ifdef NDAS_FEATURE_DISABLE_SHARED_WRITE
		*lpbSharedWrite = FALSE;
#else
		*lpbSharedWrite = TRUE;
#endif
	}

#ifdef NDAS_FEATURE_DISABLE_SHARED_WRITE
	// none for no shared write software
#else

	if (NULL == lpbPrimary) 
	{
		return TRUE;
	}

	BUSENUM_QUERY_INFORMATION BusEnumQuery = {0};
	BUSENUM_INFORMATION BusEnumInformation = {0};

	BusEnumQuery.InfoClass = INFORMATION_PDO;
	BusEnumQuery.Size = sizeof(BUSENUM_QUERY_INFORMATION);
	BusEnumQuery.SlotNo = m_NdasScsiLocation.SlotNo;

	BOOL fSuccess = ::LsBusCtlQueryInformation(
		&BusEnumQuery,
		sizeof(BUSENUM_QUERY_INFORMATION),
		&BusEnumInformation,
		sizeof(BUSENUM_INFORMATION));

	if (!fSuccess) 
	{
		DBGPRT_ERR_EX(_FT("LanscsiQueryInformation failed at slot %d: "), 
			m_NdasScsiLocation.SlotNo);
		return FALSE;
	}

	if (ND_ACCESS_ISRW(BusEnumInformation.PdoInfo.GrantedAccess)) 
	{
		*lpbPrimary = TRUE;
	} else {
		*lpbPrimary = FALSE;
	}

#endif

	return TRUE;

}
Ejemplo n.º 18
0
BOOL 
CLpxStreamListener::Listen(INT nBacklog /* = SOMAXCONN */)
{
	_ASSERTE(INVALID_SOCKET != m_sock);

	INT iResult = ::listen(m_sock, nBacklog);
	if (0 != iResult) {
		DBGPRT_ERR_EX(_FT("listen on %p failed: "), m_sock);
		return FALSE;
	}
	return TRUE;
}
Ejemplo n.º 19
0
BOOL
CLpxSockAddrListChangeNotifier::Reset()
{
	BOOL fSuccess = ::ResetEvent(m_hEvent);
	_ASSERT(fSuccess);

	if (INVALID_SOCKET != m_sock) {
		::closesocket(m_sock);
	}

	// ::ZeroMemory(&m_overlapped, sizeof(WSAOVERLAPPED));
	m_overlapped.Internal =
	m_overlapped.InternalHigh =
	m_overlapped.Offset =
	m_overlapped.OffsetHigh = 0;
	m_overlapped.hEvent = m_hEvent;

	AutoSocket sock = ::WSASocket(
		AF_LPX, 
		SOCK_DGRAM, 
		LPXPROTO_DGRAM, 
		NULL, 
		0, 
		WSA_FLAG_OVERLAPPED);

	if (INVALID_SOCKET == (SOCKET) sock) {
		return FALSE;
	}

	int iError;
	DWORD cbBytesReturned;

	iError = ::WSAIoctl(
		sock,
		SIO_ADDRESS_LIST_CHANGE,
		NULL, 0,
		NULL, 0,
		&cbBytesReturned,
		&m_overlapped,
		NULL);

	if (0 != iError && WSA_IO_PENDING != ::WSAGetLastError()) { 
		// SOCKET_ERROR
		// TODO: Error Event Log from WSAGetLastError
		DBGPRT_ERR_EX(_FT("WSAIoctl SIO_ADDRESS_LIST_CHANGE failed: "));
		return FALSE;
	}

	m_sock = sock.Detach();

	return TRUE;
}
Ejemplo n.º 20
0
BOOL
CLpxSockAddrListChangeNotifier::Initialize()
{
	if (NULL == m_hEvent) {
		m_hEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
		if (NULL == m_hEvent) {
			DBGPRT_ERR_EX(_FT("Creating a event failed: "));
			return FALSE;
		}
	}
	return TRUE;

}
Ejemplo n.º 21
0
BOOL
CLpxDatagramSocket::GetSendToResult(LPDWORD lpcbSent)
{
	BOOL fSuccess = CLpxAsyncSocket::_GetSendResult(lpcbSent);
	if (!fSuccess) 
	{
		DBGPRT_ERR_EX(_FT("_GetSendResult failed: "));
		return FALSE;
	}

	UnlockSendQueue();
	return TRUE;
}
Ejemplo n.º 22
0
BOOL
CLpxDatagramSocket::SendToSync(
	CONST SOCKADDR_LPX* pRemoteAddr,
	DWORD cbToSend, 
	CONST BYTE* lpbData, 
	DWORD dwSendFlags,
	LPDWORD lpcbSent)
{
	BOOL fSuccess = SendTo(pRemoteAddr, cbToSend, lpbData, dwSendFlags);
	if (!fSuccess) 
	{
		DBGPRT_ERR_EX(_FT("Send failed: "));
		return FALSE;
	}
	fSuccess = GetSendToResult(lpcbSent);
	if (!fSuccess) 
	{
		DBGPRT_ERR_EX(_FT("GetSendToResult failed: "));
		return FALSE;
	}
	return TRUE;
}
Ejemplo n.º 23
0
BOOL 
CLpxStreamConnection::Recv(DWORD cbBufferMax, LPDWORD lpdwFlags)
{
	_ASSERTE(INVALID_SOCKET != m_sock);

	BOOL fSuccess = FALSE;
	DWORD cbReceived = 0;

	fSuccess = AllocRecvBuf(cbBufferMax);
	if (!fSuccess) {
		DBGPRT_ERR_EX(_FT("AllocRecvBuf failed: "));
		return FALSE;
	}

	ResetRecvOverlapped();

	INT iResult = ::WSARecv(
		m_sock,
		&m_wsaReceiveBuffer, 1,
		&cbReceived, lpdwFlags,
		&m_ovReceive, NULL);

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

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

	return TRUE;
}
Ejemplo n.º 24
0
BOOL 
CNdasDeviceComm::GetUnitDeviceInformation(PNDAS_UNITDEVICE_HARDWARE_INFO pUnitDevInfo)
{
	XTLASSERT(NULL != m_hNdas && "CNdasDeviceComm is not connected");
	XTLASSERT(pUnitDevInfo != NULL);

	BOOL fSuccess = NdasCommGetUnitDeviceHardwareInfo(m_hNdas, pUnitDevInfo);
	if (!fSuccess)
	{
		DBGPRT_ERR_EX(_FT("NdasCommGetUnitDeviceInfo failed: "));
		return FALSE;
	}

	return TRUE;
}
Ejemplo n.º 25
0
// #if WINVER >= 0x0501
BOOL
CLpxStreamConnection::Disconnect(DWORD dwFlags)
{
	_ASSERTE(INVALID_SOCKET != m_sock);

	LPFN_DISCONNECTEX lpfnDisconnectEx = NULL;
	GUID GuidDisconnectEx = WSAID_CONNECTEX;
	DWORD cbRead;
	INT iResult = ::WSAIoctl(m_sock, 
		SIO_GET_EXTENSION_FUNCTION_POINTER, 
		&GuidDisconnectEx, 
		sizeof(GuidDisconnectEx),
		&lpfnDisconnectEx, 
		sizeof(lpfnDisconnectEx), 
		&cbRead,
		NULL, 
		NULL);

	if (NULL == lpfnDisconnectEx) {
		DBGPRT_ERR_EX(_FT("Cannot load DisconnectEx function: "));
		return FALSE;
	}

	BOOL fSuccess = lpfnDisconnectEx(
		m_sock,
		NULL,
		dwFlags,
		0);

	if (!fSuccess) {
		DBGPRT_ERR_EX(_FT("DisconnectEx failed: "));
		return FALSE;
	}

	return TRUE;
}
Ejemplo n.º 26
0
BOOL 
CNdasUnitDeviceCreator::ReadDIBv1AndConvert(PNDAS_DIB_V2 pDIBv2)
{
	BOOL fSuccess = FALSE;
	NDAS_DIB DIBv1 = {0};
	PNDAS_DIB pDIBv1 = &DIBv1;

	fSuccess = m_devComm.ReadDiskBlock(
		reinterpret_cast<PBYTE>(pDIBv1), 
		NDAS_BLOCK_LOCATION_DIB_V1);

	if (!fSuccess) {
		DBGPRT_ERR_EX(_FT("Reading DIBv1 block failed: "));
		return FALSE;
	}

	//
	// If there is no DIB in the disk,
	// create a pseudo DIBv2
	//
	if (NDAS_DIB_SIGNATURE != pDIBv1->Signature ||
		IS_NDAS_DIBV1_WRONG_VERSION(*pDIBv1)) 
	{
		//
		// Create a pseudo DIBv2
		//
		InitializeDIBv2AsSingle(pDIBv2);		
		return TRUE;
	}

	//
	// Convert V1 to V2
	//
	fSuccess = ConvertDIBv1toDIBv2(
		pDIBv1, 
		pDIBv2, 
		m_udinfo.SectorCount.QuadPart);

	if (!fSuccess) {
		//
		// Create a pseudo DIBv2 again!
		//
		InitializeDIBv2AsSingle(pDIBv2);		
		return TRUE;
	}

	return TRUE;
}
Ejemplo n.º 27
0
BOOL
CNdasUnitDeviceCreator::ReadContentEncryptBlock(
	PNDAS_CONTENT_ENCRYPT_BLOCK pCEB)
{
	BOOL fSuccess = m_devComm.ReadDiskBlock(
		reinterpret_cast<PBYTE>(pCEB),
		NDAS_BLOCK_LOCATION_ENCRYPT);

	if(!fSuccess) 
	{
		DBGPRT_ERR_EX(_FT("Unable to read CEB: "));
		return FALSE;
	}

	return TRUE;
}
Ejemplo n.º 28
0
DWORD
CNdasDeviceHeartbeatListener::OnTaskStart()
{
	BOOL fSuccess = m_dgramServer.Receive(
		this, 
		m_usListenPort, 
		sizeof(NDAS_DEVICE_HEARTBEAT),
		m_hTaskTerminateEvent);
	
	if (!fSuccess) 
	{
		DBGPRT_ERR_EX(_FT("Listening Heartbeat at port %d failed: "), m_usListenPort);
		return 255;
	}

	return 0;
}
Ejemplo n.º 29
0
BOOL 
CNdasEventPublisher::AddEvent(
	const NDAS_EVENT_MESSAGE& eventMessage)
{
	m_queueLock.Lock();
	m_EventMessageQueue.push(eventMessage);
	m_queueLock.Unlock();
	BOOL fSuccess = ::ReleaseSemaphore(m_hSemQueue, 1, NULL);
	if (!fSuccess) {
		// Queue Full
		DBGPRT_ERR_EX(_FT("Event Message Queue Full, Discarded %s :"), 
			NdasEventTypeString(eventMessage.EventType));
		return FALSE;
	}
	DBGPRT_INFO(_FT("Event Message Queued: %s\n"), 
		NdasEventTypeString(eventMessage.EventType));
	return TRUE;
}
Ejemplo n.º 30
0
BOOL
CNdasDeviceComm::ReadDiskBlock(PBYTE pBlockBuffer, INT64 i64DiskBlock, INT32 i32BlockSize)
{
	XTLASSERT(NULL != m_hNdas && "CNdasDeviceComm is not connected");
	XTLASSERT(pBlockBuffer != NULL);
	XTLASSERT(i32BlockSize >= 1 && i32BlockSize <= 128);
	XTLASSERT(!::IsBadWritePtr(pBlockBuffer, i32BlockSize * 512));

	BOOL fSuccess = NdasCommBlockDeviceRead(
		m_hNdas, i64DiskBlock, i32BlockSize, pBlockBuffer);

	if (!fSuccess)
	{
		DBGPRT_ERR_EX(_FT("NdasCommBlockDeviceRead failed: "));
		return FALSE;
	}

	return TRUE;
}