There is a basic example in the attachment. compilation: arm_v5t_le-gcc -I libevent-1.4.9-stable/compat/ -I libevent-1.4.9-stable -L ./lib/ test_http.c -levent -lrt -g -Wall
execution: client: $httperf --client=0/1 --server=192.168.1.6 --port=8084 --uri=/a.out --send-buffer=4096 --recv-buffer=16384 --num-conns=10 --num-calls=100000 server: #./a.out .... new client, sending a.out done new client, sending a.out done new client, sending a.out done new client, sending a.out done ..... Segmentation fault (core dumped) # /usr/bin/gdb ./a.out core GNU gdb 6.3 (MontaVista 6.3-20.0.66.0600975 2006-07-05) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "armv5tl-montavista-linuxeabi"...Using host libthread_db library "/lib/libthread_db.so.1". Core was generated by `./a.out'. Program terminated with signal 11, Segmentation fault. Reading symbols from /lib/librt.so.1...done. Loaded symbols for /lib/librt.so.1 Reading symbols from /lib/tls/libc.so.6...done. Loaded symbols for /lib/tls/libc.so.6 Reading symbols from /lib/tls/libpthread.so.0...done. Loaded symbols for /lib/tls/libpthread.so.0 Reading symbols from /lib/ld-linux.so.3...done. Loaded symbols for /lib/ld-linux.so.3 #0 epoll_dispatch (base=0x0, arg=0x2180c, tv=0x1f408) at ../libevent-1.4.9-stable/epoll.c:232 232 evwrite = evep->evwrite; (gdb) p evep $1 = (struct evepoll *) 0x0 (gdb) bt #0 epoll_dispatch (base=0x0, arg=0x2180c, tv=0x1f408) at ../libevent-1.4.9-stable/epoll.c:232 #1 0x0000a928 in event_base_loop (base=0x1b008, flags=0) at ../libevent-1.4.9-stable/event.c:530 #2 0x0000955c in main (argc=1, argv=0xbefffeb4) at test_http.c:98 2009/3/26 <valery+libev...@grid.net.ru>: > > Do you get SIGSEGV or SIGBUS? Because it might be an alignment issue. > > I either case, what is your stack trace? > > ----- Original Message ----- > From: "Alexey Ozeritsky" <aozerit...@gmail.com> > To: libevent-users@monkey.org > Sent: Friday, March 20, 2009 1:40:53 PM GMT +01:00 Amsterdam / Berlin / Bern > / Rome / Stockholm / Vienna > Subject: [Libevent-users] libevent and arm > > Hello, > > A few months ago I discovered a problem with libevent and arm architecture. > I have TI DM355 board with montavista distribution, kernel > Linux testarm 2.6.10_mvl401 #8 Wed Mar 18 15:04:34 MSK 2009 armv5tejl unknown > > My embedded libevent-based http server unexpectedly crashed. Then I > set variable EVENT_NOEPOLL=1 and everything went well. > The problem appears in the all libevent versions including the latest > 1.4.9. Today I tried to discover the problem with gdb and made this > patch (attached): > > Index: epoll.c > =================================================================== > --- epoll.c (revision 5589) > +++ epoll.c (revision 5590) > @@ -141,7 +141,7 @@ > epollop->epfd = epfd; > > /* Initalize fields */ > - epollop->events = malloc(nfiles * sizeof(struct epoll_event)); > + epollop->events = calloc(nfiles, sizeof(struct epoll_event)); > if (epollop->events == NULL) { > free(epollop); > return (NULL); > @@ -226,6 +226,7 @@ > struct event *evread = NULL, *evwrite = NULL; > > evep = (struct evepoll *)events[i].data.ptr; > + if (!evep) continue; > > if (what & (EPOLLHUP|EPOLLERR)) { > evread = evep->evread; > > It works OK now, but I'm not sure I made a correct patch. And I don't > understand why it doesn't segfaulted on x86_64 or x86 architecture. > > _______________________________________________ > Libevent-users mailing list > Libevent-users@monkey.org > http://monkeymail.org/mailman/listinfo/libevent-users > _______________________________________________ > Libevent-users mailing list > Libevent-users@monkey.org > http://monkeymail.org/mailman/listinfo/libevent-users >
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <event.h> #include <evhttp.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <signal.h> #include <errno.h> /* libevent 1.4.8 or better !!! */ const char * get_fname (const char * uri) { return uri + 1; } int do_all (struct evhttp_request * req) { const char * uri = evhttp_request_uri (req); #define BUF_SIZ 4096 char buf[BUF_SIZ]; int bytes; const char * file = get_fname (uri); FILE * f = fopen (file, "rb"); while ( (bytes = fread (buf, 1, BUF_SIZ, f) ) > 0) { struct evbuffer *answer = evbuffer_new(); evbuffer_add (answer, buf, bytes); evhttp_send_reply_chunk (req, answer); evbuffer_free (answer); } { /* end */ evhttp_send_reply_end (req); fprintf (stderr, " done \n"); } fclose (f); #undef BUF_SIZ return 0; } void gen_cb (struct evhttp_request * req, void * arg) { const char * uri = evhttp_request_uri (req); FILE * f = fopen (get_fname (uri), "rb"); if (!f) { fprintf (stderr, "new client, sending 404: %s \n", uri); evhttp_send_reply_start (req, HTTP_NOTFOUND, "not found"); return; } fclose (f); fprintf (stderr, "new client, sending %s\n", get_fname (uri) ); evhttp_add_header (req->output_headers, "Content-Type", "video/x-msvideo"); evhttp_send_reply_start (req, HTTP_OK, "OK"); do_all (req); } typedef void (*sig_handler_t) (int); void set_signal (int signo, sig_handler_t hndl) { struct sigaction sa; sa.sa_handler = hndl; sigemptyset (&sa.sa_mask); sigaddset (&sa.sa_mask, signo); sa.sa_flags = 0; if (sigaction (signo, &sa, NULL) < 0) { fprintf (stderr, "can't catch signal %d: %s\n", signo, strerror (errno) ); exit (1); } } int main (int argc, char * argv[]) { struct event_base *base = event_base_new(); struct evhttp * http = evhttp_new (base); set_signal(SIGPIPE, SIG_IGN); evhttp_set_gencb (http, gen_cb, 0); evhttp_bind_socket (http, "0.0.0.0", 8084); event_base_dispatch (base); return 0; }
_______________________________________________ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users