tinyhttpd-0.1.0源码分析

从零开始的tinyhttpd项目 从零开始的tinyhttpd项目 学习顺序(更新中)前言虚拟机安装及配置 前言 TinyWebServer是c++服务器方向常见的一个项目,但该项目涉及的内容太多。由于本人接触linux网络编程不深,所以准备从tinyhttpd项目开始学起,因为该项目代码量不大,而且涉及模块少,对于不熟悉的虚拟机配置,linux配置和命令都有很大的练习作用,故选用该项目先试手一下。虽然说是从零开始,但还需要了解基本c/c++语法,linux简单命令及网络编程基础概念即可。 虚拟机安装及配置 本人系统win10,所以安装 阅读详情

httpd-0.1.0源码分析

httpd-0.1.0介绍

TinyHTTPd是一个轻量级的http server。可以作为初级学习Linux网络编程或者C/C++入门小程序学习。此程序为开源项目。

前期准备

我个人理解的B/S架构是:
1.server先在相应的机器上运行起来,之后server程序检测端口是否有请求。
2.浏览器这时就可以通过网络访问已经运行起来的server。我们通过浏览器访问一个网站(URL可以经过一系列的解析过程变成IP地址),会发送http请求给http 服务器,如果请求的是一个静态的页面或图片,服务器会直接返回结果给浏览器。但如果要完成一个动态的请求,比如需要查询数据库这样的操作,服务器会运行一个单独的程序来执行,这个程序处理完成后会把结果转化为服务器(或者浏览器)可以识别的格式输出。

客户端

不管是C/S还是B/S要想实现功能,server必须先运行起来。

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
 int sockfd;
 int len;
 struct sockaddr_in address;
 int result;
 char ch = 'A';

 sockfd = socket(AF_INET, SOCK_STREAM, 0);
 /*AF_INET(又称 PF_INET)是 IPv4 网络协议的套接字类型,
 AF_INET6 则是 IPv6 的;而 AF_UNIX 则是 Unix 系统本地通信。        
 SOCK_STREAM提供面向连接的稳定数据传输,即TCP协议。
 SOCK_STREAM应用在C语言socket编程中,
 在进行网络连接前,需要用socket函数向系统申请一个通信端口。
 SOCK_STREAM 是数据流,一般是tcp/ip协议的编程,
 SOCK_DGRAM分是数据包,是udp协议网络编程。
 */
 address.sin_family = AF_INET;
 address.sin_addr.s_addr = inet_addr("127.0.0.1");
 address.sin_port = htons(9734);

 /*
 struct sockaddr_in

{
short sin_family;   //Address family一般来说AF_INET(地址族)PF_INET(协议族) 
unsigned short sin_port;  //Port number(必须要采用网络数据格式,普通数字可以用htons()函数转换成网络数据格式的数字)

struct in_addr sin_addr; // IP address in network byte order(Internet address)

unsigned char sin_zero[8]; //  Same size as struct sockaddr没有实际意义,只是为了 跟SOCKADDR结构在内存中对齐
};

 */
 len = sizeof(address);
 result = connect(sockfd, (struct sockaddr *)&address, len); //client

 if (result == -1)
 {
  perror("oops: client1");
  exit(1);
 }
 write(sockfd, &ch, 1);
 read(sockfd, &ch, 1);
 printf("char from server = %c\n", ch);
 close(sockfd);
 exit(0);
}

客户端程序非常简单,就是基本的流程,先创建socket,之后调用connect函数与server建立TCP连接。write和read是Linux提供的I/O函数。用来向socket输入输出数据。

服务器端

#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <ctype.h>
#include <strings.h>
#include <string.h>
#include <sys/stat.h>
#include <pthread.h>
#include <sys/wait.h>
#include <stdlib.h>

#define ISspace(x) isspace((int)(x))

#define SERVER_STRING "Server: jdbhttpd/0.1.0\r\n"

void accept_request(int);
void bad_request(int);
void cat(int, FILE *);
void cannot_execute(int);
void error_die(const char *);
void execute_cgi(int, const char *, const char *, const char *);
int get_line(int, char *, int);
void headers(int, const char *);
void not_found(int);
void serve_file(int, const char *);
int startup(u_short *);
void unimplemented(int);

