Re: [Libevent-users] file io
Thanks William, you tell me (and help me) a lot. So looks I will output the trace to a socket port and create a receiver to write it to disk. Cheers, Arthur On 10/9/07, William Ahern <[EMAIL PROTECTED]> wrote: > > On Tue, Oct 09, 2007 at 11:06:21AM -0400, arthur zhang wrote: > > Hi All, > > > > As my understanding, with libevent, any io should be non_blocking, and > here > > comes my dumb q;-) > > > > I want log stuffs(trace) to a disk file in my comm callback, so I open a > > file like below, but I didn't get any write event to call back. I am > using > > Ubuntu Dapper and my target system is Solaris 10. > > 1) You can't do non-blocking file I/O in Unix using the standard > interfaces. >You need to use a horrible and poorly implemented interfaces like POSIX >Asynchronous I/O, which is impossible to use with libevent. > > 2) A file descriptor (to a realfile) will _always_ poll as ready for > reading >or writing. (The logic being, even though the disk might be slow, it's >still always available for I/O--the disk is one gigantic buffer.) Thus, >if your code was written properly your complaint should have been that >you got an endless succession of write readiness callbacks suspicously >lacking any gap. > > > Using stdout worked. > > If stdout was a pipe, then it would work. Thus, you could shamefully (but > with good reason) pipe to cat, and redirect cat's stdout to a file. > ___ Libevent-users mailing list Libevent-users@monkey.org http://monkey.org/mailman/listinfo/libevent-users
[Libevent-users] problem with Sigint and http events
Hi, I'm not a good expert of C, but trying to build a simple example using libevent. I've succesfully build a very simple http server with the stupid "Hello World" message. Now I'm trying to capture a SIGINT as shown in "sample/signal-test.c" present in the libevent tar file. Unfortunately, I receive a segmentation fault " *** glibc detected *** ./test: double free or corruption (!prev): 0x0804f1e0 *** === Backtrace: = /lib/libc.so.6[0xb7e54c06] /lib/libc.so.6(cfree+0x89)[0xb7e568c9] /usr/lib/libevent-1.3d.so.1(evhttp_free+0x4f)[0xb7f5933f] ./test(signal_cb+0x55)[0x8048995] /usr/lib/libevent-1.3d.so.1(event_base_loop+0x242)[0xb7f56832] /usr/lib/libevent-1.3d.so.1(event_loop+0x29)[0xb7f56ac9] /usr/lib/libevent-1.3d.so.1(event_dispatch+0x1e)[0xb7f56aee] ./test[0x804891a] /lib/libc.so.6(__libc_start_main+0xe0)[0xb7e04f90] " Does some can exaplain it ? If I remove the http_free(http_server) command, the process never stop any more ;-(. I need to use a "kill -9" to stop it. Why this is so ? is there some event not yet complete ? Thanks. ANNEXE: test.c: --- 1: #include 2: #ifdef WIN32 3: #include 4: #include 5: #endif 6: 7: #ifdef HAVE_CONFIG_H 8: #include "config.h" 9: #endif 10: 11: #include 12: #include 13: #ifdef HAVE_SYS_TIME_H 14: #include 15: #endif 16: #include 17: #ifndef WIN32 18: #include 19: #include 20: #include 21: #endif 22: #include 23: #include 24: #include 25: #include 26: #include 27: #include 28: 29: #include "event.h" 30: #include "evhttp.h" 31: #include "log.h" 32: #include "http-internal.h" 33: 34: struct evhttp* httpd; 35: 36: void root_handler( struct evhttp_request *req, void *arg) 37: { 38: struct evbuffer *evb=evbuffer_new(); 39: evbuffer_add_printf(evb, "Hello World!"); 40: printf("Request from %s:", req->remote_host); 41: printf("%i\n", req->remote_port); 42: evhttp_send_reply(req, HTTP_OK, "OK", evb); 43: evbuffer_free(evb); 44: } 45: 46: 47: int called = 0; 48: 49: void 50: signal_cb(int fd, short event, void *arg) 51: { 52: struct event *signal = arg; 53: 54: printf("got signal %d\n", EVENT_SIGNAL(signal)); 55: if (called >= 2) 56: event_del(signal); 57: evhttp_free(httpd); 58: called++; 59: } 60: 61: 62: 63: int main(int argc, char **argv) 64: { 65: struct event signal_int; 66: event_init(); 67: event_set(&signal_int, SIGINT, EV_SIGNAL|EV_PERSIST, signal_cb, &signal_int); 68: event_add(&signal_int, NULL); 69: httpd=evhttp_start("0.0.0.0", 8080); 70: evhttp_set_cb(httpd, "/", root_handler, NULL); 71: printf("start dispatch\n"); 72: event_dispatch(); 73: printf("stop dispatch\n"); 74: return 0; 75: } 76: compilation commands: - gcc -g -O3 -Wall -Wstrict-prototypes -fPIC -I/var/abs/local/libevent/src/libevent-1.3b -I/usr/include/python2.5 -c test.c -o test.o gcc -g -O2 -Wall -o test test.o -levent -lnsl -lrt -lresolv ___ Libevent-users mailing list Libevent-users@monkey.org http://monkey.org/mailman/listinfo/libevent-users
Re: [Libevent-users] file io
On Tue, Oct 09, 2007 at 11:06:21AM -0400, arthur zhang wrote: > Hi All, > > As my understanding, with libevent, any io should be non_blocking, and here > comes my dumb q;-) > > I want log stuffs(trace) to a disk file in my comm callback, so I open a > file like below, but I didn't get any write event to call back. I am using > Ubuntu Dapper and my target system is Solaris 10. 1) You can't do non-blocking file I/O in Unix using the standard interfaces. You need to use a horrible and poorly implemented interfaces like POSIX Asynchronous I/O, which is impossible to use with libevent. 2) A file descriptor (to a realfile) will _always_ poll as ready for reading or writing. (The logic being, even though the disk might be slow, it's still always available for I/O--the disk is one gigantic buffer.) Thus, if your code was written properly your complaint should have been that you got an endless succession of write readiness callbacks suspicously lacking any gap. > Using stdout worked. If stdout was a pipe, then it would work. Thus, you could shamefully (but with good reason) pipe to cat, and redirect cat's stdout to a file. ___ Libevent-users mailing list Libevent-users@monkey.org http://monkey.org/mailman/listinfo/libevent-users
[Libevent-users] Re: Multithreads event_add problem
Hi, I've add event_base_set before event_add, now it seems that it works. On 10/9/07, Quan Sun <[EMAIL PROTECTED]> wrote: > Hi, > > These days I'm working on a web client project. The design is rather > simple, and I use two threads. > > One thread creates sockets, with a given time-varing speed, then these > sockets are passed to second thread. The second thread is a > event_dispatch(), it perform all the actual work. > > My question is, what is the best method to pass events between thread? > I used event_add in first thread, and these two threads share event. > But it seems that libevent is leaking fds in this case, I've read some > of 1.2a's codes, libevent itself does not have thread lock in > event_add. > > -- > > Quan Sun > -- -- 世界很大, 时间很长。 Quan Sun ___ Libevent-users mailing list Libevent-users@monkey.org http://monkey.org/mailman/listinfo/libevent-users
[Libevent-users] Multithreads event_add problem
Hi, These days I'm working on a web client project. The design is rather simple, and I use two threads. One thread creates sockets, with a given time-varing speed, then these sockets are passed to second thread. The second thread is a event_dispatch(), it perform all the actual work. My question is, what is the best method to pass events between thread? I used event_add in first thread, and these two threads share event. But it seems that libevent is leaking fds in this case, I've read some of 1.2a's codes, libevent itself does not have thread lock in event_add. -- Quan Sun ___ Libevent-users mailing list Libevent-users@monkey.org http://monkey.org/mailman/listinfo/libevent-users
[Libevent-users] file io
Hi All, As my understanding, with libevent, any io should be non_blocking, and here comes my dumb q;-) I want log stuffs(trace) to a disk file in my comm callback, so I open a file like below, but I didn't get any write event to call back. I am using Ubuntu Dapper and my target system is Solaris 10. Using stdout worked. Thanks. Arthur - fdmsg = open(glbCfg.msg_file, O_WRONLY|O_CREAT|O_APPEND|O_NONBLOCK, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if(fdmsg<0) { err(-1, "Can't open file to write %s", glbCfg.msg_file); } //fdmsg = fileno(stdout); if(fcntl(fdmsg, F_SETFL, O_NONBLOCK)==-1) { err(-1, "fcntl"); } rcd = io_new_sink(fdmsg); printf("rcd %p %d\n", rcd, fdmsg); ___ Libevent-users mailing list Libevent-users@monkey.org http://monkey.org/mailman/listinfo/libevent-users