code: def set_tcp_keepalive(socket, config):
      
  
      keepalive_options = {
          # Map fedmsg config keys to zeromq socket constants
          'zmq_tcp_keepalive': 'TCP_KEEPALIVE',
          'zmq_tcp_keepalive_cnt': 'TCP_KEEPALIVE_CNT',
          'zmq_tcp_keepalive_idle': 'TCP_KEEPALIVE_IDLE',
          'zmq_tcp_keepalive_intvl': 'TCP_KEEPALIVE_INTVL',
      }
      for key, const in keepalive_options.items():
          if key in config:
              attr = getattr(zmq, const, None)
              if attr:
                  socket.setsockopt(attr, config[key])
docs: Set a series of TCP keepalive options on the socket if
      and only if
        1) they are specified explicitly in the config and
        2) the version of pyzmq has been compiled with support
  
      We ran into a problem in FedoraInfrastructure where long-standing
      connections between some hosts would suddenly drop off the
      map silently.  Because PUB/SUB sockets don't communicate
      regularly, nothing in the TCP stack would automatically try and
      fix the connection.  With TCP_KEEPALIVE options (introduced in
      libzmq 3.2 and pyzmq 2.2.0.1) hopefully that will be fixed.
  
      See the following
        - http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html
        - http://api.zeromq.org/3-2:zmq-setsockopt