• 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;
    }
    
  • 相关阅读:
    博客园 投放 谷歌广告(google adsense) 且不被屏蔽掉
    JAVA与C#程序调用DOS命令
    redhat 5 安装apache 2.2
    解决"Windows 安装程序不允许从远程桌面连接安装"
    测试使用windows live writer的adsense coder发布文章
    解决:apache 整合redmine 启动报错 mod_passenger.so: failed to map segment from shared object: Permission denied
    企业级安全服务权限控制 Acegi安装系统介绍 Spring Framework安全系统
    解决Rails升级问题
    解决MyEclipse 7开发EXTJS 每次保存都要编译js的导致开发效率很低的问题
    解决:redmine 安装 rake db:migrate encoding: utf8
  • 原文地址:https://www.cnblogs.com/yangyingchao/p/3855547.html
Copyright © 2020-2023  润新知