zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    排序方法之冒泡排序
    JAVA浮点数的范围 和精度
    史上最全的SPRING注解
    ETL应用:使用Pro*C写入文件信息入库的方法
    MySQL查询优化器工作原理解析
    php通过Mysqli和PDO连接mysql数据详解
    PHP实现各种经典算法
    http协议的状态码——400,401,403,404,500,502,503,301,302等常见网页错误代码
    程序中使用ajax时,type为put,或者delete时在 IIS上没效果,发生HTTP Error 405.0
    linux定时任务crontab
  • 原文地址:https://www.cnblogs.com/yangyingchao/p/3855547.html
Copyright © 2011-2022 走看看