36 " -V 'log level' : set the log level (LOG_NULL, LOG_NOTICE, LOG_INFO, LOG_ERR, LOG_DEBUG)\n"
40int main(
int argc,
char* argv[]) {
44 while ((
getoptret = getopt(argc, argv,
"hV:")) != EOF) {
47 if (!strncmp(
"LOG_NULL", optarg, 8)) {
49 }
else if (!strncmp(
"LOG_NOTICE", optarg, 10)) {
51 }
else if (!strncmp(
"LOG_INFO", optarg, 8)) {
53 }
else if (!strncmp(
"LOG_ERR", optarg, 7)) {
55 }
else if (!strncmp(
"LOG_DEBUG", optarg, 9)) {
58 fprintf(stderr,
"%s is not a valid log level.\n", optarg);
71 n_log(
LOG_INFO,
"Connecting to wss://echo.websocket.org:443/ ...");
75 fprintf(stdout,
"WebSocket echo server unreachable, skipping\n");
81 memset(&greeting, 0,
sizeof(greeting));
87 const char* test_msg =
"nilorea ws test";
96 memset(&msg, 0,
sizeof(msg));
100 fprintf(stdout,
"WebSocket echo test PASSED\n");
102 fprintf(stdout,
"WebSocket echo test: got response (opcode %d)\n", msg.
opcode);
115 fprintf(stdout,
"OpenSSL not available, skipping WebSocket test\n");
#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
#define free_nstr(__ptr)
free a N_STR structure and set the pointer to NULL
N_STR * payload
message payload
N_WS_CONN * n_ws_connect(const char *host, const char *port, const char *path, int use_ssl)
Connect to a WebSocket server (ws:// or wss://).
#define N_WS_OP_TEXT
WebSocket opcodes per RFC 6455.
int n_ws_recv(N_WS_CONN *conn, N_WS_MESSAGE *msg_out)
Receive one WebSocket frame.
void n_ws_conn_free(N_WS_CONN **conn)
Free a WebSocket connection structure.
int n_ws_send(N_WS_CONN *conn, const char *payload, size_t len, int opcode)
Send a WebSocket frame (client always masks).
N_STR and string function declaration.