Closed shivagittool closed 2 years ago
Hello @shivagittool ,
Your question isn't specific to ulfius but a matter of daemon programming.
On my case I use a pthread condition to wait for an end signal, see my projects like Taliesin or esras, but you have other solutions like forks.
You can search for "Linux daemon c example" to help you.
Hai @babelouest
I need to open the REST API port continuously with out closing it. so that I could able to fetch the data from front end GUI with out any data loss.
As mentioned in the below code I'm using sleep(3) instead of getchar(), so that after 3 seconds, I'm not able to fetch the data from my front end application.
Could you please help me to resolve this issue. Thank you ////////////////////////////////////////////////////////////////////////////////////////
include
include
define PORT 8080
/**
/**
main function */ int main(void) { struct _u_instance instance;
// Initialize instance with the port number if (ulfius_init_instance(&instance, PORT, NULL, NULL) != U_OK) { fprintf(stderr, "Error ulfius_init_instance, abort\n"); return(1); }
// Endpoint list declaration ulfius_add_endpoint_by_val(&instance, "GET", "/helloworld", NULL, 0, &callback_hello_world, NULL);
// Start the framework if (ulfius_start_framework(&instance) == U_OK) { printf("Start framework on port %d\n", instance.port);
// Wait for the user to press on the console to quit the application
// getchar();
///////////////////////////////////////////
sleep(3); // 3 seconds delay i'm using
/////////////////////////////////////////
} else {
fprintf(stderr, "Error starting framework\n");
}
printf("End framework\n");
ulfius_stop_framework(&instance); ulfius_clean_instance(&instance);
return 0; }