Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#282 crash on iocp

For_2.0
closed-fixed
nobody
5
2012-07-16
2012-07-15
run_mei
No

cpp code

#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <signal.h>

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

static const int PORT = 9995;

static void
listener_cb(struct evconnlistener *listener, evutil_socket_t fd,
struct sockaddr *sa, int socklen, void *user_data)
{
}

int
main(int argc, char **argv)
{
struct event_config *evcfg;
struct event_base *base;
struct evconnlistener *listener;

struct sockaddr_in sin;
WSADATA wsa_data;
WSAStartup(0x0201, &wsa_data);

evcfg = event_config_new();
event_config_set_flag(evcfg, EVENT_BASE_FLAG_STARTUP_IOCP);
base = event_base_new_with_config(evcfg);
//base = event_base_new();
if (!base) {
fprintf(stderr, "Could not initialize libevent!\n");
return 1;
}

memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(PORT);

listener = evconnlistener_new_bind(base, listener_cb, (void *)base,
LEV_OPT_REUSEABLE|LEV_OPT_CLOSE_ON_FREE, -1,
(struct sockaddr*)&sin,
sizeof(sin));

if (!listener) {
fprintf(stderr, "Could not create a listener!\n");
return 1;
}

event_base_dispatch(base);
return 0;
}
========================
win7
msvc

Discussion

  • run_mei
    run_mei
    2012-07-15

    error message as follows:

    http-server.exe 中的 0x009d3761 处有未经处理的异常: 0xC0000005: 读取位置 0x00000004 时发生访问冲突

    error stacktrace as follows:
    > http-server.exe!evutil_tv_to_msec(const timeval * tv) 行 2133 + 0x3 字节 C
    http-server.exe!win32_dispatch(event_base * base, timeval * tv) 行 301 + 0x9 字节 C
    http-server.exe!event_base_loop(event_base * base, int flags) 行 1603 + 0x12 字节 C
    http-server.exe!event_base_dispatch(event_base * event_base) 行 1446 + 0xb 字节 C
    http-server.exe!main(int argc, char * * argv) 行 406 + 0x9 字节 C
    http-server.exe!__tmainCRTStartup() 行 555 + 0x19 字节 C
    http-server.exe!mainCRTStartup() 行 371 C
    kernel32.dll!@BaseThreadInitThunk@12() + 0x12 字节
    ntdll.dll!___RtlUserThreadStart@8() + 0x27 字节
    ntdll.dll!__RtlUserThreadStart@8() + 0x1b 字节

    reason is :

    tv is NULL

    long evutil_tv_to_msec(const struct timeval *tv)
    {
    if (tv->tv_usec > 1000000 || tv->tv_sec > MAX_SECONDS_IN_MSEC_LONG)
    return -1;

    return (tv->tv_sec * 1000) + ((tv->tv_usec + 999) / 1000);
    }

     
  • Nick Mathewson
    Nick Mathewson
    2012-07-16

    What version of libevent?

     
  • Nick Mathewson
    Nick Mathewson
    2012-07-16

    Also, it looks like you enabled IOCP without enabling threading. That's going to make the whole subsystem not work. You need to call evthread_use_windows_threads() before creating an event base.

     
  • Nick Mathewson
    Nick Mathewson
    2012-07-16

    That said, the issue that turned this into a crash should be fixed in 160e58b67d28967bc7b1800835a082bcd7052d82

     
  • Nick Mathewson
    Nick Mathewson
    2012-07-16

    • status: open --> closed-fixed