/** * Main function for this unit test. * * * @return 0 if test passed */ int main() { t_sched *sched; sched = rinoo_sched(); XTEST(sched != NULL); XTEST(rinoo_task_start(sched, server_func, NULL) == 0); XTEST(rinoo_task_start(sched, client_func, NULL) == 0); rinoo_sched_loop(sched); rinoo_sched_destroy(sched); XPASS(); }
/** * Main function for this unit test. * * * @return 0 if test passed */ int main() { t_sched *sched; sched = rinoo_sched(); XTEST(sched != NULL); XTEST(rinoo_task_start(sched, http_server, sched) == 0); XTEST(rinoo_task_start(sched, http_client, sched) == 0); rinoo_sched_loop(sched); rinoo_sched_destroy(sched); XPASS(); }
/** * Main function for this unit test * * * @return 0 if test passed */ int main() { t_sched *sched; sched = rinoo_sched(); XTEST(sched != NULL); XTEST(rinoo_task_start(sched, task1, sched) == 0); XTEST(rinoo_task_start(sched, task2, sched) == 0); XTEST(rinoo_task_start(sched, task3, sched) == 0); rinoo_sched_loop(sched); rinoo_sched_destroy(sched); XPASS(); }
/** * Main function for this unit test. * * * @return 0 if test passed */ int main() { t_sched *sched; mkdir(TEST_DIRECTORY, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); sched = rinoo_sched(); XTEST(sched != NULL); XTEST(rinoo_task_start(sched, check_file, sched) == 0); XTEST(rinoo_task_start(sched, event_generator, sched) == 0); rinoo_sched_loop(sched); rinoo_sched_destroy(sched); rmdir(TEST_DIRECTORY); XPASS(); }
/** * Starts a HTTP server which serves the given HTTP easy routes. * * @param sched Pointer to a scheduler * @param ip Ip address to bind * @param port Port to bind * @param routes Array of HTTP easy route to server * @param size Number of routes * * @return 0 on success, or -1 if an error occurs */ int rinoohttp_easy_server(t_rinoosched *sched, t_ip *ip, uint16_t port, t_rinoohttp_route *routes, int size) { t_rinoosocket *server; t_rinoohttp_easy_context *context; if (routes == NULL) { return -1; } server = rinoo_tcp_server(sched, ip, port); if (server == NULL) { return -1; } context = malloc(sizeof(*context)); if (context == NULL) { return -1; } context->socket = server; context->routes = routes; context->nbroutes = size; if (rinoo_task_start(sched, rinoohttp_easy_server_process, context) != 0) { free(context); return -1; } return 0; }
/** * Main function for this unit test. * * @return 0 if test passed */ int main() { t_rinoosched *sched; big_buffer = malloc(sizeof(*big_buffer) * BUFFER_SIZE); XTEST(big_buffer != NULL); memset(big_buffer, 'x', sizeof(*big_buffer) * BUFFER_SIZE); sched = rinoo_sched(); XTEST(sched != NULL); XTEST(rinoo_task_start(sched, server_func, sched) == 0); XTEST(rinoo_task_start(sched, client_func, sched) == 0); rinoo_sched_loop(sched); rinoo_sched_destroy(sched); free(big_buffer); XPASS(); }
/** * Main function for this unit test * * * @return 0 if test passed */ int main() { int i; t_sched *cur; t_sched *sched; memset(checker, 0, sizeof(*checker) * NBSPAWNS); sched = rinoo_sched(); XTEST(sched != NULL); XTEST(rinoo_spawn(sched, NBSPAWNS) == 0); for (i = 0; i <= NBSPAWNS; i++) { cur = rinoo_spawn_get(sched, i); XTEST(cur != NULL); if (i == 0) { XTEST(cur == sched); } XTEST(rinoo_task_start(cur, task, sched) == 0); } rinoo_sched_loop(sched); rinoo_sched_destroy(sched); for (i = 0; i <= NBSPAWNS; i++) { XTEST(checker[i] == 1); } XPASS(); }
int main() { t_sched *sched; sched = rinoo_sched(); rinoo_task_start(sched, task_server, sched); rinoo_sched_loop(sched); rinoo_sched_destroy(sched); return 0; }
/** * Main function for this unit test. * * * @return 0 if test passed */ int main() { t_rinoosched *sched; sched = rinoo_sched(); XTEST(sched != NULL); XTEST(rinoo_task_start(sched, dns_test, sched) == 0); rinoo_sched_loop(sched); rinoo_sched_destroy(sched); XPASS(); }
void task_server(void *sched) { t_socket *server; t_socket *client; server = rinoo_tcp_server(sched, IP_ANY, 4242); while ((client = rinoo_tcp_accept(server, NULL, NULL)) != NULL) { rinoo_task_start(sched, task_client, client); } rinoo_socket_destroy(server); }
int rsc_start(t_sched *sched) { uint16_t i; uint32_t j; t_sched *cur; if (config->threads > 1) { rinoo_spawn(sched, config->threads - 1); } for (i = 0; i < config->threads; i++) { cur = rinoo_spawn_get(sched, i); for (j = 0; j < config->connection.sessions; j++) { if (rinoo_task_start(cur, rsc_start_client, cur) != 0) { return -1; } thread_counter++; } } rinoo_task_start(sched, rsc_stat_aggregate, NULL); return 0; }
void server_func(void *unused(arg)) { t_socket *server; t_socket *client; server = rinoo_tcp_server(rinoo_sched_self(), IP_ANY, 4242); XTEST(server != NULL); client = rinoo_tcp_accept(server, NULL, NULL); XTEST(client != NULL); rinoo_log("client accepted"); rinoo_task_start(rinoo_sched_self(), process_client, client); rinoo_socket_destroy(server); }
void http_server(void *sched) { t_ip ip; uint16_t port; t_socket *server; t_socket *client; server = rinoo_tcp_server(sched, IP_ANY, 4242); XTEST(server != NULL); client = rinoo_tcp_accept(server, &ip, &port); XTEST(client != NULL); rinoo_log("server - accepting client (%s:%d)", inet_ntoa(*(struct in_addr *) &ip), port); rinoo_task_start(sched, http_server_process, client); rinoo_socket_destroy(server); }
void server_func(void *arg) { t_rinoosocket *server; t_rinoosocket *client; struct sockaddr_in6 addr = { 0 }; t_rinoosched *sched = arg; server = rinoo_socket(sched, &socket_class_tcp6); XTEST(server != NULL); addr.sin6_port = htons(4242); addr.sin6_family = AF_INET6; addr.sin6_addr = in6addr_any; XTEST(rinoo_socket_bind(server, (struct sockaddr *) &addr, sizeof(addr), 42) == 0); rinoo_log("server listening..."); client = rinoo_socket_accept(server, NULL, NULL); XTEST(client != NULL); rinoo_task_start(sched, process_client, client); rinoo_socket_destroy(server); }
/** * HTTP server processing callback * * @param context Pointer to a HTTP easy context */ static void rinoohttp_easy_server_process(void *context) { t_rinoosocket *client; t_rinoohttp_easy_context *c_context; t_rinoohttp_easy_context *s_context = context; while ((client = rinoo_tcp_accept(s_context->socket, NULL, NULL)) != NULL) { c_context = malloc(sizeof(*c_context)); if (c_context == NULL) { rinoo_socket_destroy(client); rinoo_socket_destroy(s_context->socket); free(s_context); return; } c_context->socket = client; c_context->routes = s_context->routes; c_context->nbroutes = s_context->nbroutes; rinoo_task_start(s_context->socket->node.sched, rinoohttp_easy_client_process, c_context); } rinoo_socket_destroy(s_context->socket); free(s_context); }