I think when the connection is closed in #post_init, further #sysreads will
fail, and send a ConnectionUnbound to the event callback, therefore
removing the connection.
I''m not sure if it''s the cleanest way and I didn''t
test it on many
different machines, but trying out your snippet, it works without the @skip
parts:
> def post_init # do rate limiting here
> port, ip = Socket.unpack_sockaddr_in(self.get_peername)
> if ip == "192.168.11.9"
> send_data "denied\n"
> close_connection_after_writing
> end
> end
>
> def receive_data(data)
> send_data "thanks!\n"
> close_connection_after_writing
> end
> end
And returns "denied\n" without "thanks!\n" as expected.
> $ telnet igloo 4300
> Trying 192.168.11.9...
> Connected to igloo.
> Escape character is ''^]''.
> denied
> Connection closed by foreign host.
Cheers,
-Ripta