/**********************************************************************/
/* A request has caused a call to accept() on the server port to
 * return.  Process the request appropriately.
 * Parameters: the socket connected to the client */
/**********************************************************************/

/*
TCP连接建立成功后,服务器启动一个新的线程来处理
客户端的其他请求。
服务器启动一个新的线程来处理客户端的请求(accept_request),
处理完成后,重新等待新的客户端请求。
*/

void accept_request(int client)
{
 char buf[1024];
 int numchars;
 char method[255];
 char url[255];
 char path[512];
 size_t i, j;
 struct stat st;
 int cgi = 0;      /* becomes true if server decides this is a CGI
                    * program */
 char *query_string = NULL;

 numchars = get_line(client, buf, sizeof(buf));  //从线程中获取数据
 i = 0; j = 0;
 while (!ISspace(buf[j]) && (i < sizeof(method) - 1))
 {
  method[i] = buf[j];
  i++; j++;
 }
 method[i] = '\0';

 /*
 一个HTTP请求报文由
 请求行(requestline)、请求头部(header)、
 空行和请求数据4个部分组成,
 请求行由请求方法字段(get或post)、URL字段
 和HTTP协议版本字段3个字段组成,它们用空格分隔。
 例如,GET /index.html HTTP/1.1。
 上面这段代码就是解析请求行,
 把方法字段保存在method变量中。
 */

 if (strcasecmp(method, "GET") && strcasecmp(method, "POST")) //忽略大小写比较字符串
 {
  unimplemented(client); //将一个网页发给客户端
  return;
 }

 if (strcasecmp(method, "POST") == 0)
  cgi = 1;

 i = 0;
 while (ISspace(buf[j]) && (j < sizeof(buf))) //判断字符是否为空格字符
  j++;
 while (!ISspace(buf[j]) && (i < sizeof(url) - 1) && (j < sizeof(buf)))
 { //不是空格 i没有到url末尾时
  url[i] = buf[j];
  i++; j++;
 }
 url[i] = '\0';

 /*
 如果是get方法,请求参数和对应的值附加在URL后面,
 利用一个问号("?")代表URL的结尾与请求参数的开始,
 传递参数长度受限制。例如,/index.jsp?10023
 其中10023就是要传递的参数。
 这段代码把参数保存在query_string中。
 */

 if (strcasecmp(method, "GET") == 0)
 {
  query_string = url;
  while ((*query_string != '?') && (*query_string != '\0'))
   query_string++;
  if (*query_string == '?')
  {
   cgi = 1;
   *query_string = '\0';
   query_string++;
  }
 }

 /*
 这段代码保存有效的url地址并加上请求地址的主页索引。
 默认的根目录是在htdocs下。
 */
 sprintf(path, "htdocs%s", url);
 if (path[strlen(path) - 1] == '/')
  strcat(path, "index.html");
 if (stat(path, &st) == -1) {
  while ((numchars > 0) && strcmp("\n", buf))  /* read & discard headers */
   numchars = get_line(client, buf, sizeof(buf));
  not_found(client);
 }
 else
 {
  if ((st.st_mode & S_IFMT) == S_IFDIR)
   strcat(path, "/index.html");
  if ((st.st_mode & S_IXUSR) ||
      (st.st_mode & S_IXGRP) ||
      (st.st_mode & S_IXOTH)    )
   cgi = 1;
  if (!cgi)
   serve_file(client, path);
  else
   execute_cgi(client, path, method, query_string);
 }

 close(client);
}

/**********************************************************************/
/* Inform the client that a request it has made has a problem.
 * Parameters: client socket */
/**********************************************************************/
void bad_request(int client)
{
 char buf[1024];

 sprintf(buf, "HTTP/1.0 400 BAD REQUEST\r\n");
 send(client, buf, sizeof(buf), 0);
 sprintf(buf, "Content-type: text/html\r\n");
 send(client, buf, sizeof(buf), 0);
 sprintf(buf, "\r\n");
 send(client, buf, sizeof(buf), 0);
 sprintf(buf, "<P>Your browser sent a bad request, ");
 send(client, buf, sizeof(buf), 0);
 sprintf(buf, "such as a POST without a Content-Length.\r\n");
 send(client, buf, sizeof(buf), 0);
}

