Thread: Winsock: Cutting A listen() Call Short

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

    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,273
    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, 12:45 AM
  2. Color Variety
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 10-23-2002, 09:17 AM
  3. C system call and library call
    By Coconut in forum C Programming
    Replies: 6
    Last Post: 08-22-2002, 11:20 AM
  4. Assembly example
    By Lynux-Penguin in forum C Programming
    Replies: 6
    Last Post: 04-24-2002, 07: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, 06:57 AM