• Stars
    star
    273
  • Rank 150,780 (Top 3 %)
  • Language
    C
  • License
    BSD 2-Clause "Sim...
  • Created over 12 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A tiny webserver for game development

Webby - A simple web server for game debugging

Webby is a web server intended for debugging tools inside a game or other program with a continously running main loop. It's intended to be used when all you need is something tiny and performance isn't a key concern.

Features

  • No dynamic memory allocations -- server memory is completely fixed
  • No threading, all I/O and serving happens on the calling thread
  • Supports socket keep-alives
  • Supports the 100-Continue scheme for file uploading
  • Basic support for WebSockets is available.

Because request/response I/O is synchronous on the calling thread, performance will suffer when you are serving data. For the use-cases Webby is intended for, this is fine. You can still run Webby in a background thread at your discretion if this is a problem.

Usage

  • Fill in a WebbyServerConfig structure
  • Compute the memory requirements by calling WebbyServerMemoryNeeded()
  • Allocate memory (or just use a static char array..)
  • Initialize the server by calling WebbyServerInit()
  • Every game frame, call WebbyServerUpdate()
    • Handle requests in your dispatch function
  • When it's time to shut down, call WebbyServerShutdown()

WebSocket Usage

  • Provide the WEBBY_SERVER_WEBSOCKETS flag at init time
  • In your ws_connect handler, decide to allow the upgrade request.
  • When the connection is established, your ws_connected handler is called. At this point, you can start sending WebSocket frames over the connection (and you can get incoming frames as well).
  • As frames come in, your ws_frame handler will be called. Webby doesn't try to merge frames together when the data is split into fragments, so you can be getting one binary/text frame followed by any number of continuation frames. It's up to your handler to make sense of the data and build a buffer as appropriate. The rationale is that otherwise Webby would need a lot more buffer space. To read the frame data, look at the payload size and then call WebbyRead to get at the data. Be careful to not read more than what is stated, or you will screw up the protocol.
  • To send WebSocket data, call WebbyBeginSocketFrame, passing in the type of frame (typically WEBBY_WS_OP_TEXT_FRAME or WEBBY_WS_OP_BINARY_FRAME). Then write an arbitrary amount of data using WebbyWrite. When you're done, call WebbyEndSocketFrame. Webby currently emits one WebSocket (continuation) frame for each WebbyWrite call (again, to reduce buffering overhead), so try to write big chunks if you can.
  • When a connection is closed, you will get a call to your ws_closed handler.

Request handling

When you configure the server, you give it a function pointer to your dispatcher. The dispatcher is called by Webby when a request has been fully read into memory and is ready for processing. The socket the request came in on has then been switched to blocking mode, and you're free to read any request data using WebbyRead() (if present, check content_length) and then write your response.

There are two ways to generate a response; explicit size or chunked.

When you know the size of the data

When you know in advance how big the response is going to be, you should pass that size in bytes to WebbyBeginResponse() (it will be sent as the Content-Length header). You then call WebbyWrite() to push that data out, and finally WebbyEndResponse() to finalize the response and prepare the socket for a new request.

When the response size is dynamic

Sometimes you want to generate an arbitrary amount of text in the response, and you don't know how much that will be. Rather than buffering everything in RAM, you can use chunked encoding. First call WebbyBeginResponse() as normal, but pass it -1 for the content length. This triggers sending the Transfer-Encoding: chunked header. You then call WebbyWrite() or WebbyPrintf() as desired until the response is complete. When you're done, call WebbyEndResponse() to finish up.

Limitations

  • There is not much error checking.

Author

Webby was written by Andreas Fredriksson (@deplinenoise on Twitter).

License

Webby is available under the BSD license. See the file LICENSE.

More Repositories

1

tundra

Tundra is a code build system that tries to be accurate and fast for incremental builds
C
431
star
2

ig-memtrace

Memory Tracing Software
C#
429
star
3

ig-debugheap

Debug heap useful for tracking down memory errors.
C
176
star
4

c-amplify

S-expression source translation and macro expansion utility
Common Lisp
81
star
5

deluxe68

A simple register allocator frontend for 68k assembly
C++
42
star
6

amiga-sdk

Bootstrap scripts for vbcc/vlink/vasm toolchain
C
27
star
7

ig-dedupe

OpenCL-based optical disc layout tool from Insomniac Games
C
26
star
8

trackloader

Amiga floppy trackloader bootblock + Demo startup.
Assembly
23
star
9

rlaunch

Amiga remote command launcher for cross development
C
20
star
10

sse-expr

Generate SSE expressions from prefix expressions
Common Lisp
20
star
11

m68kdecode

M68k instruction decoder written in Rust
Rust
14
star
12

alt

A Little Template Code Generator for C++
C
11
star
13

sse-docset

Create Dash docset from Intel Intrinsic Guide data
Perl
10
star
14

tundra-vsplugin

Visual Studio extension to improve interaction with Tundra 2.0 generated projects & solutions.
C#
10
star
15

blobct

Python library and C/Asm codegen to generate/work with binary blobs (load-in-place/mmap)
Python
6
star
16

intel-ref

Look up instructions in Intel's instruction reference PDFs and launches PDF viewer
Vim Script
6
star
17

win-path-control

Utility to add & remove paths from the system's PATH environment variable in the registry.
C++
5
star
18

vlink

Private copy of vlink with patches.
C
5
star
19

msvc-compiler-hook

Dynamic command line rewriting for Visual Studio 2008 to launch 3rd party tools, e.g. for cross compilation
C#
4
star
20

lemon-win32

Windows x64 build of the Lemon Parser generator - http://www.hwaci.com/sw/lemon/
C
4
star
21

c-amplify-swig

Experimental SWIG backend for c-amplify
C++
3
star
22

blobc3

Simple header/asm inc generator for mixed asm/c development
C#
3
star
23

ftgl

A repository of ftgl.
C++
2
star
24

vimcfg

This is where I keep my Vim configuration, with links to plugins as submodules where appropriate.
Shell
1
star