/**********************************************************************/
/* Put the entire contents of a file out on a socket.  This function
 * is named after the UNIX "cat" command, because it might have been
 * easier just to do something like pipe, fork, and exec("cat").
 * Parameters: the client socket descriptor
 *             FILE pointer for the file to cat */
/**********************************************************************/
void cat(int client, FILE *resource)
{
 char buf[1024];

 fgets(buf, sizeof(buf), resource);
 while (!feof(resource))
 {
  send(client, buf, strlen(buf), 0);
  fgets(buf, sizeof(buf), resource);
 }
}

/**********************************************************************/
/* Inform the client that a CGI script could not be executed.
 * Parameter: the client socket descriptor. */
/**********************************************************************/
void cannot_execute(int client)
{
 char buf[1024];

 sprintf(buf, "HTTP/1.0 500 Internal Server Error\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "Content-type: text/html\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "<P>Error prohibited CGI execution.\r\n");
 send(client, buf, strlen(buf), 0);
}

/**********************************************************************/
/* Print out an error message with perror() (for system errors; based
 * on value of errno, which indicates system call errors) and exit the
 * program indicating an error. */
/**********************************************************************/
void error_die(const char *sc)
{
 perror(sc);
 exit(1);
}

/**********************************************************************/
/* Execute a CGI script.  Will need to set environment variables as
 * appropriate.
 * Parameters: client socket descriptor
 *             path to the CGI script */
/**********************************************************************/
void execute_cgi(int client, const char *path,
                 const char *method, const char *query_string)
{
 char buf[1024];
 int cgi_output[2];
 int cgi_input[2];
 pid_t pid;
 int status;
 int i;
 char c;
 int numchars = 1;
 int content_length = -1;

 buf[0] = 'A'; buf[1] = '\0';
 if (strcasecmp(method, "GET") == 0)
  while ((numchars > 0) && strcmp("\n", buf))  /* read & discard headers */
   numchars = get_line(client, buf, sizeof(buf));
 else    /* POST */
 {
  numchars = get_line(client, buf, sizeof(buf));
  while ((numchars > 0) && strcmp("\n", buf))
  {
   buf[15] = '\0';
   if (strcasecmp(buf, "Content-Length:") == 0)
    content_length = atoi(&(buf[16]));
   numchars = get_line(client, buf, sizeof(buf));
  }
  if (content_length == -1) {
   bad_request(client);
   return;
  }
 }

 sprintf(buf, "HTTP/1.0 200 OK\r\n");
 send(client, buf, strlen(buf), 0);

 if (pipe(cgi_output) < 0) {
  cannot_execute(client);
  return;
 }
 if (pipe(cgi_input) < 0) {
  cannot_execute(client);
  return;
 }

 if ( (pid = fork()) < 0 ) {
  cannot_execute(client);
  return;
 }
 if (pid == 0)  /* child: CGI script */
 {
  char meth_env[255];
  char query_env[255];
  char length_env[255];

  dup2(cgi_output[1], 1);
  dup2(cgi_input[0], 0);
  close(cgi_output[0]);
  close(cgi_input[1]);
  sprintf(meth_env, "REQUEST_METHOD=%s", method);
  putenv(meth_env);
  if (strcasecmp(method, "GET") == 0) {
   sprintf(query_env, "QUERY_STRING=%s", query_string);
   putenv(query_env);
  }
  else {   /* POST */
   sprintf(length_env, "CONTENT_LENGTH=%d", content_length);
   putenv(length_env);
  }
  execl(path, path, NULL);
  exit(0);
 } else {    /* parent */
  close(cgi_output[1]);
  close(cgi_input[0]);
  if (strcasecmp(method, "POST") == 0)
   for (i = 0; i < content_length; i++) {
    recv(client, &c, 1, 0);
    write(cgi_input[1], &c, 1);
   }
  while (read(cgi_output[0], &c, 1) > 0)
   send(client, &c, 1, 0);

  close(cgi_output[0]);
  close(cgi_input[1]);
  waitpid(pid, &status, 0);
 }
}

