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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CSocket and threads

CSocket and threads

Scheduled Pinned Locked Moved C / C++ / MFC
javaquestion
5 Posts 3 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.
  • B Offline
    B Offline
    Beer
    wrote on last edited by
    #1

    hey all, say you have CSocket, or a plain WSA socket as a pointer member of a class, and you block the socket on a read method, and while it's blocked, you pass a reference to the class containing the socket to another thread through a casted pointer through the LPVOID pParam of a thread message, THEN, you start doing other operations on the CSocket from thread 2 through the pointer, while thread 1 has the thread on the blocked receive method. Like say thread 1 has the socket blocked receiving and thread 2 does a send on the same instance of the class with the m_pcsocket??? Does the world suddenly blow up if that happens? I used to do this all the time with java, but I'd like to know if it will properly work before I try it with CSocket. hey

    V M 2 Replies Last reply
    0
    • B Beer

      hey all, say you have CSocket, or a plain WSA socket as a pointer member of a class, and you block the socket on a read method, and while it's blocked, you pass a reference to the class containing the socket to another thread through a casted pointer through the LPVOID pParam of a thread message, THEN, you start doing other operations on the CSocket from thread 2 through the pointer, while thread 1 has the thread on the blocked receive method. Like say thread 1 has the socket blocked receiving and thread 2 does a send on the same instance of the class with the m_pcsocket??? Does the world suddenly blow up if that happens? I used to do this all the time with java, but I'd like to know if it will properly work before I try it with CSocket. hey

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      No. I think given that a socket is blocked, you have to wait for the thread to free the socket. One solution is WSA non-blocking model. WSA modes will return immediately and allows any other threads to process the socket. Kuphryn

      B 1 Reply Last reply
      0
      • V valikac

        No. I think given that a socket is blocked, you have to wait for the thread to free the socket. One solution is WSA non-blocking model. WSA modes will return immediately and allows any other threads to process the socket. Kuphryn

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

        "void CancelBlockingCall( ); Remarks Call this member function to cancel a blocking call currently in progress." This is nuts, how are you going to cancel a blocking call if the call is blocked? They HAVE to mean from another thread right? Then you can cancel the receive before you send text then restart it right after your data is sent right? am i wrong or am i right? hey

        1 Reply Last reply
        0
        • B Beer

          hey all, say you have CSocket, or a plain WSA socket as a pointer member of a class, and you block the socket on a read method, and while it's blocked, you pass a reference to the class containing the socket to another thread through a casted pointer through the LPVOID pParam of a thread message, THEN, you start doing other operations on the CSocket from thread 2 through the pointer, while thread 1 has the thread on the blocked receive method. Like say thread 1 has the socket blocked receiving and thread 2 does a send on the same instance of the class with the m_pcsocket??? Does the world suddenly blow up if that happens? I used to do this all the time with java, but I'd like to know if it will properly work before I try it with CSocket. hey

          M Offline
          M Offline
          markkuk
          wrote on last edited by
          #4

          MFC CSockets can't be passed between threads. It should be possible with a plain WinSock socket.

          B 1 Reply Last reply
          0
          • M markkuk

            MFC CSockets can't be passed between threads. It should be possible with a plain WinSock socket.

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

            It turned out I was actually looking for CSocket's OnReceive function, overriding that gave the class i was writing the desired effect. hey

            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