- 论坛徽章:
- 0
|
#include <sys/types.h>
#include <sys/time.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <time.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <assert.h>
#include <signal.h>
#include <stdbool.h>
#include <err.h>
#include <event.h>
#include <evhttp.h>
#define VERSION "1.1"
/* 处理模块 */
void httpsqs_handler(struct evhttp_request *req, void *arg)
{
struct evbuffer *buf;
buf = evbuffer_new();
evbuffer_add_printf(buf, "%s", "hello..........");
/* 输出内容给客户端 */
evhttp_send_reply(req, HTTP_OK, "OK", buf);
/* 内存释放 */
evbuffer_free(buf);
}
int main(int argc, char **argv)
{
char *httpsqs_settings_listen = "0.0.0.0";
int httpsqs_settings_port = 80;
int httpsqs_settings_timeout = 1; /* 单位:秒 */
/* 请求处理部分 */
struct evhttp *httpd;
event_init();
httpd = evhttp_start(httpsqs_settings_listen, httpsqs_settings_port);
evhttp_set_timeout(httpd, httpsqs_settings_timeout);
evhttp_set_gencb(httpd, httpsqs_handler, NULL);
event_dispatch();
evhttp_free(httpd);
return 0;
} |
|