Winsock: Cutting A listen() Call Short

This is a discussion on Winsock: Cutting A listen() Call Short within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I have a thread which creates a socket and listens, creating new worker threads upon connections. I also have ...

  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,266

    Question Winsock: Cutting A listen() Call Short

    Hello,

    I have a thread which creates a socket and listens, creating new worker threads upon connections. I also have a GUI thread.

    When the user closes the main window of my program, how can I stop the server thread from listen()ing? I've tried calling shutdown(g_sockServer, SD_RECEIVE) but that doesn't appear to achieve anything.

    This should be achievable without the use of Asynchronous Winsock.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Is calling closesocket an option?

    Other options are to temporarily put the socket in non-blocking mode, as demonstrated in this post. More hackishly, you could connect to the socket to break the accept.

  3. #3
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,266
    Ah sorry, that wasn't the problem. It was that I wasn't breaking out of an infinite while loop if listen returns an error (which it will do if you shutdown or close the socket it's using).

    Silly me!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. winsock
    By pode in forum Networking/Device Communication
    Replies: 2
    Last Post: 09-26-2003, 01:45 AM
  2. Color Variety
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 10-23-2002, 10:17 AM
  3. C system call and library call
    By Coconut in forum C Programming
    Replies: 6
    Last Post: 08-22-2002, 12:20 PM
  4. Assembly example
    By Lynux-Penguin in forum C Programming
    Replies: 6
    Last Post: 04-24-2002, 08:45 PM
  5. Pls help me to do this project in C I need source code
    By sureshmenon74 in forum C Programming
    Replies: 4
    Last Post: 10-04-2001, 07:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21