C - event_new() 函数在 HPUX 安腾上失败



我正在尝试调试使用libevent库的代码。在该库中,有一个函数event_new,它假设创建一个event_cb。不知何故,在我调度事件库后,无法调用或访问event_cb。此问题仅发生在 hpux 安腾上。此代码适用于 hpux pa-risc、Redhat、AIX 和 Solaris。有什么需要设置

的吗?

这是代码的一部分

int ttypread (int fd, Header *h, char **buf)
{
    int c,k;
    struct user_data user_data;
    struct bufferevent *in_buffer;
    struct event_config *evconfig;
    log_debug("inside ttypread");
    in_buffer = NULL;
    user_data.fd = fd;
    user_data.h = h;
    user_data.buf = buf;
    log_debug("from user_data, fd = %d",user_data.fd);  //the log_debug is a debugging function for me to check the value sent by the system. I use it to compare between each platform
    log_debug("from user_data, buf = %s",user_data.buf);
    log_debug("from user_data, h.len = %d",user_data.h->len);
    log_debug("from user_data, h.type = %d",user_data.h->type);
    evconfig = event_config_new();
    if (evconfig == NULL) {
            log_error("event_config_new failed");
            return -1;
    }
    if (event_config_require_features(evconfig, EV_FEATURE_FDS)!=0) {
            log_error("event_config_require_features failed");
            return -1;
    }
    base = event_base_new_with_config(evconfig);
    if (!base) {
            log_error("ttypread:event_base_new failed");
            return -1;
    }
    const char* method;              //these 3 lines are the new line edited
    method = event_base_get_method(base);
    log_debug("ttyread is using method = %s",method);
    ev = event_new(base, fd, EV_READ|EV_PERSIST, ttypread_event_cb, &user_data);
    c = event_add(ev, NULL);
    log_debug("ttypread passed event_add with c value is %d",c);
    in_buffer = bufferevent_socket_new(base, STDIN_FILENO, BEV_OPT_CLOSE_ON_FREE);
    log_debug("ttypread passed bufferevent_socket_new");
    if(in_buffer == NULL){
            log_debug("problem with bufferevent_socket_new");
    }
    bufferevent_setcb(in_buffer, in_read_cb, NULL, in_event_cb, NULL);
    bufferevent_disable(in_buffer, EV_WRITE);
    bufferevent_enable(in_buffer, EV_READ);
    k =event_base_dispatch(base);
    log_debug("event_base have been dispatched"); //when looking at the debugging file, the other plaform will go to ttypread_event_cb function. But for hpux itanium, it stays here.
    if (k == 0){
            log_debug("event_base_dispatch returned 0");
    } else if (k == -1){
            log_debug("event_base_dispatch returned -1");
    } else  {
            log_debug("event_base_dispatch returned 1");
    }
    event_base_free(base);
    event_free(ev);
    log_debug("finish ttypread");
    log_debug("ttypread_ret will return [%d]",ttypread_ret);
    return ttypread_ret;
}
void ttypread_event_cb(evutil_socket_t fd, short events, void *arg)
{
    int nread;
    struct timeval  t;
    struct user_data *user_data;
    user_data = (struct user_data*)arg;
    nread = 0;
    log_debug("inside ttypread_event_cb");
    if (events & EV_READ) {
            log_debug("got events & EV_READ");
            nread = ttyread(fd, user_data->h, user_data->buf);
            if (nread == -1) {
                    ttypread_ret = -1;
                    event_del(ev);
                    event_base_loopexit(base, NULL);
            } else if (nread == 0) {
                    if (access(input_filename, F_OK)!=0) {
                            log_debug("cannot access [%s]",input_filename);
                            tcsetattr(0, TCSANOW, &old);  /* Return terminal state */
                            exit(EXIT_SUCCESS);
                    }
                    t.tv_sec = 0;
                    t.tv_usec = 250000;
                    select(0, 0, 0, 0, &t);
            } else {
                    ttypread_ret = 1;
                    event_del(ev);
                    event_base_loopexit(base, NULL);
            }
    }
    else if (events & EV_WRITE) {
    log_debug("got events & EV_WRITE");
    }
}

不确定这是否有帮助。但只是关于 hpux 安腾的一些信息

uname -a = HP-UX hpux-ita B.11.23 U ia64

如果您需要任何其他信息或其他功能声明,只需发表评论,我将编辑问题。

编辑:我在ttypread中添加了一个函数。不知何故,对于 hpux itanium 来说,它返回的 devpoll 而其他平台正在返回民意调查。我不确定这是否是问题所在。但如果是这样,我有什么办法可以改变它吗?

在检查了event_base_get_method的结果后,我发现只有在我的 hpux-itanium 上使用 devpoll 方法。这就是我解决它的方式。

    char string[8] = "devpoll";
    struct user_data user_data;
    struct bufferevent *in_buffer;
    struct event_config *evconfig;
    const char *method;
    const char *devpoll;
    devpoll = string;
    in_buffer = NULL;
    user_data.fd = fd;
    user_data.h = h;
    user_data.buf = buf;
    evconfig = event_config_new();
    if (evconfig == NULL) {
            log_error("event_config_new failed");
            return -1;
    }
    if (event_config_require_features(evconfig, EV_FEATURE_FDS)!=0) {
            log_error("event_config_require_features failed");
            return -1;
    }
    if (event_config_avoid_method(evconfig,devpoll) != 0)
    {
            log_error("Failed to ignore devpoll method");
    }

强制 libevent 忽略使用 devpoll 并改用 poll。

相关内容

  • 没有找到相关文章

最新更新