http server v0.1_http_reponse.c
#include <string.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h> #include "mime.h"
#include "http_common.h"
#include "http_webapp.h"
static STR_STATUS_MAP resp_map[]={HTTP_STATUS_MAP(HTTP_MAP_GEN)}; /*---------------------------------------------------------------------------- -----------------------------------------------------------------------------*/
int get_response_head(EN_REP_STATUS status, EN_MIME_TYPE type, char* resp_head, int content_len)
{
int stat_len = ;
char* point = NULL;
char* content_type = NULL;
char lenstr[]; if(resp_head == NULL)
return -; if(status > HTTP_END || status < )
return -; point = resp_head;
// response status
stat_len = strlen(resp_map[status].head);
strncpy(point, resp_map[status].head, stat_len);
// server version
strcat(point, HTTP_RESP_HEAD_SERVER);
// content type
content_type = get_resp_type(type);
strcat(point, HTTP_RESP_HEAD_CONTENT_TYPE);
strcat(point, content_type);
// content length
strcat(point, HTTP_RESP_HEAD_CONTENT_LENGTH);
bzero(lenstr, sizeof(lenstr));
strcat(point, itoa(content_len,lenstr,));
// head end
strncat(point, "\r\n\r\n", );
return ;
} int get_response_body(EN_MIME_TYPE type, void* body, char* uri, long len)
{
int fd = ;
void* bodybuf = NULL;
if(body == NULL || uri == NULL)
return -; if(len == )
return ; if(type == HTTP_ELSE)
return -; fd = open(uri, O_RDONLY, );
if(fd == -)
{
close(fd);
return -;
}
// virsual memory map
bodybuf = mmap(, len, PROT_READ, MAP_PRIVATE, fd, );
memcpy(body, bodybuf, len);
munmap(bodybuf, len);
close(fd);
return ;
}
http server v0.1_http_reponse.c的更多相关文章
- http server v0.1_http_server.c
/**************************************************************** filename: http_server.c author: xx ...
- http server v0.1_http_parse.c
#include <stdio.h> #include <string.h> #include <stdlib.h> #include "mime.h&q ...
- http server v0.1_http_webapp.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h&g ...
- http server v0.1_mime.c
#include <string.h> #include "mime.h" static STR_MIME_MAP mime_map[]= { MIME_MAP(MIM ...
- 用FileZilla Server开FTP
FileZilla(教程)是经典的开源FTP解决方案,包括FileZilla客户端和FileZilla Server.其中,FileZilla Server的功能比起商业软件FTP Serv-U毫不逊 ...
- DNS隧道之DNS2TCP实现——dns2tcpc必须带server IP才可以,此外ssh可以穿过墙的,设置代理上网
我自己的命令: server端: dns2tcpd -F -d 1 -f ./dns2tcpd.conf 输出: 09:08:59 : Debug options.c:97 Add resource ...
- docker 下 安装rancher 笔记
sudo yum update 更新系统环境 curl -sSL https://get.docker.com/ | sh 安装最新docker版本 systemctl start docker.se ...
- 容器基础(七): 使用docker compose部署程序
配置 在上一节的基础上, 增加如下的docker-compose.yml文件, 然后用docker-compose up命令启动容器进行部署: version: " services: s ...
- 容器基础(八): 使用docker swarm部署程序
环境 基于上一节的env/server:v0.1, env/worker:v0.1镜像, 在基于debian8.2的两台机器上测试部署docker swarm. docker service部署 ➜ ...
随机推荐
- C#使用Sockets操作FTP【转载】
using System; using System.Collections; using System.IO; using System.Net; using System.Net.Sockets; ...
- BringWindowToTop(), SetForegroundWindow(), SetActiveWindow()
1. SetActiveWindow() 原型: <span style="font-size:14px;">CWnd* SetActiveWindow(); HWND ...
- [TypeScript] Reflection and Decorator Metadata
TypeScript allows you to emit decorator metadata which enables more powerful features through reflec ...
- ios6如何处理内存,分别为前警告后
这里有一篇文章.非常具体地说明了ios6前后是怎样处理内存警告的: 来自唐巧的技术博客:http://blog.devtang.com/blog/2013/05/18/goodbye-viewdidu ...
- Linux I/O Scheduler--CFQ(上)图解
http://blog.csdn.net/vanbreaker/article/details/8299491 http://doc.okbase.net/29060569/archive/46628 ...
- LabVIEW设计模式系列——case结构模拟事件结构
标准:1.所有按钮的机械动作必须都用释放时触发或者单击时触发,这是为了保证仅仅触发一次动作. 标准:1.使用简单的case结构模拟事件结构.
- ThreadLocal 笔记
synchronized 同步的机制可以解决多线程并发问题,这种解决方案下,多个线程访问到的都是同一份变量的内容.为了防止在多线程访问的过程中,可能会出现的并发错误.不得不对多个线程的访问进行同步,这 ...
- Oracle11g - dos 命令 sqlplus/nolog 提示 不是内部命令解决办法
继安装Oracle 11g后,解锁SCOtt时发现 dos 命令 sqlplus/nolog 提示 不是内部命令解决办法 通过实际验证现整理有效方法步骤如下: 步骤一:开始>>找到Or ...
- MYSQL之高级查询
PHP高级查询 分组查询.联合查询.连接查询.子查询 版权声明:本文为博主原创文章,未经博主允许不得转载.
- .NET(C#):获取进程的内存私有工作集
当前.NET Framework(.NET 4.0)的Process仅提供进程的内存工作集的获取(通过WorkingSet64属性),而没有提供对私有工作集的获取.注意在Windows Vista之后 ...