/**********************************************************************/
/* Get a line from a socket, whether the line ends in a newline,
 * carriage return, or a CRLF combination.  Terminates the string read
 * with a null character.  If no newline indicator is found before the
 * end of the buffer, the string is terminated with a null.  If any of
 * the above three line terminators is read, the last character of the
 * string will be a linefeed and the string will be terminated with a
 * null character.
 * Parameters: the socket descriptor
 *             the buffer to save the data in
 *             the size of the buffer
 * Returns: the number of bytes stored (excluding null) */
/**********************************************************************/
int get_line(int sock, char *buf, int size)  // 1024
{
 int i = 0;
 char c = '\0';
 int n;

 while ((i < size - 1) && (c != '\n'))
 {
  n = recv(sock, &c, 1, 0);
  /* DEBUG printf("%02X\n", c); */
  if (n > 0)
  {
   if (c == '\r')
   {
    n = recv(sock, &c, 1, MSG_PEEK);
    /* DEBUG printf("%02X\n", c); */
    if ((n > 0) && (c == '\n'))
     recv(sock, &c, 1, 0);
    else
     c = '\n';
   }
   buf[i] = c;
   i++;
  }
  else
   c = '\n';
 }
 buf[i] = '\0';

 return(i);
}

/**********************************************************************/
/* Return the informational HTTP headers about a file. */
/* Parameters: the socket to print the headers on
 *             the name of the file */
/**********************************************************************/
void headers(int client, const char *filename)
{
 char buf[1024];
 (void)filename;  /* could use filename to determine file type */

 strcpy(buf, "HTTP/1.0 200 OK\r\n");
 send(client, buf, strlen(buf), 0);
 strcpy(buf, SERVER_STRING);
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "Content-Type: text/html\r\n");
 send(client, buf, strlen(buf), 0);
 strcpy(buf, "\r\n");
 send(client, buf, strlen(buf), 0);
}

