Skip to content

Commit

Permalink
net_skeleton -> fossa
Browse files Browse the repository at this point in the history
  • Loading branch information
cpq committed Nov 3, 2014
1 parent f2ef18a commit f193f06
Show file tree
Hide file tree
Showing 24 changed files with 58 additions and 58 deletions.
54 changes: 27 additions & 27 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

image:{buildstatus-badge}[Build Status,link={buildstatus-uri}]

image::https://drone.io/github.com/cesanta/net_skeleton/status.png[Build Status,link=https://drone.io/github.com/cesanta/net_skeleton/latest]
image::https://coveralls.io/repos/cesanta/net_skeleton/badge.png?branch=master[Coverage Status,link=https://coveralls.io/r/cesanta/net_skeleton?branch=master]
image::https://drone.io/github.com/cesanta/fossa/status.png[Build Status,link=https://drone.io/github.com/cesanta/fossa/latest]
image::https://coveralls.io/repos/cesanta/fossa/badge.png?branch=master[Coverage Status,link=https://coveralls.io/r/cesanta/fossa?branch=master]


Net Skeleton is a multi-protocol networking library written in C.
Fossa is a multi-protocol networking library written in C.
It provides easy to use event-driven interface that allows to implement
network protocols or scalable network applications with little effort.
Net Skeleton releives developers from the burden of network programming
Fossa releives developers from the burden of network programming
complexity and let them concentrate on the logic, saving time and money.

Net Skeleton has built-in support for several protocols, like
HTTP and Websocket, and is ideal for embedded environments. Net Skeleton
Fossa has built-in support for several protocols, like
HTTP and Websocket, and is ideal for embedded environments. Fossa
has been designed as an open source platform for connecting devices and
bringing them online.

Expand All @@ -35,7 +35,7 @@ bringing them online.

== Concept

Net Skeleton is a non-blocking, asyncronous event manager described by
Fossa is a non-blocking, asyncronous event manager described by
`struct ns_mgr` structure. That structure holds active connections.
Connections could be either *listening*, *client* or *accepted*.
Client connections are created by
Expand All @@ -52,15 +52,15 @@ function for each of those events.

Each connection has send and receive buffer, `struct ns_connection::send_iobuf`
and `struct ns_connection::recv_iobuf` respectively. When data arrives,
Net Skeleton appends received data to the `recv_iobuf` and
Fossa appends received data to the `recv_iobuf` and
triggers `NS_RECV` event. User may send data back (`ns_send()` or
`ns_printf()`), which appends data to the `send_iobuf`. When Net Skeleton
`ns_printf()`), which appends data to the `send_iobuf`. When Fossa
successfully writes data to the socket, it discards it from `send_iobuf` and
sends `NS_SEND` event. When connection is closed, `NS_CLOSE` event is sent.

image::http://cesanta.com/images/net_skeleton/iobuf.png[]
image::http://cesanta.com/images/fossa/iobuf.png[]

== Using Net Skeleton
== Using Fossa

1. Define an event handler function.
2. Initialize mgr by calling `ns_mgr_init()`.
Expand All @@ -72,7 +72,7 @@ an event handler function.

