GoAhead2.5移植到ARM教程
1、下载GoAhead2.5
下载地址:https://github.com/embedthis/goahead/releases?after=v3.1.2
2、编译
先解压到虚拟机的/opt目录下,cd /opt/goahead-2.5.0/LINUX,修改Makefile文件,在文件的最前面添加如下代码:
CROSS_COMPILE =/opt/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
修改输出库名称:
ARCH = libwebs_arm_linux_gnueabihf.a
注释掉SSL功能,并保存
#matrixsslDir:=$(shell ls -d ../matrixssl-3-1*/)
make
这时会在LINUX目录下生成libwebs_arm_linux_gnueabihf.a库,/opt/goahead-2.5.0目录下所有头文件(wsInitn.h、websSSL.h、websda.h、webs.h、um.h、uemf.h、md5.h、matrixSSLSocket.h、emfdb.h、ejIntrn.h、ej.h)和libwebs_arm_linux_gnueabihf.a库可以用于开发webserver程序,/opt/goahead-2.5.0/LINUX目录下的main.c文件中webserver启动过程可以用于自己开发webserver程序的一部分,以Qt开发为例,可以单独创建一个线程QWebServerThread。
头文件qwebserverthread.h
class QWebServerThread : public QThread
{
Q_OBJECT
public:
QWebServerThread(QString strWeb,QString strIP,int nPort,int nRPort);
~QWebServerThread ();
int initWeb();
static int websHomePageHandler(webs_t wp, char_t *urlPrefix, char_t *webDir,int arg, char_t *url, char_t *path, char_t *query);
#ifdef B_STATS
void memLeaks();
void printMemStats(int handle, char_t *fmt, ...);
#endif
protected:
void run();
private:
QString strWeb;
QString strIP;
int nPort;
int nRPort;
}
cpp文件qwebserverthread.cpp
#include "qwebserverthread.h"
WebServerThread::QWebServerThread(QString strWeb,QString strIP,int nPort)
{
this->strWeb = WebRoot;
this->strIP = strIP;
this->nPort = nPort;
this->nRPort = nRPort;
}
QWebServerThread::~QWebServerThread()
{
}
void QWebServerThread::run()
{
/*
*首先分配一个大的内存块(60*1024字节),以后只要是以b开头的对内存操作的函数都是在这个已经分好的内存块上的操作,这些操作在Balloc.c中实现。
*/
bopen(NULL,(60 * 1024),B_USE_MALLOC);
/*
*忽略SIGPIPE信号
*/
signal(SIGPIPE,SIG_IGN);
/*
*Initialize the web server
*初始化用户管理部分,打开web服务器,注册URL处理函数。
*用户管理部分在um.c中实现,
*Web服务器的初始化是在default.c和webs.c中实现
*url处理函数在handler.c中实现
*/
if(initWeb() < 0)
{
printf("initWeb error.\n");
return;
}
/*
*初始化Ssl认证部分
*注:在这个文档中对ssl认证不做研究
*/
#ifdef WEBS_SSL_SUPPORT
websSSLOpen();
#endif
/*
* Basic event loop. SocketReady returns true when a socket is ready for
* service. SocketSelect will block until an event occurs. SocketProcess
* will actually do the servicing.
*/
/*
*主循环
*/
while(getRunState())
{
/*
1,socketReady()函数检查是否有准备好的sock事件
2,socketSelect()函数首先把各个sock感兴趣的事件(sp->handlerMask)注册给三个集合(读,写,例外),然后调用select系统调用,然后更新各个sock的sp->currentEvents,表示各个sock的当前状态。
这两个函数在sockGen.c中实现,他们主要操作的数据是socket_t变量socketList中的handlerMask和currentEvents,socketList在sock.c中定义并主要由该文件中的socketAlloc,socketFree和socketPtr三个函数维护。
*/
if(socketReady(-1) || socketSelect(-1,1000))
{
/*
该函数处理具体的sock事件
1,调用socketReady(sid)对socketList[sid]进行检查,看是否有sock事件
2,如果有sock事件,则调用socketDoEvent()函数,对事件进行处理
*/
socketProcess(-1);
}
/*
该函数在cgi.c中实现,检查cgiRec变量cgilist,首先把cgi的结果输出,如果有的话,然后看cgi进程是否已对号束,如果结束,就清理该cgi进程。
Cgilist在函数websCgiHandler和websCgiCleanup中维护。
*/
websCgiCleanup();
/*
该函数在websuemf.c中实现,功能是检查sched_t变量sched,断开超时的连接,sched变量在emfSchedCallback和emfUnschedCallback中维护
*/
emfSchedProcess();
}
/*
退出时的清理工作,永远不会执行到这里
*/
#ifdef WEBS_SSL_SUPPORT
websSSLClose();
#endif
#ifdef USER_MANAGEMENT_SUPPORT
umClose();
#endif
//Close the socket module, report memory leaks and close the memory allocator
websCloseServer();
socketClose();
#ifdef B_STATS
memLeaks();
#endif
bclose();
}
int QWebServerThread::initWeb()
{
//Initialize the socket subsystem
socketOpen();
#ifdef USER_MANAGEMENT_SUPPORT
/*
* Initialize the User Management database
*/
umOpen();
umRestore((char_t*)_T("umconfig.txt"));
#endif
/*
* Define the local Ip address, host name, default home page and the
* root web directory.
*/
struct in_addr intaddr;
intaddr.s_addr = inet_addr(strIP .toUtf8().data());
/*
* Set ../www as the root web
*/
char *cp;
char* dir = NULL;
getcwd(dir, sizeof(dir));
if ((cp = strrchr(dir, '/')))
{
*cp = '\0';
}
char* WebDir = NULL;
sprintf(WebDir, "%s/%s", dir, strWeb.toUtf8().data());
/*
* Configure the web server options before opening the web server
*/
websSetDefaultDir(pWebDir);
SAVE_DELETE_ARRAY(dir);
SAVE_DELETE_ARRAY(WebDir);
char_t wbuf[128] = {0};
char *cp = inet_ntoa(intaddr);
ascToUni(wbuf, cp, min(strlen(cp) + 1, sizeof(wbuf)));
websSetIpaddr(wbuf);
ascToUni(wbuf, host, min(strlen(host) + 1, sizeof(wbuf)));
websSetHost(wbuf);
/*
* Configure the web server options before opening the web server
*/
websSetDefaultPage("default.asp");
websSetPassword( (char_t*)_T(""));
/*
* Open the web server on the given port. If that port is taken, try
* the next sequential port for up to "retries" attempts.
*/
websOpenServer(m_nPort, nRPort);
/*
* First create the URL handlers. Note: handlers are called in sorted order
* with the longest path handler examined first. Here we define the security
* handler, forms handler and the default web page handler.
*/
websUrlHandlerDefine((char_t*)_T(""), NULL, 0, websSecurityHandler,WEBS_HANDLER_FIRST);
websUrlHandlerDefine((char_t*)_T("/goform"), NULL, 0, websFormHandler, 0);
websUrlHandlerDefine((char_t*)_T("/cgi-bin"), NULL, 0, websCgiHandler, 0);
websUrlHandlerDefine((char_t*)_T(""), NULL, 0, websDefaultHandler,WEBS_HANDLER_LAST);
/*
* Now define two test procedures. Replace these with your application
* relevant ASP script procedures and form functions.
*/
registeredHandler(); //注册函数 如asp函数和表单处理函数(自定义函数)
/*
* Create the Form handlers for the User Management pages
*/
#ifdef USER_MANAGEMENT_SUPPORT
formDefineUserMgmt();
#endif
/*
* Create a handler for the default home page
*/
websUrlHandlerDefine((char_t*)_T("/"),NULL,0,websHomePageHandler,0);
return 0;
}
//Home page handler
int QWebServerThread::websHomePageHandler(webs_t wp, char_t *urlPrefix, char_t *webDir,int arg, char_t *url, char_t *path, char_t *query)
{
(void*)(urlPrefix);
(void*)(webDir);
(void*)(arg);
(void*)(path);
(void*)(query);
//If the empty or "/" URL is invoked, redirect default URLs to the home page
if(*url == '\0' || gstrcmp(url, (char_t*)_T("/")) == 0)
{
websRedirect(wp, (char_t*)WEBS_DEFAULT_HOME);
return 1;
}
return 0;
}
#ifdef B_STATS
void QWebBase::memLeaks()
{
int fd;
if ((fd = gopen(_T("leak.txt"), O_CREAT | O_TRUNC | O_WRONLY, 0666)) >= 0) {
bstats(fd, printMemStats);
close(fd);
}
}
//Print memory usage / leaks
void QWebBase::printMemStats(int handle, char_t *fmt, ...)
{
va_list args;
char_t buf[256];
va_start(args, fmt);
vsprintf(buf, fmt, args);
va_end(args);
write(handle, buf, strlen(buf));
}
#endif
GoAhead2.5移植到ARM教程的更多相关文章
- Qt 4.7.2移植到ARM教程
Qt的移植包括步骤如下: 1.下载并安装VMware WorkStation 12(最好比较高级的版本,早期的版本共享目录在虚拟机里可能显 示不了). 2.下载ubuntu 14.0.4(最好是lts ...
- iTOP-4412开发板-实战教程-ssh服务器移植到arm开发板
本文转自迅为开发板:http://www.topeetboard.com 在前面实战教程中,移植了“串口文件传输工具”,整个移植过程是比较简单的,而且我 们没有做任何协议方面的了解,只是“配置”+“编 ...
- 【Linux开发】【Qt开发】ARM QT移植详细步骤教程
ARM QT移植详细步骤教程 米尔SAM9X5和A5D3X上默认的Qt版本是4.5.3,当这个版本的Qt库不能满足实际开发需求时,可通过此方法制定Qt开发.运行环境. 移植的步骤如下: 1.下载新版q ...
- iTOP-IMX6UL 实战项目:ssh 服务器移植到 arm 开发板
实验环境:迅为提供的Ubuntu12.04.2 以及虚拟机 编译器:arm-2009q3 编译器 开发板系统:QT系统 开发板使用手册中给Windows 系统安装了 ssh 客户端,给 Ubunt ...
- 将SQLite移植到ARM板上 (转)
SQLite,是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它, 它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够 ...
- 怎样将lua移植到arm平台的linux内核
将脚本移植到内核是一件非常酷的事情,lua已经被移植到NetBSD的内核中,也有一个叫lunatik的项目把lua移植到了linux内核.仅仅可惜仅仅支持x86.不支持arm,在网上搜索了下,没有找到 ...
- SQL数据库移植到ARM板步骤
SQL作为一种存储数据的数据结构,具有体积小(能堵存储的数据多),容易移植等优点.例如,在Ubuntu或者ARM开发板上被大量应用.下面就简单说一下SQL移植到ARM板的步骤. 下载源代码 (记得在家 ...
- W5200移植W5500驱动教程
说明,移植例程为我按照这个教程移植的例程,测试通过.工程模板为我经常使用的一个w5500模板,可以在里面直接添加文件编程.1. 将driver文件夹中W5500文件夹和所有.c文件复制到工程/sour ...
- ffmpeg之移植到ARM
移植方法分为两种:第一种手工移植,第二种buildroot移植. 第一种手工移植: 优点:灵活性高 缺点:重复工作多 一.配置 ./configure --enable-memalign-hack - ...
随机推荐
- 众签demo
众签demo using System; using System.Collections.Generic; using System.Linq; using System.Text; using S ...
- iframe内部刷新后跳转锚点
开发过程中需要在iframe内容页中点击刷新按钮刷新页面并跳转至页面底部,编写js函数在url后面加上锚点名称#mao,但发现并未达到预期效果,通过测试发现锚点只有在第一次访问页面的时候才会生效,所有 ...
- 24 The Go image package go图片包:图片包的基本原理
The Go image package go图片包:图片包的基本原理 21 September 2011 Introduction The image and image/color packag ...
- geoserver 启动闪退
跟JDK版本有关: 比如geoserver2.11需要JDK版本为JDK1.8 windows配置两个jdk环境: 网上有方法,但如果只需要满足geoserver的话,可以只安装jdk(注意jdk和j ...
- python基础-类的属性(类属性,实例属性,私有属性)
一:类的属性 类的属性分为:类属性(公有属性),实例属性和私有属性. 1)类属性(公有属性(静态字段): 类定义时直接指定的属性(不是在__init__方法中),可以通过类名直接访问属性,并且保存 ...
- MySQL 5.1完全卸载
第一步:控制面板里的增加删除程序内进行删除 第二步:删除MySQL文件夹下的my.ini文件,如果备份好,可以直接将文件夹全部删除 第三步:regedit进入注册表 HKEY_LOCAL_MACHIN ...
- 美团外卖商家获取订单-signToken取值
需要抓取美团历史订单,请联系QQ:858-048-581所需工具: findller chrome 获取外卖历史订单地址为: http://e.waimai.meituan.com/v2/order/ ...
- Bootstrap进阶五:Web开发中很实用的交互效果积累
1.页面切换效果 我们已经在示例中罗列了一组动画,可以被应用到页面切换过程中,创造出很有趣的导航效果.  2.视差滚动(parallax-slider) 视差滚动(parallax-slider)已 ...
- 回文树练习 Part1
URAL - 1960 Palindromes and Super Abilities 回文树水题,每次插入时统计数量即可. #include<bits/stdc++.h> using ...
- Spring单例 和 Scope注解
关键字 @Scope @Qualifier Singleton 单例 Spring是单例模式.结合Springboot的例子. Controller @Autowired private Tes ...