Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Waitting on hEvent of Mailslot

Waitting on hEvent of Mailslot

Scheduled Pinned Locked Moved C / C++ / MFC
question
11 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    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

    CPalliniC V 2 Replies Last reply
    0
    • F ForNow

      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

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      I think you have to create a named event, see Interprocess Synchronization (Windows)[^].

      In testa che avete, signor di Ceprano?

      F 1 Reply Last reply
      0
      • F ForNow

        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

        V Offline
        V Offline
        Victor Nijegorodov
        wrote on last edited by
        #3

        There is an excellent article about using mailslots: Using Mailslots for Interprocess Communication[^] Did you read it?

        F 2 Replies Last reply
        0
        • CPalliniC CPallini

          I think you have to create a named event, see Interprocess Synchronization (Windows)[^].

          F Offline
          F Offline
          ForNow
          wrote on last edited by
          #4

          I did in a ReadFile for a mail slot when the i/o is completed shouldn't hOverLap.hEvent be signaled ?

          1 Reply Last reply
          0
          • V Victor Nijegorodov

            There is an excellent article about using mailslots: Using Mailslots for Interprocess Communication[^] Did you read it?

            F Offline
            F Offline
            ForNow
            wrote on last edited by
            #5

            thanks

            1 Reply Last reply
            0
            • V Victor Nijegorodov

              There is an excellent article about using mailslots: Using Mailslots for Interprocess Communication[^] Did you read it?

              F Offline
              F Offline
              ForNow
              wrote on last edited by
              #6

              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

              Richard Andrew x64R 1 Reply Last reply
              0
              • F ForNow

                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

                Richard Andrew x64R Offline
                Richard Andrew x64R Offline
                Richard Andrew x64
                wrote on last edited by
                #7

                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.

                F 1 Reply Last reply
                0
                • Richard Andrew x64R Richard Andrew x64

                  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.

                  F Offline
                  F Offline
                  ForNow
                  wrote on last edited by
                  #8

                  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");
                  
                  Richard Andrew x64R 1 Reply Last reply
                  0
                  • F ForNow

                    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");
                    
                    Richard Andrew x64R Offline
                    Richard Andrew x64R Offline
                    Richard Andrew x64
                    wrote on last edited by
                    #9

                    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.

                    F 1 Reply Last reply
                    0
                    • Richard Andrew x64R Richard Andrew x64

                      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.

                      F Offline
                      F Offline
                      ForNow
                      wrote on last edited by
                      #10

                      You are probably right the WriteFile has a NULL for the overlapped While the ReadFile has a overlapped paramater

                      L 1 Reply Last reply
                      0
                      • F ForNow

                        You are probably right the WriteFile has a NULL for the overlapped While the ReadFile has a overlapped paramater

                        L Offline
                        L Offline
                        leon de boer
                        wrote on last edited by
                        #11

                        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

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups