zoukankan      html  css  js  c++  java
  • vtun 中的__io_canceled变量和相关函数

    1、__io_canceled在lib.h中定义,

    /* IO cancelation */
    extern volatile sig_atomic_t __io_canceled;

     

    __io_canceled变量影响下列函数,

    static inline int read_n(int fd, char *buf, int len)
    {
        register int t=0, w;

        while (!__io_canceled && len > 0)
        {
            if( (w = read(fd, buf, len)) < 0 )
            {
            if( errno == EINTR || errno == EAGAIN )
            continue;
            return -1;
            }
            if( !w )
                return 0;
            len -= w; buf += w; t += w;
        }

        return t;
    }  

    static inline int write_n(int fd, char *buf, int len)
    {
        register int t=0, w;

        while (!__io_canceled && len > 0)
        {
            if( (w = write(fd, buf, len)) < 0 )
            {
                if( errno == EINTR || errno == EAGAIN )
                    continue;
                return -1;
            }
            if( !w ) return 0;
            len -= w; buf += w; t += w;
        }

        return t;
    }

    2、下面的函数改变__io_canceled变量,

    static inline void io_init(void)
    {
        __io_canceled = 0;
    }

    static inline void io_cancel(void)
    {
        __io_canceled = 1;
    }

    3、

    而io_cancel函数在下面函数中调用,

    static void sig_term(int sig)
    {
        vtun_syslog(LOG_INFO, "Closing connection");
        io_cancel();
        linker_term = VTUN_SIG_TERM;
    }

    static void sig_hup(int sig)
    {
        vtun_syslog(LOG_INFO, "Reestablishing connection");
        io_cancel();
        linker_term = VTUN_SIG_HUP;
    }

    4、

    当内核发出退出或挂起等信号时,会调用sig_term或sig_hup函数,从而改变__io_canceled的值,从而停止read_n  write_n.

  • 相关阅读:
    ES 遇到 unassigned shard如何处理?
    elasticsearch如何安全重启
    Agg学习笔记
    二进制文件中读写结构体
    C语言 结构体数组保存到二进制文件中
    Memcache 笔记
    memcached完全剖析–1. memcached的基础
    Redis和Memcache对比及选择
    Exploring the MapBox stack: MBTiles, TileJSON, UTFGrids and Wax
    Tilemill + tilestream + mapbox.js 自制地图
  • 原文地址:https://www.cnblogs.com/helloweworld/p/2704235.html
Copyright © 2011-2022 走看看