tinyhttp 安装和使用 (代码阅读前期准备)

系统:ubuntu14.04

知识准备: <计算机网路第五版>   (美)特南鲍姆   7.3节 万维网

  

一:下载安装包 

tinyhttpd-0.1.0 .tar.gz

二:解压

tar -zxvf tinyhttpd-0.1.0 .tar.gz

三:安装

cd tinyhttpd-0.1.0
make

出现报错

/usr/include/x86_64-linux-gnu/sys/socket.h:127:12: note: expected ‘socklen_t * __restrict__’ but argument is of type ‘int *extern int getsockname (int __fd, __SOCKADDR_ARG __addr,
            ^
httpd.c: In function ‘main’:
httpd.c:491:24: warning: pointer targets in passing argument 3 of ‘accept’ differ in signedness [-Wpointer-sign]
                        &client_name_len);
                        ^
In file included from httpd.c:16:0:
/usr/include/x86_64-linux-gnu/sys/socket.h:243:12: note: expected ‘socklen_t * __restrict__’ but argument is of type ‘int *extern int accept (int __fd, __SOCKADDR_ARG __addr,
            ^
httpd.c:495:2: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [enabled by default]
  if (pthread_create(&newthread , NULL, accept_request, client_sock) != 0)
  ^
In file included from httpd.c:25:0:
/usr/include/pthread.h:244:12: note: expected ‘void * (*)(void *)’ but argument is of type ‘void (*)(int)’
 extern int pthread_create (pthread_t *__restrict __newthread,
            ^
httpd.c:495:2: warning: passing argument 4 of ‘pthread_create’ makes pointer from integer without a cast [enabled by default]
  if (pthread_create(&newthread , NULL, accept_request, client_sock) != 0)
  ^
In file included from httpd.c:25:0:
/usr/include/pthread.h:244:12: note: expected ‘void * __restrict__’ but argument is of type ‘intextern int pthread_create (pthread_t *__restrict __newthread,
            ^
/usr/bin/ld: cannot find -lsocket
collect2: error: ld returned 1 exit status
View Code

  查询原因,是当时的环境为solar,改为linux必须做一些改变,在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.
 */

解决

运行

zh@zh-pc:~/tinyhttpd-0.1.0$ ./httpd
httpd running on port 43580

访问

在浏览器中输入

http://127.0.0.1:50502/

要加上端口好50502,具体看http程序输出什么

可用结果

原文地址:https://www.cnblogs.com/dilidingzhi/p/4304440.html