阅读:2562回复:3
TDI发送速率的问题,有代码,求助
现在用TDI发送TCP数据,但是大约每200ms才发出去一个包,调试以后发现在
KeWaitForSingleObject( &Event, Executive, KernelMode, FALSE, NULL); 这儿会一直等待直到数据发出去。 我把KeWaitForSingleObject去掉以后发送速度很快但发到网络上的数据却出错了, 在坛子里搜索了一下发现其他人也有这样的问题。 谁知道到底怎么解决这个问题,代码贴出来了: NTSTATUS TDISendData( PDEVICE_OBJECT TDI_Device_Object, PFILE_OBJECT TDI_Endpoint_FileObj, PIRP Irp ) { PIRP pIrp; PMDL pMdl; KEVENT Event; NTSTATUS Status; IO_STATUS_BLOCK IoStatus; PVOID pSendBuffer; ULONG SendBfrLength; KeInitializeEvent(&Event, NotificationEvent, FALSE); // This code is necessary if buffer is in the paged pool. // Must run at <= DISPATCH_LEVEL. pSendBuffer = MmGetMdlVirtualAddress ( Irp->MdlAddress ); SendBfrLength = MmGetMdlByteCount( Irp->MdlAddress ); ASSERT( KeGetCurrentIrql() <= DISPATCH_LEVEL ); pMdl = IoAllocateMdl(pSendBuffer, SendBfrLength, FALSE, FALSE, NULL); if(NULL==pMdl) { DbgPrint("Could not get an MDL for TDI_SEND"); return(STATUS_INSUFFICIENT_RESOURCES); } // Must run at < DISPATCH_LEVEL for pageable memory. ASSERT( KeGetCurrentIrql() < DISPATCH_LEVEL ); __try { MmProbeAndLockPages( pMdl, // (Try to) fix buffer. KernelMode, IoModifyAccess ); } __except(EXCEPTION_EXECUTE_HANDLER) { DbgPrint("Exception calling MmProbeAndLockPages"); return STATUS_UNSUCCESSFUL; } if(pMdl) { // Build an IRP to connect to a remote host. pIrp = TdiBuildInternalDeviceControlIrp( TDI_SEND, TDI_Device_Object, // TDI driver's device object TDI_Endpoint_FileObj, // connection (endpoint) file object &Event, // event to be signalled when IRP completes &IoStatus // I/O status block ); if(pIrp){ TdiBuildSend( pIrp, TDI_Device_Object, // TDI driver's device object TDI_Endpoint_FileObj, // connection (endpoint) file object NULL, // I/O completion routine NULL, // context for I/O completion routine pMdl, // MDL address 0, // Flags. 0 => send as normal TSDU. SendBfrLength // length of buffer mapped by MDL ); ASSERT( KeGetCurrentIrql() <= DISPATCH_LEVEL ); // Send the command to the underlying TDI driver. Status = IoCallDriver(TDI_Device_Object, pIrp); if ( Status == STATUS_PENDING ) { KeWaitForSingleObject( &Event, Executive, KernelMode, FALSE, NULL); } Status = IoStatus.Status; Irp->IoStatus.Information = IoStatus.Information; if ( (Status != STATUS_SUCCESS) && (Status != STATUS_PENDING)) { // Something is wrong. DbgPrint("IoCallDriver failed (send), status 0x%08X", Status); return STATUS_UNSUCCESSFUL; } if ((Status == STATUS_PENDING) && (IoStatus.Status != STATUS_SUCCESS)) { // Something is wrong. DbgPrint("Completion of IRP failed (send), status 0x%08X", IoStatus.Status); return STATUS_UNSUCCESSFUL; } } } return Status; } |
|
沙发#
发布于:2007-10-20 06:14
Faint...fatal memory leakage!
Just discard the delay issue. While you refer to IoAllocateMdl and MmProbeAndLockPages, keep in mind when and where you place the IoFreeMdl and MmUnlockPages. |
|
|
板凳#
发布于:2009-06-06 16:10
up, 碰到了同样的问题,等待高手来解决
|
|
地板#
发布于:2009-07-24 17:45
可以设置一个完成回调函数。
|
|