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;
    }
    
  • 相关阅读:
    IB(InterBase Server) 的完整连接格式
    jna
    编写基于Prototype的Javascript动画类
    Go——使用 go mod ——有依赖的Go工程
    pkgconfig—— PKG_CONFIG_PATH——Makefile——pkgconfig的作用与使用
    Go——Goland Debug报错Version of Delve is too old for this version of Go
    NATS——NATS Streaming 是什么 (转)
    Go——Go语言调用C语言
    go get安装包超时处理
    NATS—基础介绍 (转自 https://www.cnblogs.com/yorkyang/p/8392172.html)
  • 原文地址:https://www.cnblogs.com/yangyingchao/p/3855547.html
Copyright © 2011-2022 走看看