Disonnecting a TCP listening socket - Networking

This is a discussion on Disonnecting a TCP listening socket - Networking ; Hi If a server program wants to stop accepting client connections, it just has to close() the listening socket. By doing this, it also discards the connections that are established, but that accept() hasn't returned yet. My question therefore is ...

+ Reply to Thread
Results 1 to 13 of 13

Thread: Disonnecting a TCP listening socket

  1. Disonnecting a TCP listening socket

    Hi

    If a server program wants to stop accepting client connections, it
    just has to close() the listening socket. By doing this, it also
    discards the connections that are established, but that accept()
    hasn't returned yet.
    My question therefore is : is it possible to tell the OS to stop
    accepting incoming connection requests, and still getting the
    connections that are already established and waiting in the queue ?


    Thanks for your help

    Jean-Luc

  2. Re: Disonnecting a TCP listening socket

    true801@gmail.com writes:

    > If a server program wants to stop accepting client connections, it
    > just has to close() the listening socket. By doing this, it also
    > discards the connections that are established, but that accept()
    > hasn't returned yet.
    > My question therefore is : is it possible to tell the OS to stop
    > accepting incoming connection requests, and still getting the
    > connections that are already established and waiting in the queue ?


    Just use the firewall to reject the syn packets?

    Vilmos

  3. Re: Disonnecting a TCP listening socket

    On 19 sep, 20:15, Vilmos Soti wrote:
    > true...@gmail.com writes:
    > > If a server program wants to stop accepting client connections, it
    > > just has to close() the listening socket. By doing this, it also
    > > discards the connections that are established, but that accept()
    > > hasn't returned yet.
    > > My question therefore is : is it possible to tell the OS to stop
    > > accepting incoming connection requests, and still getting the
    > > connections that are already established and waiting in the queue ?

    >
    > Just use the firewall to reject the syn packets?
    >
    > Vilmos


    Tanks, but I'm looking for a simpler solution.

    Jean-Luc

  4. Re: Disonnecting a TCP listening socket

    true801@gmail.com wrote:
    > If a server program wants to stop accepting client connections, it
    > just has to close() the listening socket. By doing this, it also
    > discards the connections that are established, but that accept()
    > hasn't returned yet.


    > My question therefore is : is it possible to tell the OS to stop
    > accepting incoming connection requests, and still getting the
    > connections that are already established and waiting in the queue ?


    Might look into what happens to existing connections when you set the
    backlog to a very small number. It may not close the window entirely,
    but it may close it just enough. Or it may behave just like close()
    against the listen endpoint...

    rick jones
    --
    Wisdom Teeth are impacted, people are affected by the effects of events.
    these opinions are mine, all mine; HP might not want them anyway...
    feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...

  5. Re: Disonnecting a TCP listening socket

    On Sep 19, 10:49*am, true...@gmail.com wrote:
    > Hi
    >
    > If a server program wants to stop accepting client connections, it
    > just has to close() the listening socket. By doing this, it also
    > discards the connections that are established, but that accept()
    > hasn't returned yet.
    > My question therefore is : is it possible to tell the OS to stop
    > accepting incoming connection requests, and still getting the
    > connections that are already established and waiting in the queue ?


    No. There's no easy way to do it. And it's very tricky to do it 100%
    correctly in combination with things like syn cookies. It's tricky to
    tell for sure whether an incoming SYN is for a new connection or one
    that's already established (and your SYN/ACK dropped).

    DS

  6. Re: Disonnecting a TCP listening socket

    On 19 sep, 20:41, Rick Jones wrote:
    > true...@gmail.com wrote:
    > > If a server program wants to stop accepting client connections, it
    > > just has to close() the listening socket. By doing this, it also
    > > discards the connections that are established, but that accept()
    > > hasn't returned yet.
    > > My question therefore is : is it possible to tell the OS to stop
    > > accepting incoming connection requests, and still getting the
    > > connections that are already established and waiting in the queue ?

    >
    > Might look into what happens to existing connections when you set the
    > backlog to a very small number. *It may not close the window entirely,
    > but it may close it just enough. *Or it may behave just like close()
    > against the listen endpoint...


    How do you modify the backlog of existing connections ?

    Jean-Luc


  7. Re: Disonnecting a TCP listening socket

    On 19 sep, 21:25, David Schwartz wrote:
    > On Sep 19, 10:49*am, true...@gmail.com wrote:
    >
    > > Hi

    >
    > > If a server program wants to stop accepting client connections, it
    > > just has to close() the listening socket. By doing this, it also
    > > discards the connections that are established, but that accept()
    > > hasn't returned yet.
    > > My question therefore is : is it possible to tell the OS to stop
    > > accepting incoming connection requests, and still getting the
    > > connections that are already established and waiting in the queue ?

    >
    > No. There's no easy way to do it. And it's very tricky to do it 100%
    > correctly in combination with things like syn cookies. It's tricky to
    > tell for sure whether an incoming SYN is for a new connection or one
    > that's already established (and your SYN/ACK dropped).
    >
    > DS


    If it is not possible, how can web servers and other severs using TCP
    stop properly ?


    Jean-Luc

  8. Re: Disonnecting a TCP listening socket

    true801@gmail.com wrote:
    > How do you modify the backlog of existing connections ?


    I was thinking via another listen() call against the listen endpoint.
    Presumably the application made one when setting-up the listen()
    endpoint in the first place, and gave it some backlog value. My
    _speculation_ was that perhaps that backlog value could be "shrunk" on
    an existing listen endpoint.

    rick jones
    --
    oxymoron n, Hummer H2 with California Save Our Coasts and Oceans plates
    these opinions are mine, all mine; HP might not want them anyway...
    feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...

  9. Re: Disonnecting a TCP listening socket

    true801@gmail.com wrote:
    > If it is not possible, how can web servers and other severs using
    > TCP stop properly ?


    By defining "properly" as "may involve some RST's sent to clients
    waiting for service."

    rick jones
    --
    portable adj, code that compiles under more than one compiler
    these opinions are mine, all mine; HP might not want them anyway...
    feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...

  10. Re: Disonnecting a TCP listening socket

    On Sep 19, 12:54*pm, true...@gmail.com wrote:

    > If it is not possible, how can web servers and other severs using TCP
    > stop properly ?
    >
    > Jean-Luc


    The protocol should be designed such that it is perfectly acceptable
    for the server to close the connection before receiving or sending any
    data. The client should interpret this as the web server being
    unwilling or unable to serve that client at that time.

    If a protocol doesn't do this, the protocol is broken for TCP, and
    suffers from (yet another) version of the two generals problem. That
    is, it assumes the two ends can agree on whether a connection was
    established or not, and that is provably impossible to achieve.

    DS

  11. Re: Disonnecting a TCP listening socket

    On 20 sep, 00:46, David Schwartz wrote:
    > On Sep 19, 12:54*pm, true...@gmail.com wrote:
    >
    > > If it is not possible, how can web servers and other severs using TCP
    > > stop properly ?

    >
    > > Jean-Luc

    >
    > The protocol should be designed such that it is perfectly acceptable
    > for the server to close the connection before receiving or sending any
    > data. The client should interpret this as the web server being
    > unwilling or unable to serve that client at that time.
    >
    > If a protocol doesn't do this, the protocol is broken for TCP, and
    > suffers from (yet another) version of the two generals problem. That
    > is, it assumes the two ends can agree on whether a connection was
    > established or not, and that is provably impossible to achieve.
    >
    > DS


    All right. It is clear now.

    Thanks all for your help.


    Jean-Luc

  12. Re: Disonnecting a TCP listening socket

    true801@gmail.com wrote:
    > If a server program wants to stop accepting client connections, it
    > just has to close() the listening socket. By doing this, it also
    > discards the connections that are established, but that accept()
    > hasn't returned yet.
    > My question therefore is : is it possible to tell the OS to stop
    > accepting incoming connection requests, and still getting the
    > connections that are already established and waiting in the queue ?


    Will shutdown() on the listening socket do that?

  13. Re: Disonnecting a TCP listening socket

    On Sep 22, 10:59*am, Joe Beanfish wrote:
    > true...@gmail.com wrote:
    > > If a server program wants to stop accepting client connections, it
    > > just has to close() the listening socket. By doing this, it also
    > > discards the connections that are established, but that accept()
    > > hasn't returned yet.
    > > My question therefore is : is it possible to tell the OS to stop
    > > accepting incoming connection requests, and still getting the
    > > connections that are already established and waiting in the queue ?

    >
    > Will shutdown() on the listening socket do that?


    Nope. But it would be kind of cool if it did. On every platform I know
    of, 'shutdown' only works on sockets that are connected.

    DS

+ Reply to Thread