1 #include<stdio.h>
2 #include<evhttp.h>
3
void
test_handle(
struct
evhttp_request *r,
void
*u){
4 u_char *buf;
5 buf=EVBUFFER_DATA(r->input_buffer);
6 evhttp_send_reply(r,200,
"read ok!"
,NULL);
7
printf
(
"the host is: %s \n"
,r->remote_host);
8
printf
(
"the data is:\n%s\n"
,buf);
9
return
;
10 }
11
int
main(
void
){
13
struct
event_base *base;
14
struct
evhttp *http;
15 base =event_base_new();
16 http=evhttp_new(base);
17
if
(!http){
18
perror
(
"evhttp_new() failed"
);
19
return
-1;
20 }
21
if
(evhttp_bind_socket(http,
"0.0.0.0"
,8080)){
22
perror
(
"bind_sock() failed"
);
23
return
-1;
24 }
25
//evhttp_set_cb(http,"/",test_handle,NULL);
26 evhttp_set_gencb(http,test_handle,NULL);
27 event_base_dispatch(base);
28 evhttp_free(http);
29 event_base_free(base);
30
return
0;
31 }