• How to detect whether socket is still connected...


    How to detect whether socket is still connected…

    From wget source code…

    bool
    test_socket_open (int sock)
    {
      fd_set check_set;
      struct timeval to;
      int ret = 0;
    
      /* Check if we still have a valid (non-EOF) connection.  From Andrew
       * Maholski's code in the Unix Socket FAQ.  */
    
      FD_ZERO (&check_set);
      FD_SET (sock, &check_set);
    
      /* Wait one microsecond */
      to.tv_sec = 0;
      to.tv_usec = 1;
    
      ret = select (sock + 1, &check_set, NULL, NULL, &to);
    #ifdef WINDOWS
    /* gnulib select() converts blocking sockets to nonblocking in windows.
    wget uses blocking sockets so we must convert them back to blocking
    */
      set_windows_fd_as_blocking_socket ( sock );
    #endif
    
      if ( !ret )
        /* We got a timeout, it means we're still connected. */
        return true;
      else
        /* Read now would not wait, it means we have either pending data
           or EOF/error. */
        return false;
    }
    
  • 相关阅读:
    csv与xlsx导出
    行业报告
    How JavaScript works: an overview of the engine, the runtime, and the call stack
    CAS单点登陆/oAuth2授权登陆
    YChaos生成混沌图像
    Why数学图像生成工具
    WHY数学图形可视化工具(开源)
    WHY翻写NEHE与红龙的3D图形程序 [开源]
    四边形密铺平面
    数学图形(1.50)三曲线
  • 原文地址:https://www.cnblogs.com/yangyingchao/p/3855547.html
Copyright © 2020-2023  润新知