下载tinyhttpd 代码
在泰山派的sdk里面,查看tinyhttpd的mk文件
TINYHTTPD_VERSION = 0.1.0
TINYHTTPD_SITE = http://downloads.sourceforge.net/project/tinyhttpd/tinyhttpd%20source/tinyhttpd%20$(TINYHTTPD_VERSION)
对代码进行下载
$ mkdir ./tinyhttpd
$ cd ./tinyhttpd/
tinyhttpd$ wget http://downloads.sourceforge.net/project/tinyhttpd/tinyhttpd%20source/tinyhttpd%200.1.0/tinyhttpd-0.1.0.tar.gz
--2024-09-16 14:44:53-- http://downloads.sourceforge.net/project/tinyhttpd/tinyhttpd%20source/tinyhttpd%200.1.0/tinyhttpd-0.1.0.tar.gz
Resolving downloads.sourceforge.net (downloads.sourceforge.net)... 204.68.111.105
Connecting to downloads.sourceforge.net (downloads.sourceforge.net)|204.68.111.105|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://jaist.dl.sourceforge.net/project/tinyhttpd/tinyhttpd%20source/tinyhttpd%200.1.0/tinyhttpd-0.1.0.tar.gz?viasf=1 [following]
--2024-09-16 14:44:53-- http://jaist.dl.sourceforge.net/project/tinyhttpd/tinyhttpd%20source/tinyhttpd%200.1.0/tinyhttpd-0.1.0.tar.gz?viasf=1
Resolving jaist.dl.sourceforge.net (jaist.dl.sourceforge.net)... 150.65.7.130, 2001:df0:2ed:feed::feed
Connecting to jaist.dl.sourceforge.net (jaist.dl.sourceforge.net)|150.65.7.130|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5934 (5.8K) [application/x-gzip]
Saving to: ‘tinyhttpd-0.1.0.tar.gz’
tinyhttpd-0.1.0.tar.gz 100%[===============================================>] 5.79K --.-KB/s in 0s
2024-09-16 14:44:53 (246 MB/s) - ‘tinyhttpd-0.1.0.tar.gz’ saved [5934/5934]
/tinyhttpd$ tar -zxvf ./tinyhttpd-0.1.0.tar.gz
tinyhttpd-0.1.0/
tinyhttpd-0.1.0/htdocs/
tinyhttpd-0.1.0/htdocs/check.cgi
tinyhttpd-0.1.0/htdocs/README
tinyhttpd-0.1.0/htdocs/color.cgi
tinyhttpd-0.1.0/htdocs/index.html
tinyhttpd-0.1.0/Makefile
tinyhttpd-0.1.0/README
tinyhttpd-0.1.0/httpd.c
tinyhttpd-0.1.0/simpleclient.c
tinyhttpd$ tree ./
./
├── tinyhttpd-0.1.0
│ ├── htdocs
│ │ ├── check.cgi
│ │ ├── color.cgi
│ │ ├── index.html
│ │ └── README
│ ├── httpd.c
│ ├── Makefile
│ ├── README
│ └── simpleclient.c
└── tinyhttpd-0.1.0.tar.gz
2 directories, 9 files
把其中的htdocs文件夹和httpd.c复制到虹软的SDK目录下
在主程序中引入httpd
httpd.c中,有一个注释要留意
/* This program compiles for Sparc Solaris 2.6.
* To compile for Linux:
* 1) Comment out the #include <pthread.h> line.
* 2) Comment out the line that defines the variable newthread.
* 3) Comment out the two lines that run pthread_create().
* 4) Uncomment the line that runs accept_request().
* 5) Remove -lsocket from the Makefile.
*/
按照要求操作,这样就不使用pthread_create多线程操作,只能处理一个请求
由于htdocs在上一层,也要修改一下这里
sprintf(path, "../htdocs%s", url);
把httpd的main函数改成 int httpd_main(void),并在主程序中调用
//tinyhttpd
httpd_main();
编译测试
在cmake文件中添加httpd.c和httpd.h, 编译,测试
face/samplecode/ASFTestDemo/build$ sudo ./arcsoft_face_engine_test
......
httpd running on port 39153
进一步将httpd单独开线程固定端口
固定8080端口
u_short port = 8080;
更改原来的httpd函数为
void* httpd_thread(void* arg)
主函数调用
//tinyhttpd
pthread_t newthread;
void* arg_httpd;
if (pthread_create(&newthread , NULL, httpd_thread, arg_httpd) != 0)
perror("pthread_create");
printf("main thread ok \n");
编译测试
main thread ok
httpd running on port 8080
两个线程正常