여기 수준 보아하니 쓰레기들이라 별로 기대는 안한다만..

필터에서 여러개 메세지를 동신에 여러게 보냈어...

근데 워커 쓰레드에서는 그메세지를 하나 밖에 못봤었어 다른일 하느라... 

그런데 신기한건 다른 여러게 메세지가 어딘가 버퍼에 저장되어 있는지 사라지지 않고 차례차례 들어오더군...

그 이유를 아는 사람?


자세한 코드는 여기 보여주마


어플에서 메세지 받는 부분은 이거고

        private void worker()

        {


            int ovlpOffset = Marshal.OffsetOf(typeof(NOTIFICATION_MESSAGE), "Ovlp").ToInt32();

            IntPtr messagePtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(NOTIFICATION_MESSAGE)));

 

            try

            {

                while (true)

                {

                    NOTIFICATION_MESSAGE notifyMessage = new NOTIFICATION_MESSAGE();

                    Marshal.StructureToPtr(notifyMessage, messagePtr, false); // memset to 0


                    long res = NativeMethods.FilterGetMessage(

                                                portPtr,

                                                messagePtr,

                                                ovlpOffset,

                                                messagePtr + ovlpOffset);

                    HRESULT hr = new HRESULT((uint)res);

                    if (hr != Win32Error.ERROR_IO_PENDING.ToHRESULT())

                        break;


                    uint numOfBytes = 0;

                    UIntPtr completionKeyPtr = UIntPtr.Zero;

                    IntPtr overlappedPtr = IntPtr.Zero;

                    if (!NativeMethods.GetQueuedCompletionStatus(completionPort,

                                                                 ref numOfBytes,

                                                                 ref completionKeyPtr,

                                                                 ref overlappedPtr,

                                                                 int.MaxValue))

                    {

                        break;

                    }


                    NOTIFICATION_MESSAGE message = (NOTIFICATION_MESSAGE)Marshal.PtrToStructure(overlappedPtr - ovlpOffset, typeof(NOTIFICATION_MESSAGE));


-->여기서 한참 잡고 있다고 가정해도 메세지가 사라지지 않음

                    //add to list 

                    fltMsgQueue.Enqueue(message);

                }

            }

            catch

            {

            }

            finally

            {

                Marshal.FreeHGlobal(messagePtr);

                messagePtr = IntPtr.Zero;

            }

        }



이거는 필터코드 

try{


//

// Set notification info.

//


notification.NotifyType = NotifyType;


replyLength = sizeof(REPLY_DATA);

notification.BytesToScan = sizeof(MSG_SEND_DATA);


RtlCopyMemory(&notification.Contents, MsgData, sizeof(MSG_SEND_DATA));


UNICODE_STRING tmpPath;

RtlInitUnicodeString(&tmpPath, notification.Contents.FilePath);


LOG_PRINT(LOGFL_DEBUG, ("rgFilter!SendLogMessage: Msg sending command : [%d], pid : [%d] File: [%wZ]\n",

notification.Contents.Command, notification.Contents.Pid, &tmpPath));


//

// Send message with msg data and recevied reply data.

//


status = FltSendMessage(gFilterData.Filter,

&gFilterData.ClientPort,

&notification,

sizeof(NOTIFICATION),

&replyData,

&replyLength,

NULL);


if (STATUS_SUCCESS == status) {


LOG_PRINT(LOGFL_DEBUG, ("rgFilter!SendLogMessage: Msg replied command : [%d], pid : [%d]\n",

replyData.Command, replyData.Pid));

}


//

// in case of reject command recevied , 1: allow 2: reject

//


result = replyData.Command;

}

except(EXCEPTION_EXECUTE_HANDLER) {


//

//  The copy failed, return an error, failing the operation.

//


Data->IoStatus.Status = GetExceptionCode();

Data->IoStatus.Information = 0;


leave;

}