File: teofossa.c Author: Kirill Scherba kiril.nosp@m.l@sc.nosp@m.herba.nosp@m..ru
Check integration teonet with fossa
The Teonet runs in main thread and the fossa runs in separate thread.
How to execute this test:
1) Start this test application in terminal:
tests/fossa/teofossa teofossa -a 127.0.0.1
2) Start telnet in other terminal:
telnet 0 1234
3) Type in the terminal some text:
Hello world!
4) Press Ctrl+C in the teonet terminal window to stop this test.
The text "Hello world!" will be:
- received by fossa in fossa event handler
- resends to teonet with the ksnetEvMgrAsync function
- send back to terminal with fossa ns_send function in teonet event handler
Created on July 20, 2015, 5:09 PM
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "fossa.h"
#define TFOSSA_VERSION VERSION
size_t data_len, void *user_data) {
switch (ev) {
{
char *d = strndup(data, data_len);
d[strcspn(d, "\r\n")] = 0;
printf("Async event was received %d bytes: %s\n", (int)data_len, (char*) d);
ns_send(user_data, data, data_len);
}
break;
default:
break;
}
}
static void ev_handler(
struct ns_connection *
nc,
int ev,
void *ev_data) {
struct mbuf *io = &nc->recv_mbuf;
switch (ev) {
case NS_RECV:
break;
default:
break;
}
}
struct ns_mgr mgr;
ns_mgr_init(&mgr, ke);
ns_bind(&mgr, "1234", ev_handler);
for (;;) {
ns_mgr_poll(&mgr, 100);
}
ns_mgr_free(&mgr);
return NULL;
}
int main(
int argc,
char** argv) {
if (err != 0) printf("\nCan't create thread :[%s]", strerror(err));
else printf("\nThread created successfully\n");
return (EXIT_SUCCESS);
}