GoAhead初探

来源:互联网 发布:数据中心网络拓扑结构 编辑:程序博客网 时间:2024/05/29 07:48

1、GoAhead is the world's most popular embedded web server deployed for over 15 years in hundreds of millions of devices by industry leaders and startups. It is compact at less than 150K and is easily embedded for dynamic web applications.


2、GoAhead 目前最新版本为3.4.9,和之前的2.*.*版本源代码差别还是有点大的。具体使用差别还有待深入学习。

   代码量其实并不大,可以走读代码结合官方资料http://embedthis.com/goahead/doc/学会使用。稍微看了一下,果然是网上说的单线程处理程序。

goahead.c->MAIN(goahead, int argc, char **argv, char **envp)->websServiceEvents(&finished)->socketProcess()->

PUBLIC void socketProcess()
{
    WebsSocket    *sp;
    int         sid;
    for (sid = 0; sid < socketMax; sid++) {
        if ((sp = socketList[sid]) != NULL) {
            if (sp->currentEvents & sp->handlerMask) {
                socketDoEvent(sp);
            }
        }
    }
}


3、windows下编译:

A、visual studio 2012 \project\goahead-windows-default.sln 直接双击打开,可以编译通过。

B、debug starting会提示“**\bin\prep.exe”系统找不到指定的文件,暂且不去深究。

C、直接到可执行文件目录\build\windows-x86-vsrelease\bin找到goahead.exe/goahead拖到cmd中运行,会提示错误。goahead: 0: Can't initialize server. Exiting.

原因很简单,源码中只考虑单网卡的设备,而笔记本往往有多个网卡,需要修改获取本地IP地址部分代码(http.c中的setLocalHost()函数)。

具体方法可以参考:http://blog.csdn.net/yangzhongxuan/article/details/17373055 ,该文章是基于linux的,struct ifreq 在windows中未定义,学自己改写程序。   


D、route.txt,auth.txt,网页文件放到web目录,全部copy到cmd默认的执行目录下。

E、运行,再游览器中输入http://localhost/打开,OK

0 0