44 " -V 'log level' : set the log level (LOG_NULL, LOG_NOTICE, LOG_INFO, LOG_ERR, LOG_DEBUG)\n"
57 fprintf(stdout,
"SSE event %d: type=%s data=%s id=%s\n",
60 (
event->data &&
event->data->data) ? event->
data->
data :
"(empty)",
61 (
event->id &&
event->id->data) ? event->
id->
data :
"(none)");
69int main(
int argc,
char* argv[]) {
73 while ((
getoptret = getopt(argc, argv,
"hV:")) != EOF) {
76 if (!strncmp(
"LOG_NULL", optarg, 8)) {
78 }
else if (!strncmp(
"LOG_NOTICE", optarg, 10)) {
80 }
else if (!strncmp(
"LOG_INFO", optarg, 8)) {
82 }
else if (!strncmp(
"LOG_ERR", optarg, 7)) {
84 }
else if (!strncmp(
"LOG_DEBUG", optarg, 9)) {
87 fprintf(stderr,
"%s is not a valid log level.\n", optarg);
100 n_log(
LOG_INFO,
"Connecting to SSE endpoint https://sse.dev/test ...");
104 fprintf(stdout,
"SSE server unreachable, skipping\n");
108 fprintf(stdout,
"SSE example completed, received %d events\n",
event_count);
113 fprintf(stdout,
"OpenSSL not available, skipping SSE test\n");
static N_SSE_CONN * g_conn
pointer to connection for callback to stop
static int event_count
counter for received events
static void on_sse_event(N_SSE_EVENT *event, N_SSE_CONN *conn, void *user_data)
SSE event callback.
#define MAX_EVENTS
maximum number of events to receive before stopping
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
#define LOG_NOTICE
normal but significant condition
#define LOG_NULL
no log output
#define LOG_INFO
informational
N_STR * event
event type (or NULL for default)
N_STR * id
last event ID (or NULL)
void n_sse_stop(N_SSE_CONN *conn)
Signal the SSE connection to stop reading.
void n_sse_conn_free(N_SSE_CONN **conn)
Free an SSE connection structure.
N_SSE_CONN * n_sse_connect(const char *host, const char *port, const char *path, int use_ssl, void(*on_event)(N_SSE_EVENT *, N_SSE_CONN *, void *), void *user_data)
Connect to an SSE endpoint and start reading events.
SSE event received from server.
N_STR and string function declaration.