📄 test-linux.cpp
字号:
#include "cHttpsvr.h"
extern "C"
{
#include <stdio.h>
#include <signal.h>
}
using namespace std;
using namespace yyc;
int exit_flag=0;//程序是否退出标志,==1时,结束运行
void handler(int signo)
{
static pid_t pid=0;
if (pid==0)
pid=getpid();
else
{
if (signo==SIGINT&&pid==getpid())
{
printf("program ended by ctrl-c\n");
exit_flag=1;
}
} //?else
}
int http_test(cSocket * psock,cHttpreq * phttpreq)
{
const char *ptr=phttpreq->get_para("timer");
if (ptr!=NULL) {
psock->send("<html><head><META HTTP-EQUIV=REFRESH CONTENT=%s><title>runway:sms-gw</title></head><body>",ptr);
}
else
psock->send("<html><head><title>runway:sms-gw</title></head><body>");
psock->send("<img src=runway.gif> test</body></html>");
return 0;
}
int main(void)
{
struct sigaction sa_new;
handler(0); //初始化父线程ID
//设置结束消息处理函数
sa_new.sa_handler = handler;
sigemptyset(&sa_new.sa_mask);
sa_new.sa_flags =0;//SA_SIGINFO;
sigaction(SIGINT, &sa_new, NULL);
//屏蔽SIGALRM消息
sa_new.sa_handler = handler;
sigemptyset(&sa_new.sa_mask);
sa_new.sa_flags =0;//SA_SIGINFO;
sigaction(SIGALRM, &sa_new, NULL);
//屏蔽SIGPIPE消息
sa_new.sa_handler = handler;
sigemptyset(&sa_new.sa_mask);
sa_new.sa_flags =0;//SA_SIGINFO;
sigaction(SIGPIPE, &sa_new, NULL);
cHttpsvr *phttpsvr=new cHttpsvr;
phttpsvr->start(7776);
phttpsvr->add_url("/test",(FUNC_DOREQ *)&http_test);
while(!exit_flag)
{
my_usleep(100000);
}
delete phttpsvr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -