05-30-06 06:15 PM
aamesster@googlemail.com wrote On 05/30/06 10:58,:
> Hi all,
>
> I've been wondering how to reject a connection? Instead of accept() I
> would like to "decline()" a connection. The only way of rejecting
> connections I've thought about is to accept() and then close()
> immediatelly. But would the other end actually receive the accept and
> then the connection would be dropped?
The other end never "receives the accept" because even
in normal operation, accept() doesn't transmit anything.
The socket returned by accept() has already completed its
three-way handshake and is in the connected state; the fact
that accept() returns is just bookkeeping on the listening
side and does not affect the connection at all.
When you close the connection, the other end's TCP/IP
stack will learn about it fairly promptly in the course
of events for a normal shutdown. The application on the
other end probably won't learn about the disconnect until
it tries to send or receive something.
As for "rejecting" connections -- well, the simplest
way is never to listen() in the first place. But assuming
that you want to permit some connections while forbidding
others, it follows that you must listen() and accept().
After accept() returns you can make your decision and either
communicate or close.
--
Eric.Sosman@sun.com
[ Post a follow-up to this message ]
|