-----------------------------------------------------------------------------------------------------------------
int hFree(void ***map, int handle) 功能:释放使用的map数组 说明:
-----------------------------------------------------------------------------------------------------------------
int hAllocEntry(void ***list, int *max, int size) 功能:Allocate an entry in the halloc array. 说明:
-----------------------------------------------------------------------------------------------------------------
int bopen(void *buf, int bufsize, int flags) 功能:初始化balloc模块,分配64k内存 说明:
-----------------------------------------------------------------------------------------------------------------
void bclose()
功能:关闭balloc模块,释放内存 说明:
-----------------------------------------------------------------------------------------------------------------
void *balloc(B_ARGS_DEC, int size)
功能:分配能容下size大小的最小的块, 说明:
-----------------------------------------------------------------------------------------------------------------
void bfree(B_ARGS_DEC, void *mp)
功能:释放balloc分配的内存空间 说明:
-----------------------------------------------------------------------------------------------------------------
void bfreeSafe(B_ARGS_DEC, void *mp) 功能:没啥用 说明:
-----------------------------------------------------------------------------------------------------------------
char *bstrdupA(B_ARGS_DEC, char *s) 功能:没啥用 说明:
-----------------------------------------------------------------------------------------------------------------
char_t *bstrdup(B_ARGS_DEC, char_t *s) 功能:分配内存,拷贝字符串 说明:
-----------------------------------------------------------------------------------------------------------------
void *brealloc(B_ARGS_DEC, void *mp, int newsize) 功能:扩大分配的内存空间 说明:
-----------------------------------------------------------------------------------------------------------------
static int ballocGetSize(int size, int *q)
功能:获得能容下size的最小的块的大小 说明:
Block classes are: 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536
-----------------------------------------------------------------------------------------------------------------
static void bFillBlock(void *buf, int bufsize) 功能:没啥用 说明:
-----------------------------------------------------------------------------------------------------------------
void bstats(int handle, void (*writefn)(int handle, char_t *fmt, ...)) 功能:输出内存的统计信息 说明:
-----------------------------------------------------------------------------------------------------------------
static int bStatsFileSort(const void *cp1, const void *cp2) 功能:比较大小 说明:
-----------------------------------------------------------------------------------------------------------------
static void bStatsAlloc(B_ARGS_DEC, void *ptr, int q, int size) 功能:计算分配的统计信息 说明:
-----------------------------------------------------------------------------------------------------------------
static void bStatsFree(B_ARGS_DEC, void *ptr, int q, int size) 功能:释放统计信息 说明:
-----------------------------------------------------------------------------------------------------------------
static void bstatsWrite(int handle, char_t *fmt, ...) 功能:输出 说明:
-----------------------------------------------------------------------------------------------------------------
static void verifyUsedBlock(bType *bp, int q) 功能:校验使用中的块 说明:
-----------------------------------------------------------------------------------------------------------------
static void verifyFreeBlock(bType *bp, int q) 功能:校验未使用的块 说明:
-----------------------------------------------------------------------------------------------------------------
void verifyBallocSpace() 功能:校验分配的空间 说明:
-----------------------------------------------------------------------------------------------------------------
char_t *bstrdupNoBalloc(char_t *s) 功能: 说明:
-----------------------------------------------------------------------------------------------------------------
goAhead实现文件上传
1. 说明
最近调试web文件上传到服务器功能,但在调试时,处理函数总是获取不到文件路径,百思不得其解,查了网上许多文章,但大多提到的是前端文件上传的原理、实现方式等,而未提供服务器端处理的实现(利用C函数实现)。此外,由于对web不了解,花了些时间研究web程序。
2. goAhead实现文件上传的方法
总得来说,goAhead上实现文件上传功能是比较容易的。因为有现成的代码可用,稍微移植下即可。 2.1 实现原理
使用html form即表单提交文件上传请求,web服务器核心处理接收客户端Post过来的文件数据(注意post的是二进制数据),最后,web服务器把接收到文件数据以二进制格式写到服务器本端存储系统。 2.2 前端设计
前端设计比较简单,就是设计一个form,type属性为file,本人是在goAhead-2.5附带的wwwdemo的asptest.asp网页上增加了一个这样的form。
Expanded ASP data: <% aspTest(\z=z+1) \\ { \\ write(z+\qual to 3
\} \\ GoForm upload file test
其中,enctype参数用来设置表单的MIME编码方式,在进行文件(或同时包含文本框)
上传时,必须将其属性设置为\;formUploadFileTest 是web服务器定义的一个处理函数,用于把web服务器接收到的上传文件数据写到存储系统。 2.3 goAhead增加文件上传功能
goAhead-2.5的源码中,是没有包含文件上传功能的,因此需要对goAhead-2.5增加文件上传功能。本人使用v2.1.1版本的补丁,可从下载:http://download.csdn.net/detail/reille/3687321
打补丁的时候不是很方便,需要利用对比工具,把文件上传功能的源码增加到goAhead-2.5中。
2.4 把上传文件写到存储系统
在goAhead-2.5的源码main.c中增加文件上传form的处理函数:formUploadFileTest (),代码如下:
/******************************************************************************/ * for test html upload file to web serverstaticvoid formUploadFileTest(webs_t wp, char_t *path, char_t *query) { char_t * fn; char_t * bn = NULL; printf(\.............\\n\\n\websGetVar(wp, T(\t)(bn = gstrrchr(fn, '/') + 1) == 1) { if ((int)(bn = gstrrchr(fn, '\\\\') + 1) == 1) { bn = fn; } } } printf(\.......\\n\
\\; locWrite = 0; numLeft = wp->lenPostData; numWrite = fwrite(&(wp->postData[locWrite]), sizeof(*(wp->postData)), numLeft, fp); if (numWrite < numLeft) { websWrite(wp, T(\> ferror=%d locWrite=%d numLeft=%d numWrite=%d Size=%d bytes
\ locWrite += numWrite; numLeft -= numWrite; } websWrite(wp, T(\t=%d numWrite=%d Size=%d bytes
\rite, wp->lenPostData); websWrite(wp, T(\bytes
\eft=%d locWrite=%d Size=%d bytes
\Data); } } websFooter(wp); websDone(wp, 200); }