Hi,
I took some testing but the keepalive works as it is suppose to. The default timer is 2 hours so unless you change it you will be waiting a long time before anything happens. If you build the kernel with sysctl support you can change the values through the proc file system. They live in /proc/sys/net/ipv4 you should change both tcp_keepalive_time & tcp_keepalive_intvl to shorter values. If you change these values it is global so all sockets opened after the change will use the new values. If you want the change to be only for a specific socket use the setsockopt with the level IPPROTO_TCP and the option name TCP_KEEPIDLE & TCP_KEEPINTVL. You could also change the option TCP_KEEPCNT to change the number of probes before it take action (default is 9).
To detect a failure you need have a read posted and you will receive a read timeout error.
Hope this helps.