def write(s)
      if idle_timeout
        if (t=Time.now) > @last_write + idle_timeout
          @socket.close rescue nil
          connect
        else
          @last_write = t
        end
      end
      begin
        retry_id ||= 0
        do_write(s)
      rescue => e
        if (retry_id += 1) < @retries
          @socket.close rescue nil
          connect
          retry
        else
          raise e
        end
      end
    end
def write(s)
      if idle_timeout
        if (t=Time.now) > @last_write + idle_timeout
          @socket.close rescue nil
          connect
        else
          @last_write = t
        end
      end
      begin
        retry_id ||= 0
        do_write(s)
      rescue => e
        if (retry_id += 1) < @retries
          @socket.close rescue nil
          connect
          retry
        else
          raise e
        end
      end
    end
Allow to retry on failed writes