zoukankan      html  css  js  c++  java
  • libevent linux安装

    wget http://monkey.org/~provos/libevent-1.4.13-stable.tar.gz
    wget http://downloads.sourceforge.net/levent/libevent-2.0.22-stable.tar.gz
    tar –xzvf libevent-1.4.13-stable.tar.gz
    tar -xzvf libevent-2.0.22-stable.tar.gz
    cd libevent-1.4.13-stable
    ./configure --prefix=/home/mydir/libevent
    不指定prefix,则可执行文件默认放在/usr /local/bin,
    库文件默认放在/usr/local/lib,
    配置文件默认放在/usr/local/etc。
    其它的资源文件放在/usr /local/share。
    你要卸载这个程序,要么在原来的make目录下用一次make uninstall(前提是make文件指定过uninstall),要么去上述目录里面把相关的文件一个个手工删掉。
    指定prefix,直接删掉一个文件夹就够了。
    make && make install

    src:main.cpp

    /*
    * XXX This sample code was once meant to show how to use the basic Libevent
    * interfaces, but it never worked on non-Unix platforms, and some of the
    * interfaces have changed since it was first written. It should probably
    * be removed or replaced with something better.
    *
    * Compile with:
    * cc -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -levent
    */

    #include <sys/types.h>

    #include <event2/event-config.h>

    #include <sys/stat.h>
    #ifndef WIN32
    #include <sys/queue.h>
    #include <unistd.h>
    #endif
    #include <time.h>
    #ifdef _EVENT_HAVE_SYS_TIME_H
    #include <sys/time.h>
    #endif
    #include <fcntl.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <errno.h>

    #include <event2/event.h>
    #include <event2/event_struct.h>
    #include <event2/util.h>

    #ifdef WIN32
    #include <winsock2.h>
    #endif

    struct timeval lasttime;

    int event_is_persistent;

    static void
    timeout_cb(evutil_socket_t fd, short event, void *arg)
    {
    struct timeval newtime, difference;
    struct event *timeout = (struct event *)arg;
    double elapsed;

    evutil_gettimeofday(&newtime, NULL);
    evutil_timersub(&newtime, &lasttime, &difference);
    elapsed = difference.tv_sec +
    (difference.tv_usec / 1.0e6);

    printf("timeout_cb called at %d: %.3f seconds elapsed. ",
    (int)newtime.tv_sec, elapsed);
    lasttime = newtime;

    if (! event_is_persistent) {
    struct timeval tv;
    evutil_timerclear(&tv);
    tv.tv_sec = 2;
    event_add(timeout, &tv);
    }
    }

    int
    main(int argc, char **argv)
    {
    struct event timeout;
    struct timeval tv;
    struct event_base *base;
    int flags;

    #ifdef WIN32
    WORD wVersionRequested;
    WSADATA wsaData;

    wVersionRequested = MAKEWORD(2, 2);

    (void)WSAStartup(wVersionRequested, &wsaData);
    #endif

    if (argc == 2 && !strcmp(argv[1], "-p")) {
    event_is_persistent = 1;
    flags = EV_PERSIST;
    } else {
    event_is_persistent = 0;
    flags = 0;
    }

    /* Initalize the event library */
    base = event_base_new();

    /* Initalize one event */
    event_assign(&timeout, base, -1, flags, timeout_cb, (void*) &timeout);

    evutil_timerclear(&tv);
    tv.tv_sec = 2;
    event_add(&timeout, &tv);

    evutil_gettimeofday(&lasttime, NULL);

    event_base_dispatch(base);

    return (0);
    }


    g++ main.cpp -L./libevent/lib -levent -I./libevent/include/
    export LD_LIBRARY_PATH=/home/shengkaishan/work/libevent/lib/:$LD_LIBRARY_PATH
  • 相关阅读:
    如何组建开发团队-建立畅通的沟通渠道
    如何组建开发团队-激励团队气势
    文件夹名与类名一致造成的命名空间无法识别的问题
    SQL Server 还原错误“restore database正在异常终止 错误 3154”
    S​Q​L​ ​S​e​r​v​e​r​ ​服务无法启动,错误1069解决办法
    无法升级数据库....因为此版本的 SQL Server 不支持该数据库的非发布版本(539) 解决方案
    图解Microsoft SQL Server——“远程过程调用失败 [0x800706be] 错误“。
    Eclipse: Android Device Chooser
    部署网站时的错误“one of its dependencies.试图加载格式不正确的程序。”解决方案。
    把char赋值到string里面
  • 原文地址:https://www.cnblogs.com/kaishan1990/p/4895284.html
Copyright © 2011-2022 走看看