Make accept() stop

This is a discussion on Make accept() stop within the Networking/Device Communication forums, part of the General Programming Boards category; Originally Posted by Eibro Simply closing the socket from another thread will cause accept() to return. True, but anonytmouse's method ...

  1. #16
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by Eibro
    Simply closing the socket from another thread will cause accept() to return.
    True, but anonytmouse's method looks pretty solid. Plus his method wouldn't require a worker thread to maintain which sockets need to be closed.

  2. #17
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Quote Originally Posted by master5001
    True, but anonytmouse's method looks pretty solid. Plus his method wouldn't require a worker thread to maintain which sockets need to be closed.
    Eh? His would require another thread to set the quit event.

  3. #18
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Right, but what if you don't want to close the socket?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #19
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Quote Originally Posted by Hunter2
    Right, but what if you don't want to close the socket?
    Why else would you want accept() to die? That socket is typically used for nothing more than accepting clients.

  5. #20
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    For the sake of pointless argument, I'll just say: Because perhaps you want to keep the socket bound on that port for later accept()ing If you close the socket, there's a small chance that another socket will steal the port before you get around to re-binding to it.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  6. #21
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    *cough* non-blocking functions *cough*

  7. #22
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    That's what anonytmouse did. Anyway, select() works wonders too.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  8. #23
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Quote Originally Posted by master5001
    *cough* non-blocking functions *cough*
    What do you suggest? Setting a socket to non-blocking mode and spinning the CPU until you can accept a connection?

    That's what anonytmouse did. Anyway, select() works wonders too.
    No, anonytmouse's method blocks perfectly well.

  9. #24
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>Setting a socket to non-blocking mode and spinning the CPU until you can accept a connection?
    Or you could have it in another thread, and then use anonytmouse's implementation - and if in your main thread you want it to abort the accept, you can cancel it by setting an event without closing the socket.

    And as I have mentioned, though it means eating CPU cycles in many situations, you can emulate non-blocking using select().
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  10. #25
    Registered User
    Join Date
    Dec 2004
    Posts
    95
    AcceptEx please

  11. #26
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Ahh.. right, overlapped completion routines.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  12. #27
    Registered User
    Join Date
    Dec 2004
    Posts
    95
    Preferably not completion routines, completion ports.

  13. #28
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    I thought IOCP only works on certain OS'es?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  14. #29
    Registered User
    Join Date
    Dec 2004
    Posts
    95
    Yeah, that's the limitation. NT,2k,XP,2003 only. But you'd mainly apply it to scalable servers (or clients), which personally I wouldn't bother running on 9x kernel machines.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why does my prog just stop?
    By Queatrix in forum Windows Programming
    Replies: 4
    Last Post: 03-01-2006, 05:12 PM
  2. Win32 Common Controls in C++, how do i make and use them?
    By C+noob in forum Windows Programming
    Replies: 6
    Last Post: 01-09-2006, 11:53 AM
  3. want to make this small program...
    By psycho88 in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2005, 02:05 AM
  4. Make Cortana Stop Kicking Me!!!???
    By drdroid in forum C++ Programming
    Replies: 6
    Last Post: 02-27-2003, 05:27 PM
  5. how to make files
    By quiksilver9531 in forum C++ Programming
    Replies: 6
    Last Post: 02-22-2002, 06:44 PM

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