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. ATL / WTL / STL
  4. assign an event to a socket operation

assign an event to a socket operation

Scheduled Pinned Locked Moved ATL / WTL / STL
c++tutorialcsharpvisual-studioquestion
6 Posts 3 Posters 13 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.
  • U Offline
    U Offline
    User 7946055
    wrote on last edited by
    #1

    Windows 7, Visual Studio 2012, winsock Edit: Oops, posted in ATL rather than C++. If you are an admin type, please move it. How is an event associated with a socket operation? For example: [code]

    // start listening for new clients attempting to connect
    iResult = listen(ListenSocket, 1);

    [/code] The socket is non-blocking and the code continues while waiting for the listen operation to complete. I want event: CLIENT_DETECTED (arbitrary name, I know how to create the event.) to be triggered when a client solicits a connection. Yes, I understand a bunch of code is needed to capture that event and do something. Thank you for your time.

    L 1 Reply Last reply
    0
    • U User 7946055

      Windows 7, Visual Studio 2012, winsock Edit: Oops, posted in ATL rather than C++. If you are an admin type, please move it. How is an event associated with a socket operation? For example: [code]

      // start listening for new clients attempting to connect
      iResult = listen(ListenSocket, 1);

      [/code] The socket is non-blocking and the code continues while waiting for the listen operation to complete. I want event: CLIENT_DETECTED (arbitrary name, I know how to create the event.) to be triggered when a client solicits a connection. Yes, I understand a bunch of code is needed to capture that event and do something. Thank you for your time.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      See http://msdn.microsoft.com/en-gb/library/windows/desktop/ms739168(v=vs.85).aspx[^], listen is a blocking call.

      B 1 Reply Last reply
      0
      • L Lost User

        See http://msdn.microsoft.com/en-gb/library/windows/desktop/ms739168(v=vs.85).aspx[^], listen is a blocking call.

        B Offline
        B Offline
        bkelly13
        wrote on last edited by
        #3

        Hello, OK, its there as in:

        Quote:

        Note When issuing a blocking Winsock call such as listen, Winsock may need to wait for a network event before the call can complete.

        I presumed that it could also be non-blocking. Then they carry on with:

        Quote:

        Winsock performs an alertable wait in this situation, which can be interrupted by an asynchronous procedure call (APC) scheduled on the same thread.

        So in order to kill the program when no client comes a-calling, I need to learn this. I will search but if you have a link to a good article on this, that would be appreciated. Thank you for your time. Edit: While re-reading the MSDN page on listen(), I noticed that the words are:

        Quote:

        ... Winsock may need to wait for a network event....

        Directing attention to the word "may," that means that there are circumstances in which Winsock does not need to wait for a network event. Should that statement have stated that Winsock "will" wait for a network event? Or is there another way out of the Listen call?

        Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com

        L 1 Reply Last reply
        0
        • B bkelly13

          Hello, OK, its there as in:

          Quote:

          Note When issuing a blocking Winsock call such as listen, Winsock may need to wait for a network event before the call can complete.

          I presumed that it could also be non-blocking. Then they carry on with:

          Quote:

          Winsock performs an alertable wait in this situation, which can be interrupted by an asynchronous procedure call (APC) scheduled on the same thread.

          So in order to kill the program when no client comes a-calling, I need to learn this. I will search but if you have a link to a good article on this, that would be appreciated. Thank you for your time. Edit: While re-reading the MSDN page on listen(), I noticed that the words are:

          Quote:

          ... Winsock may need to wait for a network event....

          Directing attention to the word "may," that means that there are circumstances in which Winsock does not need to wait for a network event. Should that statement have stated that Winsock "will" wait for a network event? Or is there another way out of the Listen call?

          Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          bkelly13 wrote:

          Should that statement have stated ...

          I cannot answer for Microsoft's wording. My reading of it is that listen always blocks for a connection to complete, it should not be too difficult to test.

          B 2 Replies Last reply
          0
          • L Lost User

            bkelly13 wrote:

            Should that statement have stated ...

            I cannot answer for Microsoft's wording. My reading of it is that listen always blocks for a connection to complete, it should not be too difficult to test.

            B Offline
            B Offline
            bkelly13
            wrote on last edited by
            #5

            I am going with that. Thank you for taking the time to reply.

            Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com

            1 Reply Last reply
            0
            • L Lost User

              bkelly13 wrote:

              Should that statement have stated ...

              I cannot answer for Microsoft's wording. My reading of it is that listen always blocks for a connection to complete, it should not be too difficult to test.

              B Offline
              B Offline
              bkelly13
              wrote on last edited by
              #6

              I have finally progressed to the point of testing the listen() function. This app sets non-blocking attribute and the code steps right over the listen() call, with a noticeable pause. Now the question becomes: Is there a proper method of stopping a listen in progress? There are WSASend() and other socket methods with additional arguments, but I did not find a WSAListen(); I will post that as a new question.

              Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com

              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