Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
server-sse.c File Reference

HTTP Server sse. More...

#include <getopt.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "soletta.h"
#include "sol-http.h"
#include "sol-http-server.h"
#include "sol-util.h"
#include "sol-util-file.h"

Macros

#define HTML_FILE
 

Functions

static void delete_cb (void *data, const struct sol_http_progressive_response *sse)
 
static void on_feed_done_cb (void *data, struct sol_http_progressive_response *sse, struct sol_blob *blob, int status)
 
static bool on_stdin (void *data, int fd, uint32_t flags)
 
static int request_cb (void *data, struct sol_http_request *request)
 
static int request_events_cb (void *data, struct sol_http_request *request)
 
static void shutdown_server (void)
 
 SOL_MAIN_DEFAULT (startup_server, shutdown_server)
 
static void startup_server (void)
 

Variables

static int port = 8080
 
static struct sol_ptr_vector responses = SOL_PTR_VECTOR_INIT
 
static struct sol_http_serverserver
 
static bool should_quit = false
 
static struct sol_fd * stdin_watch
 

Detailed Description

HTTP Server sse.

Sample server that return a response and keep it alive. It implements server sent events. The server sends the data typed in stdin and the data is broadcasted to all the clients connected.

To test it:

run ./server-sse -p 8080 open a browser in http://127.0.0.1:8080 or curl http://127.0.0.1:8080 type something

To see the usage help, -h or –help.

Macro Definition Documentation

#define HTML_FILE
Value:
"<!DOCTYPE html>" \
"<html>" \
"<body>" \
"<h1>Getting server updates</h1>" \
"<div id=\"result\"></div>" \
"<script>" \
"if(typeof(EventSource) !== \"undefined\") {" \
"var source = new EventSource(\"http://%.*s:%d/events\");" \
"source.onmessage = function(event) {" \
"document.getElementById(\"result\").innerHTML += event.data + \"<br>\";" \
"};" \
"} else {" \
"document.getElementById(\"result\").innerHTML = \"Sorry, your browser does not support server-sent events...\";" \
"}" \
"</script>" \
"</body>" \
"</html>"
Examples:
/src/samples/http/server-sse.c.

Referenced by request_cb().

Function Documentation

static void delete_cb ( void *  data,
const struct sol_http_progressive_response sse 
)
static
static void on_feed_done_cb ( void *  data,
struct sol_http_progressive_response sse,
struct sol_blob blob,
int  status 
)
static
static bool on_stdin ( void *  data,
int  fd,
uint32_t  flags 
)
static
static int request_cb ( void *  data,
struct sol_http_request request 
)
static
static int request_events_cb ( void *  data,
struct sol_http_request request 
)
static
static void shutdown_server ( void  )
static
SOL_MAIN_DEFAULT ( startup_server  ,
shutdown_server   
)
static void startup_server ( void  )
static

Variable Documentation

int port = 8080
static
struct sol_ptr_vector responses = SOL_PTR_VECTOR_INIT
static
struct sol_http_server* server
static

Referenced by shutdown_server(), and startup_server().

bool should_quit = false
static
Examples:
/src/samples/http/server-sse.c.

Referenced by delete_cb(), and on_stdin().

struct sol_fd* stdin_watch
static