[source,c]
----
#include "net_skeleton.h"
#include "fossa.h"
// This event handler implements TCP echo server
static void ev_handler(struct ns_connection *nc, int ev, void *ev_data) { // 1
Expand Down Expand Up @@ -104,13 +104,13 @@ int main(void) {
----


Net Skeleton accepts incoming connections, reads and writes data, and
Fossa accepts incoming connections, reads and writes data, and
calls specified event handler for each connection when appropriate. An
event handler should examine received data, set connection flags if needed,
and send data back to the client by `ns_send()` or `ns_printf()`. Here is a
typical event flow for the accepted connection:
`NS_ACCEPT` -> `NS_RECV` -> .... -> `NS_CLOSE`. Below is a complete list
of events triggered by Net Skeleton:
of events triggered by Fossa:

NS_ACCEPT:: sent when new server connection is accepted by a
listening connection. `void *ev_data` is `union socket_address`
Expand Down Expand Up @@ -141,41 +141,41 @@ static void ev_handler(struct ns_connection *nc, int ev, void *ev_data) {
NS_RECV:: New data is received and appended to the end of `recv_iobuf`.
`void *ev_data` is `int *num_received_bytes`.

WARNING: Net Skeleton uses `realloc()` to expand receive buffer.
WARNING: Fossa uses `realloc()` to expand receive buffer.
It is user's responsibility to discard processed
data from the beginning of receive buffer, note the `iobuf_remove()`
call in the example above.

NS_SEND:: Net Skeleton has written data to the remote peer and discarded
NS_SEND:: Fossa has written data to the remote peer and discarded
written data from the `send_iobuf`. `void *ev_data` is `int *num_sent_bytes`

NS_POLL:: Sent to all connections on each invocation of `ns_server_poll()`

An event handler can set `struct ns_connection::flags` attribute to control
the behavior of the connection. Below is a list of connection flags:

* `NSF_FINISHED_SENDING_DATA` tells Net Skeleton that all data has been
appended to the `send_iobuf`. As soon as Net Skeleton sends it to the
* `NSF_FINISHED_SENDING_DATA` tells Fossa that all data has been
appended to the `send_iobuf`. As soon as Fossa sends it to the
socket, the connection will be closed.
* `NSF_BUFFER_BUT_DONT_SEND` tells Net Skeleton to append data to the
* `NSF_BUFFER_BUT_DONT_SEND` tells Fossa to append data to the
`send_iobuf` but hold on sending it, because the data will be modified
later and then will be sent by clearing `NSF_BUFFER_BUT_DONT_SEND` flag.
* `NSF_SSL_HANDSHAKE_DONE` SSL only, set when SSL handshake is done
* `NSF_CONNECTING` set when connection is in connecting state after
`ns_connect()` call but connect did not finish yet
* `NSF_CLOSE_IMMEDIATELY` tells Net Skeleton to close the connection
* `NSF_CLOSE_IMMEDIATELY` tells Fossa to close the connection
immediately, usually after some error
* `NSF_LISTENING` set for all listening connections
* `NSF_UDP` set if connection is UDP
* `NSF_IS_WEBSOCKET` set by Net Skeleton if connection is a Websocket connection
* `NSF_IS_WEBSOCKET` set by Fossa if connection is a Websocket connection
* `NSF_WEBSOCKET_NO_DEFRAG` should be set by a user if user wants to switch
off automatic frame defragmentation
* `NSF_USER_1`, `NSF_USER_2`, `NSF_USER_3`, `NSF_USER_4` could be
used by a developer to store application-specific state

== Plain TCP/UDP/SSL API

CAUTION: Net skeleton manager instance is single threaded. It does not protect
CAUTION: Fossa manager instance is single threaded. It does not protect
it's data structures by mutexes, therefore all functions that are dealing
with particular event manager should be called from the same thread,
with exception of `mg_broadcast()` function. It is fine to have different
Expand All @@ -187,10 +187,10 @@ event managers handled by different threads.
- `struct ns_mgr` Container for a bunch of connections
- `struct iobuf` Describes piece of data

=== Functions for net skeleton manager
=== Functions for Fossa manager

void ns_mgr_init(struct ns_mgr *, void *user_data)::
Initializes net skeleton manager.
Initializes Fossa manager.

void ns_mgr_free(struct ns_mgr *)::

Expand Down Expand Up @@ -237,7 +237,7 @@ Connect to a remote host. If successful, `NS_CONNECT` event will be delivered
to the new connection. `addr` format is the same as for the `ns_bind()` call,
just an IP address becomes mandatory: `[PROTO://]HOST:PORT`
`PROTO` could be `tcp://` or `udp://`. If `HOST` is not an IP
address, Net Skeleton will resolve it - beware that standard blocking resolver
address, Fossa will resolve it - beware that standard blocking resolver
will be used. It is a good practice to pre-resolve hosts beforehands and
use only IP addresses to avoid blockin an IO thread.
Returns: new client connection, or `NULL` on error.
Expand All @@ -252,7 +252,7 @@ Also, a protocol prefix could be specified, valid prefixes are `tcp://` or
Note that for UDP listening connections, only `NS_RECV` and `NS_CLOSE`
are triggered.

If IP address is specified, Net Skeleton binds to a specific interface only.
If IP address is specified, Fossa binds to a specific interface only.
Also, port could be `"0"`, in which case a random non-occupied port number
will be chosen. Return value: a listening connection on success, or
`NULL` on error.
Expand Down Expand Up @@ -451,7 +451,7 @@ can be larger then `dst_len` that indicates an overflow.

== License

Net Skeleton is released under
Fossa is released under
http://www.gnu.org/licenses/old-licenses/gpl-2.0.html[GNU GPL v.2].
Businesses have an option to get non-restrictive, royalty-free commercial
license and professional support from http://cesanta.com[Cesanta Software].
2 changes: 1 addition & 1 deletion examples/json_rpc_server/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PROG = json_rpc_server
SOURCES = $(PROG).c ../../net_skeleton.c
SOURCES = $(PROG).c ../../fossa.c
CFLAGS = -W -Wall -I../.. -pthread $(CFLAGS_EXTRA)

all: $(PROG)
Expand Down
2 changes: 1 addition & 1 deletion examples/json_rpc_server/json_rpc_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* $ curl -d '{"id":1,method:"sum",params:[22,33]}' 127.0.0.1:8000
*/

#include "net_skeleton.h"
#include "fossa.h"

static const char *s_http_port = "8000";

Expand Down
2 changes: 1 addition & 1 deletion examples/netcat/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PROG = nc
SOURCES = $(PROG).c ../../net_skeleton.c
SOURCES = $(PROG).c ../../fossa.c
CFLAGS = -W -Wall -I../.. -pthread -DNS_ENABLE_SSL -lssl $(CFLAGS_EXTRA)

all: $(PROG)
Expand Down
2 changes: 1 addition & 1 deletion examples/netcat/nc.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

// This file implements "netcat" utility with SSL and traffic hexdump.

#include "net_skeleton.h"
#include "fossa.h"

static sig_atomic_t s_received_signal = 0;

Expand Down
2 changes: 1 addition & 1 deletion examples/publish_subscribe/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PROG = publish_subscribe
SOURCES = $(PROG).c ../../net_skeleton.c
SOURCES = $(PROG).c ../../fossa.c
CFLAGS = -W -Wall -I../.. -pthread $(CFLAGS_EXTRA)

all: $(PROG)
Expand Down
2 changes: 1 addition & 1 deletion examples/publish_subscribe/publish_subscribe.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//
// $Date: 2014-09-28 05:04:41 UTC $

#include "net_skeleton.h"
#include "fossa.h"

static void *stdin_thread(void *param) {
int ch, sock = * (int *) param;
Expand Down
2 changes: 1 addition & 1 deletion examples/restful_client/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PROG = restful_client
SOURCES = $(PROG).c ../../net_skeleton.c
SOURCES = $(PROG).c ../../fossa.c
CFLAGS = -W -Wall -I../.. -pthread $(CFLAGS_EXTRA)

all: $(PROG)
Expand Down
2 changes: 1 addition & 1 deletion examples/restful_client/restful_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* All rights reserved
*/

#include "net_skeleton.h"
#include "fossa.h"

static const char *s_target_address = "ajax.googleapis.com:80";
static int s_exit = 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/restful_server/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PROG = restful_server
SOURCES = $(PROG).c ../../net_skeleton.c
SOURCES = $(PROG).c ../../fossa.c
CFLAGS = -W -Wall -I../.. -pthread $(CFLAGS_EXTRA)

all: $(PROG)
Expand Down
2 changes: 1 addition & 1 deletion examples/restful_server/restful_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* All rights reserved
*/

#include "net_skeleton.h"
#include "fossa.h"

static const char *s_http_port = "8000";
static struct ns_serve_http_opts s_http_server_opts = { "." };
Expand Down
2 changes: 1 addition & 1 deletion examples/tcp_echo_server/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PROG = echo_server
SOURCES = $(PROG).c ../../net_skeleton.c
SOURCES = $(PROG).c ../../fossa.c
CFLAGS = -W -Wall -I../.. -pthread $(CFLAGS_EXTRA)

all: $(PROG)
Expand Down
2 changes: 1 addition & 1 deletion examples/tcp_echo_server/echo_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//
// $Date: 2014-09-28 05:04:41 UTC $

#include "net_skeleton.h"
#include "fossa.h"

static void ev_handler(struct ns_connection *nc, int ev, void *p) {
struct iobuf *io = &nc->recv_iobuf;
Expand Down
2 changes: 1 addition & 1 deletion examples/websocket_chat/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

PROG = websocket_chat
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
SOURCES = $(PROG).c ../../net_skeleton.c
SOURCES = $(PROG).c ../../fossa.c

$(PROG): $(SOURCES)
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
Expand Down
2 changes: 1 addition & 1 deletion examples/websocket_chat/websocket_chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* All rights reserved
*/

#include "net_skeleton.h"
#include "fossa.h"

static sig_atomic_t s_signal_received = 0;
static const char *s_http_port = "8000";
Expand Down
2 changes: 1 addition & 1 deletion net_skeleton.c → fossa.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "net_skeleton.h"
#include "fossa.h"
/* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*
Expand Down
File renamed without changes.
16 changes: 8 additions & 8 deletions modules/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
include modules.mk

all: ../net_skeleton.c ../net_skeleton.h
all: ../fossa.c ../fossa.h

../net_skeleton.h: Makefile $(HEADERS)
$(MAKE) -s --no-print-directory merge_net_skeleton.h >$@
../fossa.h: Makefile $(HEADERS)
$(MAKE) -s --no-print-directory merge_fossa.h >$@

../net_skeleton.c: Makefile $(SOURCES)
$(MAKE) -s --no-print-directory merge_net_skeleton.c >$@
../fossa.c: Makefile $(SOURCES)
$(MAKE) -s --no-print-directory merge_fossa.c >$@

merge_net_skeleton.h: Makefile $(HEADERS)
merge_fossa.h: Makefile $(HEADERS)
@cat $(HEADERS)

merge_net_skeleton.c: Makefile $(SOURCES)
@(echo '#include "net_skeleton.h"'; (cat $(SOURCES) | sed '/^#include "/d'))
merge_fossa.c: Makefile $(SOURCES)
@(echo '#include "fossa.h"'; (cat $(SOURCES) | sed '/^#include "/d'))
2 changes: 1 addition & 1 deletion modules/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#ifndef NS_DISABLE_HTTP_WEBSOCKET

#include "net_skeleton.h"
#include "fossa.h"
#include "sha1.h"
#include "util.h"
#include "http.h"
Expand Down
2 changes: 1 addition & 1 deletion modules/json-rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#ifndef NS_DISABLE_JSON_RPC

#include "net_skeleton.h"
#include "fossa.h"
#include "json-rpc.h"

int ns_rpc_create_reply(char *buf, int len, const struct ns_rpc_request *req,
Expand Down
2 changes: 1 addition & 1 deletion modules/skeleton.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* $Date: 2014-09-28 05:04:41 UTC $
*/

#include "net_skeleton.h"
#include "fossa.h"

#ifndef NS_MALLOC
#define NS_MALLOC malloc
Expand Down
2 changes: 1 addition & 1 deletion modules/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* All rights reserved
*/

#include "net_skeleton.h"
#include "fossa.h"
#include "util.h"

const char *ns_skip(const char *s, const char *end,
Expand Down
6 changes: 3 additions & 3 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PROG = unit_test
SSL=-DNS_ENABLE_SSL
CFLAGS = -W -Wall -Werror -I.. $(SSL) -DNS_ENABLE_IPV6 -pthread -g -O0 $(CFLAGS_EXTRA)
PEDANTIC=$(shell gcc --version 2>/dev/null | grep -q clang && echo -pedantic)
AMALGAMATED_SOURCES = $(PROG).c ../net_skeleton.c
AMALGAMATED_SOURCES = $(PROG).c ../fossa.c

include ../modules/modules.mk

Expand All @@ -14,8 +14,8 @@ all: clean ismerged $(PROG)_ansi $(PROG)_c99 $(PROG) $(PROG)_coverage
.PHONY: clean clean_coverage lcov valgrind $(PROG) $(PROG)_ansi $(PROG)_c99 $(PROG).exe $(PROG)_mingw.exe

ismerged:
$(MAKE) -C ../modules -s --no-print-directory merge_net_skeleton.c | diff ../net_skeleton.c -
$(MAKE) -C ../modules -s --no-print-directory merge_net_skeleton.h | diff ../net_skeleton.h -
$(MAKE) -C ../modules -s --no-print-directory merge_fossa.c | diff ../fossa.c -
$(MAKE) -C ../modules -s --no-print-directory merge_fossa.h | diff ../fossa.h -

$(PROG): Makefile
g++ -x c++ $(AMALGAMATED_SOURCES) -o $(PROG) $(CFLAGS) -lssl && ./$(PROG)
Expand Down
2 changes: 1 addition & 1 deletion test/unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* license, as set out in <http://cesanta.com/>.
*/

#include "net_skeleton.h"
#include "fossa.h"

#define FAIL(str, line) do { \
printf("%s:%d:1 [%s]\n", __FILE__, line, str); \
Expand Down

0 comments on commit f193f06

Please sign in to comment.