Embedded Web-Server Development
A crash course in writing embedded servers using the Snorkel API
Version .09
Walter E. Capers
01.19.2010
2
Table of Contents
Embedded Web-Server Development ....................................................................................................... 1
About Snorkel ............................................................................................................................................... 5
Keeping It Simple ...................................................................................................................................... 5
Getting Started .......................................................................................................................................... 7
Naming Conventions ............................................................................................................................. 8
Asynchronous Message Processing ...................................................................................................... 8
1 – Diving in, Your First Embedded Server .................................................................................................... 9
1.1 Embedding Snorkel ............................................................................................................................. 9
2 – Dynamic Content, Overloading URIs ..................................................................................................... 20
2.1 Overloading HTTP-GET ...................................................................................................................... 20
2.2 Overloading HTTP-POST .................................................................................................................... 27
2.3 Content Caching ................................................................................................................................ 37
2.4 Overloading MIMEs ........................................................................................................................... 37
2.5 URI Overloading and Wildcards ........................................................................................................ 49
3 – Overloading HTTP, Protocol Stacking .................................................................................................... 50
4 – Building Your First Bubble ..................................................................................................................... 62
4.2 Registering Functions with an Existing Bubble ................................................................................. 73
5 – Advanced Topics ................................................................................................................................... 76
5.1 Mutual Exclusion ............................................................................................................................... 76
5.1.1 Mutexes ..................................................................................................................................... 76
5.1.2 Events ......................................................................................................................................... 79
3
5.2 Snorkel Threads ................................................................................................................................ 80
5.2.1 Supported Thread Implementations .......................................................................................... 80
5.2.2 Worker threads .......................................................................................................................... 80
5.2.3 Run-and-forget Threads ............................................................................................................. 83
5.3 Memory Management ...................................................................................................................... 84
5.4 Server Optimization .......................................................................................................................... 84
5.4.1 Handler Thread Heap Storage .................................................................................................... 85
5.4.2 Using Larger TCP Windows ........................................................................................................ 85
6 – Miscellaneous Topics ............................................................................................................................ 87
6.1 Cookies .............................................................................................................................................. 87
6.2 User Authentication .......................................................................................................................... 88
6.2.1 Restricting User Access .............................................................................................................. 88
6.3 Queries and HTTP Header Values ..................................................................................................... 90
Roadmap ..................................................................................................................................................... 91
Other projects based on the Snorkel core .............................................................................................. 91
snorkel_init ......................................................................................................................................... 92
snorkel_obj_create ............................................................................................................................. 92
snorkel_get_sys................................................................................................................................... 95
snorkel_mutex_lock ............................................................................................................................ 96
snorkel_mutex_unlock ........................................................................................................................ 97
snorkel_marshal/snorkel_unmarshal ................................................................................................. 97
snorkel_event_set ............................................................................................................................... 98
snorkel_event_wait ............................................................................................................................ 99
snorkel_event_waittimed ................................................................................................................. 100
snorkel_obj_destroy ......................................................................................................................... 101
snorkel_obj_start .............................................................................................................................. 102
snorkel_printf, snorkel_put .............................................................................................................. 103
snorkel_mem_alloc ........................................................................................................................... 104
snorkel_mem_free ............................................................................................................................ 105
snorkel_obj_set ................................................................................................................................. 106
snorkel_thread_sleep ....................................................................................................................... 109
snorkel_obj_get ................................................................................................................................ 110
5
About Snorkel
Snorkel provides basic web server capabilities for natively built applications. The library supports both
dynamic and static content, has a very low memory profile, and provides features that simplify the
creation of web based application interfaces and/or proprietary protocols. Developed in C, adhering to
POSIX and Windows standards, Snorkel is a highly portable runtime library. It is also one of the fastest
embedded web-servers available, capitalizing on multi-core technology.
There are many advantages to using embedded web servers:
HTTP is well-studied cross-platform protocol.
HTTP clients, web-browsers, are readily available on all modern computers.
Intranet routers seldom block HTTP.
A growing trend in using embedded web servers within applications mirrors ubiquitous
computing.
Natively compiled embedded web servers require minimal system resources and are self-
standing requiring little or no software perquisites such as a JVM, Apache, Eclipse, or complex
frameworks, which may not be readily available or consistently supported on target platforms.
While there are several embedded web servers available on line, many have restrictive licenses, limited
platform support, or require large learning curves.
Keeping It Simple
Snorkel is not an end all be all web server solution. Its capabilities are limited in comparison to
mainstream web servers like Apache and Tomcat. Then again, Snorkel is an embedded server and does
not have to be. Embedded servers only need to provide enough functionality to expose or provide
access to the underlying business logic of the linked application. Further, by eliminating unnecessary
server side functionality, Snorkel’s contribution to an application’s resource consumption is minimal
making it one of the leaner solutions.
SNORKEL SUPPORTS THE FOLLOWING
HTTP 1.0
Open SSL
1
IPV4 and IPV6
URI overloading
1
Open-SSL support requires the Open-SSL runtimes and Snorkel-SSL runtime library, (snorkel32ssl or snorkel64ssl).
The Snorkel-SSL runtimes are not currently distributed outside of the US due to US trade laws.
评论0
最新资源