阅读:2601回复:3
TDI中tdi receive的问题?
我想写一个tdi两端通信的程序,客户端用的普通socket,服务端则是tdi 建立基本的连接后,用函数sendtocontroler()发送和receivefromcontroller()接受。sendtocontroler()没有问题,就是receivefromcontroler()出错。
NTSTATUS receivefromcontroler( ) { PDEVICE_OBJECT devObj; KEVENT receiveevent; PIRP irp; PMDL mdl; IO_STATUS_BLOCK iosb; NTSTATUS status; devObj = IoGetRelatedDeviceObject(connectionFileObject); KeInitializeEvent(&receiveevent, NotificationEvent, FALSE); irp = TdiBuildInternalDeviceControlIrp(TDI_RECEIVE, devObj, connectionFileObject, &receiveevent, &iosb); if (irp == NULL) { return STATUS_INSUFFICIENT_RESOURCES; } if (len) { mdl = IoAllocateMdl((void*) buf, len, FALSE, FALSE, NULL); if (mdl == NULL) { IoFreeIrp(irp); return STATUS_INSUFFICIENT_RESOURCES; } __try { MmProbeAndLockPages(mdl, KernelMode, IoReadAccess); status = STATUS_SUCCESS; } __except (EXCEPTION_EXECUTE_HANDLER) { IoFreeMdl(mdl); IoFreeIrp(irp); status = STATUS_INVALID_USER_BUFFER; } if (!NT_SUCCESS(status)) { return status; } } TdiBuildReceive(irp, devObj, connectionFileObject, NULL, NULL, len ,mdl , flags, len); IoSetCompletionRoutine(irp,TDICompletionRoutine,&receiveevent,TRUE.TRUE,TRUE); status = IoCallDriver(devObj, irp); if (status == STATUS_PENDING) { KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL); status = iosb.Status; } return NT_SUCCESS(status) ; memcpy(getcommand,mdl ,strlen(mdl )); } 外面定义 char getcommand[256]; 接受一个命令没有问题,我在主函数中创建了一个线程,在其中用while(true) {receivefromcontroler();},当不启动客户端只启动服务端时就会蓝屏,当和客户端建立连接然后 客户端推出时,也会蓝屏,但是不用while循环就不会这样,不知道为什么,困扰了好久,请求各位大侠帮忙 |
|
沙发#
发布于:2009-03-04 16:27
不解的一点就是为什么一循环就蓝屏
|
|
板凳#
发布于:2009-03-06 14:36
memcpy(getcommand,mdl ,strlen(mdl ));
是否strlen(mdl )会大于256? |
|
|
地板#
发布于:2009-03-06 21:36
哈哈,memcpy(getcommand,mdl ,strlen(mdl ));更本就是垃圾代码,怎么会被执行到呢?
但是"KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);"这行代码中的event是那里冒出来来的? 你哪个本地变量是KEVENT receiveevent; 是写贴出来的错了? 不连接connectionFileObject是NULL,你去接收当然有问题. 同样在关闭连接后,对象已经删除你还在接收,怎么不错 |
|
|