/**********************************************************************/
/* Give a client a 404 not found status message. */
/**********************************************************************/
void not_found(int client)
{
 char buf[1024];

 sprintf(buf, "HTTP/1.0 404 NOT FOUND\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, SERVER_STRING);
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "Content-Type: text/html\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "<HTML><TITLE>Not Found</TITLE>\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "<BODY><P>The server could not fulfill\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "your request because the resource specified\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "is unavailable or nonexistent.\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "</BODY></HTML>\r\n");
 send(client, buf, strlen(buf), 0);
}

/**********************************************************************/
/* Send a regular file to the client.  Use headers, and report
 * errors to client if they occur.
 * Parameters: a pointer to a file structure produced from the socket
 *              file descriptor
 *             the name of the file to serve */
/**********************************************************************/
void serve_file(int client, const char *filename)
{
 FILE *resource = NULL;
 int numchars = 1;
 char buf[1024];

 buf[0] = 'A'; buf[1] = '\0';
 while ((numchars > 0) && strcmp("\n", buf))  /* read & discard headers */
  numchars = get_line(client, buf, sizeof(buf));

 resource = fopen(filename, "r");
 if (resource == NULL)
  not_found(client);
 else
 {
  headers(client, filename);
  cat(client, resource);
 }
 fclose(resource);
}

/**********************************************************************/
/* This function starts the process of listening for web connections
 * on a specified port.  If the port is 0, then dynamically allocate a
 * port and modify the original port variable to reflect the actual
 * port.
 * Parameters: pointer to variable containing the port to connect on
 * Returns: the socket */
/**********************************************************************/
/*程序创建一个服务器socket对象,然后绑写(bind),
并监听指定的端口(listen),这些动作都是在startup函数实现的。
这些也是Linux建立TCP连接的基本准备。
有一个细节稍微注意一下,如果传来的端口是0,
程序会随机分配一个监听的端口。
并通过指向port变量的地址返回该值。
*/

int startup(u_short *port)
{
 int httpd = 0;
 struct sockaddr_in name;

 httpd = socket(PF_INET, SOCK_STREAM, 0);
 if (httpd == -1)
  error_die("socket");
 memset(&name, 0, sizeof(name)); //内存清空
 name.sin_family = AF_INET;  //IPv4
 name.sin_port = htons(*port);   //端口号
 name.sin_addr.s_addr = htonl(INADDR_ANY); //INADDR_ANY就是指定地址为0.0.0.0的地址,这个地址事实上表示不确定地址,或“所有地址”、“任意地址”。 一般来说,在各个系统中均定义成为0值。
 if (bind(httpd, (struct sockaddr *)&name, sizeof(name)) < 0)
  error_die("bind");
 if (*port == 0)  /* if dynamically allocating a port */
 {
  int namelen = sizeof(name);
  if (getsockname(httpd, (struct sockaddr *)&name, &namelen) == -1) // 获得套接字名称
   error_die("getsockname");
  *port = ntohs(name.sin_port);
 }
 if (listen(httpd, 5) < 0)
  error_die("listen");
 return(httpd);
}

/**********************************************************************/
/* Inform the client that the requested web method has not been
 * implemented.
 * Parameter: the client socket */
/**********************************************************************/
void unimplemented(int client)
{
 char buf[1024];

 sprintf(buf, "HTTP/1.0 501 Method Not Implemented\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, SERVER_STRING);
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "Content-Type: text/html\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "<HTML><HEAD><TITLE>Method Not Implemented\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "</TITLE></HEAD>\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "<BODY><P>HTTP request method not supported.\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "</BODY></HTML>\r\n");
 send(client, buf, strlen(buf), 0);
}

/**********************************************************************/

int main(void)
{
 int server_sock = -1;
 u_short port = 0;
 int client_sock = -1;
 struct sockaddr_in client_name;
 int client_name_len = sizeof(client_name);
 pthread_t newthread;

 server_sock = startup(&port); //初始化
 printf("httpd running on port %d\n", port);

 while (1)
 {
  /*套接字收到客户端连接请求*/  
  client_sock = accept(server_sock,
                       (struct sockaddr *)&client_name,
                       &client_name_len);//新的socket来完成数据传输的任务,
  if (client_sock == -1)
   error_die("accept");

  /*派生新线程用accept_request 函数处理新请求*/  
  /* accept_request(client_sock); */
  if (pthread_create(&newthread , NULL, accept_request, client_sock) != 0) // 线程开启
   perror("pthread_create");
 }

 close(server_sock);

 return(0);
}

服务器程序也是先创建socket,之后调用startup函数初始化端口,然后服务器会在accpet函数阻塞。
当客户端的TCP连接请求到达时,accpet函数返回一个新的专用于数据传输的socket。此后服务器读写数据都是通过新的socket。
之后服务器程序开启一个线程负责这个TCP连接的数据传输。
accept_request函数会回应客户端的http请求,cat函数将读到的内容作为http响应报文的数据部分发送回客户端。

tinyhttpd编译执行 源文件下载地址:https://sourceforge.net/projects/tinyhttpd/1.解压压缩文件 tar -zxvf tinyhttpd-0.1.0.tar.gz2.进入文件目录 cd tinyhttpd-0.1.0修改htdocs文件夹里面.cgi文件因为cgi文件是用perl写的,我这里perl的位置是/usr/bin/perl所以打开.cgi文件第一句改为 #!/usr... 阅读详情

相关推荐

Tinyhttpd源码分析

Tinyhttpd是一个超轻量级的http服务器,使用C语言开发,代码只有500多行,不用于实际生产, 只是为了学习使用,通过阅读代码可以理解初步web服务器的本质,下面是学习Tinyhttpd的相关资料: Tinyhttpd源码 HTTP教程 一、HTTP协议 在阅读源码之间, 我们先要初步了解HTTP协议。HTTP协议(HyperText Transfer Protocol,超文本传输协...

brook666 935

【C语言开源项目】tinyhttpd ——下载、安装、使用

本系列将带领大家看一些C语言的优秀的开源项目,并逐步深入讲解源码,感兴趣的可以点击关注、收藏,有问题及时在评论区评论~

优快云GuoYuying的博客 1002

Tinyhttpd源码分析与总结

一、概念 httpd是Apache(HTTP)服务器的主程序。被设计为一个独立运行的后台进程,它会建立一个处理请求的子进程或线程的池。 cgi模式(web server和CGI的交互模式):httpd接收到一个动态请求就fork一个cgi进程,cgi进程返回结果给httpd进程后自我销毁。简单说明CGI和动态请求是什么 二、Tinyhttpd源码分析 1、转自【源码剖析】tinyhttpd...

u014694510的博客 1295

linux下编译运行tinyhttpd

linux下编译运行tinyhttpd 开始 1.下载 tinyhttpd 点击下载 2. 解压源码包 tar -zxvf tinyhttpd-0.1.0.tar.gz cd tinyhttpd-0.1.0 3.修改httpd.c文件 httpd.c 注释里有介绍怎么修改 /* This program compiles for Sparc Solaris 2.6. * To compile ...

qq673675158的博客 1581

#CentOS on Mac#4.WebBench测试TinyHttpd

早有听闻WebBench和TinyHttpd是工程师不得不了解的十大优秀C语言开源项目 出乎我意料的是,两个项目的代目都十分精简约在400行左右,而且稳定性极高,将近十年未更新 任务: 1.编译运行WebBench并了解注释WebBench源代码 2.编译运行TinyHttpd并了解注释TinyHttpd源代码 3.用编译的WebBench测试编译的TinyHttpd

chiu的博客 1602

【C语言开源库】 一个只有500行代码的开源http服务器:Tinyhttpd

项目搬运地址:Tinyhttpd 源码解析博客: HTTP服务器的本质:tinyhttpd源码分析及拓展 [Tinyhttpd精读解析] Tinyhttpd 源码解析 TinyHTTPd 源码分析 演示 首先确保你的linux上安装了 gcc,make,Perl,Perl-CGI 在某个目录下 //将远程仓库的源代码克隆到你的linux上 git clone https://github.com/EZLippi/Tinyhttpd //编译生成目标文件 make //执行 ./http 输入了执

qq_41854911的博客 936

源码分析之tinyhttpd-0.1

1. 简介: tinyhttpd是使用c语言开发的超轻量级http服务器,通过代码流程可以了解http服务器的基本处理流程, 并且涉及了网络套接字,线程,父子进程,管道等等知识点; 项目地址:http://sourceforge.net/projects/tinyhttpd/ 2. 流程介绍: (1) 服务器启动,等待客户端请求到来; (2) 客户端请求到来,创建新线程处理...

weixin_30627381的博客 162

一个简练易懂的http服务器tinyhttpd-0.1.0

tinyhttpd是一个linux平台下的http服务器,David Blackstone在1999写的。通过它,你可以了解到HTTP服务器的本质。tinyhttpd代码简练易读,包括注释仅有502行,还附带了一个HTTP客户端。

通过tinyhttpd-0.1.0源码理解服务器原理

tinyhttpd是一个demo版的服务器。代码几百行。源码分析在这。从中可用一窥服务器的基础原理。他采用的是一个请求新开一个线程处理的方式。里面涉及了多进程、多线程、进程间通信等知识。     我们从main函数开始分析。 int main(void) { int server_sock = -1; u_short port = 0; int cli...

标子 的专栏 363

tinyhttpd-0.1.0

tinyhttpd-0.1.0,c语言源码。。。。。。。。。。。。

http 1.0 源码

客户端(浏览器)与web服务器之间的交互主要包含客户的请求和服务器的应答。 请求和应答的格式在超文本传输协议(HTTP)中有定义。HTTP协议使用纯文本。 例如: $telnet www.ouc.edu.cn 80 Trying 211.64.150.68... Connected to www.ouc.edu.cn(211.64.150.68) Escape character is '^]'. GET /index.html HTTP/1.0 HTTP/1.1 200 OK Date: Wed, 21 Jun 2006 08:26:04 GMT Server: Apache/2.0.54(Unix) DAV/2 ..................................

Tinyhttpd 学习笔记

文章目录Tinyhttpd1. 概要(Abstract)2. 实例(Example)3. 源码剖析(Source Code)mainstartupaccept_requestexecute_cgicolor.cgiserver_fileget_linecatheaderscannot_executeunimplementednot_foundbad_requesterror_die4. Makefile总结 Tinyhttpd Tinyhttpd是J. David Blackstone在1999年写的微型

爱敲键盘的吉他手 1386

SimpleHTTPServer-1.0

SimpleHTTPServer-1.0 此部分HTTP / 1.0服务器将教我们HTTP / 1.0协议的基础知识,该基础知识以后将用于创建更接近可部署服务的应用程序。

Tinyhttpd源码精读

Tinyhttpd源码精读 参考博客 参考1 主要流程 收到客户端请求method:GETmethod:POSTmainstartupaccept_requestserve_fileexecute_cgi 这里的原理非常简单,以至于我自看完之后都非常惊讶,web服务器的工作机制好简单。佩服作者精简的思路。 在startup中我们完成端口和IP地址的绑定。实际上就是将之前的IP和端口号等设置进行了...

心灵迷宫 331

OpenCV 开闭运算

开运算和闭运算是将腐蚀和膨胀按照一定的次序进行处理。 但这两者并不是可逆的,即先开后闭并不能得到原来的图像。 开运算 开运算是先腐蚀后膨胀,其作用是:分离物体,消除小区域。特点:消除噪点,去除小的干扰块,而不影响原来的图像。 闭运算 闭运算与开运算相反,是先膨胀后腐蚀,作用是消除/“闭合”物体里面的孔洞,特点:可以填充闭合区域。 cv.morphologyEx(img, op, kernel) img: 要处理的图像 op: 处理方式:若进行开运算,则设为cv.MORPH_OPEN,若进行闭

꧁༺ʚvv༒catɞ༻꧂的博客 949

1.Fay-UE5数字人工程导入(UE数字人系统教程)

ue5数字人系列教程(含源文件工程)

1万+

TinyHttpd----超轻量型Http Server源码分析

tinyhttpd是一个超轻量型Http Server,使用C语言开发,全部代码只有502行(包括注释),附带一个简单的Client,可以通过阅读这段代码理解一个 Http Server 的本质。下载链接:http://sourceforge.net/projects/tinyhttpd/分析这段源码前,需要对网络协议,Linux编程,以及HTTP有一定的了解,这里假设大家对http有一定的了解,如

菜鸟成长记 3221

Basler相机和pylon viewer 的使用

文章目录1 线路连接2 安装和使用pylon 1 线路连接 电源线接到电源插座,网线接到电脑(电脑没有网口的话,可用转换器转到type-c接口)。 2 安装和使用pylon 参考 Basler pylon安装及对网口相机基本设置 相机和电脑以太网IP设置参考:balser相机IP设置 关于相机参数和pylon viewer的详细设置,可以参考pylon Viewer安装路径下的文档(Documentation) ...

Deephome的博客 1万+

Tiny Httpd在ubuntu上的运行,以及对tinyhttpd的理解

对tinyhttpd的理解: 它是一个轻量型的http服务器。 首先从其工作流程开始理解比较好: 1.创建套接字、监听、指定或者绑定端口、以及返回绑定的端口号: int startup(u_short *port); 2.

jia2938724298的博客 1399

从零构建:四轴机械臂D-H参数建模与MATLAB实战指南

本文详细介绍了四轴机械臂D-H参数建模的完整流程与MATLAB实战应用。从机械臂运动学基础出发,解析D-H参数原理与坐标系建立规则,提供MATLAB Robotics Toolbox的安装、模型创建及正逆运动学求解的代码实现。特别针对四轴机械臂的逆运算优化、轨迹规划和奇异位形规避等高级应用给出实用解决方案,是机器人开发者的实战指南。

weixin_29062255的博客 419

把大表拆成更好用的“小仓库”:SAP HANA 表分区设计、分区裁剪与内存代价全解析

摘要:本文深入解析SAP HANA分区技术的核心价值与实现策略。作为内存数据库的"手术刀",分区通过将逻辑表横向切分为独立物理容器,显著提升并行计算能力与查询效率。重点探讨了三种分区类型(Range、Hash、Round-robin)的适用场景,以及分区裁剪的优化原理与前提条件。特别指出分区设计需要平衡查询模式与数据分布,并揭示了分区对内存占用的双向影响机制:既可能因字典复制增加消耗,也可能因数据纯度提升压缩率。通过电商订单表等实际案例,展示了合理分区如何将分钟级报表优化至秒级响应。文章

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1652
上一篇: 自己实现ArrayList
下一篇: pip-pop源码分析
cslqm
博客等级 码龄11年 32粉丝 92原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值