Waitting on hEvent of Mailslot
-
Hi I am using Mailslots for Interprocess communication. Process A does a WriteFile with NULL for the overlapped parameter. Process B has a overlapped parameter on the ReadFile. My question is Can process A do WaitForSingleObject on the hEvent of process B overlapped to know when the read has completed Thsnks
-
Hi I am using Mailslots for Interprocess communication. Process A does a WriteFile with NULL for the overlapped parameter. Process B has a overlapped parameter on the ReadFile. My question is Can process A do WaitForSingleObject on the hEvent of process B overlapped to know when the read has completed Thsnks
There is an excellent article about using mailslots: Using Mailslots for Interprocess Communication[^] Did you read it?
-
I think you have to create a named event, see Interprocess Synchronization (Windows)[^].
-
There is an excellent article about using mailslots: Using Mailslots for Interprocess Communication[^] Did you read it?
-
There is an excellent article about using mailslots: Using Mailslots for Interprocess Communication[^] Did you read it?
I read the article Which basically Said if I CreateFile on the Client Side with FILE_FLAG_OVERALAPPED File then when doing an I/O which I would assume would include ReadFile on the Server side An Overlapped structure would be used (A member of which is m_hEvent I did a OpenEvent on the Client side as The CreateProcess let me inherit objects tried WaitForSingleObject (m_hEvent of the overlapped of the ReadFile) the First wait worked the second didn't as I did three writes
-
I read the article Which basically Said if I CreateFile on the Client Side with FILE_FLAG_OVERALAPPED File then when doing an I/O which I would assume would include ReadFile on the Server side An Overlapped structure would be used (A member of which is m_hEvent I did a OpenEvent on the Client side as The CreateProcess let me inherit objects tried WaitForSingleObject (m_hEvent of the overlapped of the ReadFile) the First wait worked the second didn't as I did three writes
ForNow wrote:
First wait worked the second didn't as I did three writes
"Didn't work" is hardly a technical description of the problem. Are you forgetting to reset a manual-reset event?
The difficult we do right away... ...the impossible takes slightly longer.
-
ForNow wrote:
First wait worked the second didn't as I did three writes
"Didn't work" is hardly a technical description of the problem. Are you forgetting to reset a manual-reset event?
The difficult we do right away... ...the impossible takes slightly longer.
-
Don't think so the flag is set to False it should auto-reset
sysblk.mail = CreateEvent(&sa, FALSE, // let Windows Re-set FALSE, // Intially set off (LPCTSTR)"MyEvent");
Well maybe the writes are occurring so quickly that the system only has time to signal the event one time. Whenever the event is signaled, you should check for more messages before looping back to the wait function. Don't expect the event to be signaled exactly once for each message you write.
The difficult we do right away... ...the impossible takes slightly longer.
-
Well maybe the writes are occurring so quickly that the system only has time to signal the event one time. Whenever the event is signaled, you should check for more messages before looping back to the wait function. Don't expect the event to be signaled exactly once for each message you write.
The difficult we do right away... ...the impossible takes slightly longer.
-
You are probably right the WriteFile has a NULL for the overlapped While the ReadFile has a overlapped paramater
The WriteFile doesn't need or require an overlapped access and I would be intrigued what security attributes you are feeding in via sa. Naming the event is fine but why are you needing to provide specific security attributes are you doing something special? The worry I gleaned was you hold the event handle in sysblk.mail are you remembering to copy the handle reference into your overlapped structure? It's sort of odd what you are doing there but not wrong so long as you remember to transfer the handle. The usual read thread code direct from MSDN looks like
char buffer[100];
OVERLAPPED ovlp = {0};// Create event in overlapped structure // This directly places Event handle in empty Overlapped structure ovlp.hEvent = CreateEvent(NULL, false, false, NULL); if (ovlp.hEvent == NULL) { // You have some error creating the event run some error code } DWORD read; do { ReadFile(mailslot, buffer, sizeof(buffer), &read, &ovlp); // ovlp.handle in your case must be sysblk.mail buffer\[read\] = 0; WaitForSingleObject(ovlp.hEvent, INFINITE); // you are then waiting on your event sysblk.mail process\_message(buffer); } while (strcmp(buffer, "exit")); // <= Your exit thread condition
The write thread is create function is non overlapped
HANDLE mailslot = CreateFile("\\\\.\\mailslot\\myslot",
GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
0,
NULL);They are the by the book MSDN examples and your code should be some extension of that process inside your sysblk code. Also remember this sort of thing is for relatively low speed, small packet exchanges if you want to go beyond that you need to change to memory mapped files.
In vino veritas