book@ubuntu:/home/demo/tinyhttpd-0.1.0$ make
gcc -W -Wall -lsocket -lpthread -o httpd httpd.c
httpd.c: In function ‘startup’:
httpd.c:437:34: warning: pointer targets in passing argument 3 of ‘getsockname’ differ in signedness [-Wpointer-sign]
/usr/include/i386-linux-gnu/sys/socket.h:119:12: note: expected ‘socklen_t * __restrict__’ but argument is of type ‘int *’
httpd.c: In function ‘main’:
httpd.c:491:24: warning: pointer targets in passing argument 3 of ‘accept’ differ in signedness [-Wpointer-sign]
/usr/include/i386-linux-gnu/sys/socket.h:214:12: note: expected ‘socklen_t * __restrict__’ but argument is of type ‘int *’
httpd.c:495:2: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [enabled by default]
/usr/include/pthread.h:225:12: note: expected ‘void * (*)(void *)’ but argument is of type ‘void (*)(int)’
httpd.c:495:2: warning: passing argument 4 of ‘pthread_create’ makes pointer from integer without a cast [enabled by default]
/usr/include/pthread.h:225:12: note: expected ‘void * __restrict__’ but argument is of type ‘int’
/usr/bin/ld: cannot find -lsocket
collect2: ld returned 1 exit status
make: *** [httpd] Error 1
book@ubuntu:/home/demo/tinyhttpd-0.1.0$ gcc -o httpd httpd.c -lpthread
httpd.c: In function ‘main’:
httpd.c:495:2: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [enabled by default]
/usr/include/pthread.h:225:12: note: expected ‘void * (*)(void *)’ but argument is of type ‘void (*)(int)’
httpd.c:495:2: warning: passing argument 4 of ‘pthread_create’ makes pointer from integer without a cast [enabled by default]
/usr/include/pthread.h:225:12: note: expected ‘void * __restrict__’ but argument is of type ‘int’
有上面错误知:pthread_create 传递的参数有问题。
源码修改:
1、源码495行 ,改为 if (pthread_create(&newthread , NULL, accept_request, (void*)&client_sock) != 0)
2、33行改为 void* accept_request(void *); 相应的该函数的实现也要做出修改:
void *accept_request(void *pclient)
{
int client = *(int *)pclient;
...
}
https://baike.baidu.com/item/apache/6265
http://blog.csdn.net/wenqian1991/article/details/46048987
https://www.cnblogs.com/chenyang920/p/5610052.html
gcc -W -Wall -lsocket -lpthread -o httpd httpd.c
httpd.c: In function ‘startup’:
httpd.c:437:34: warning: pointer targets in passing argument 3 of ‘getsockname’ differ in signedness [-Wpointer-sign]
/usr/include/i386-linux-gnu/sys/socket.h:119:12: note: expected ‘socklen_t * __restrict__’ but argument is of type ‘int *’
httpd.c: In function ‘main’:
httpd.c:491:24: warning: pointer targets in passing argument 3 of ‘accept’ differ in signedness [-Wpointer-sign]
/usr/include/i386-linux-gnu/sys/socket.h:214:12: note: expected ‘socklen_t * __restrict__’ but argument is of type ‘int *’
httpd.c:495:2: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [enabled by default]
/usr/include/pthread.h:225:12: note: expected ‘void * (*)(void *)’ but argument is of type ‘void (*)(int)’
httpd.c:495:2: warning: passing argument 4 of ‘pthread_create’ makes pointer from integer without a cast [enabled by default]
/usr/include/pthread.h:225:12: note: expected ‘void * __restrict__’ but argument is of type ‘int’
/usr/bin/ld: cannot find -lsocket
collect2: ld returned 1 exit status
make: *** [httpd] Error 1
book@ubuntu:/home/demo/tinyhttpd-0.1.0$ gcc -o httpd httpd.c -lpthread
httpd.c: In function ‘main’:
httpd.c:495:2: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [enabled by default]
/usr/include/pthread.h:225:12: note: expected ‘void * (*)(void *)’ but argument is of type ‘void (*)(int)’
httpd.c:495:2: warning: passing argument 4 of ‘pthread_create’ makes pointer from integer without a cast [enabled by default]
/usr/include/pthread.h:225:12: note: expected ‘void * __restrict__’ but argument is of type ‘int’
有上面错误知:pthread_create 传递的参数有问题。
源码修改:
1、源码495行 ,改为 if (pthread_create(&newthread , NULL, accept_request, (void*)&client_sock) != 0)
2、33行改为 void* accept_request(void *); 相应的该函数的实现也要做出修改:
void *accept_request(void *pclient)
{
int client = *(int *)pclient;
...
}
https://baike.baidu.com/item/apache/6265
http://blog.csdn.net/wenqian1991/article/details/46048987
https://www.cnblogs.com/chenyang920/p/5610052.html