you will want to spawn off your own webserver thread via pthreads, and run a loop in there.
Also make sure you're not busy-polling the CPU (causing 100% load with your thread).
If you can't figure out how to do an event based activation of your thread, place a sleep for
0.1 seconds into your loop. Doesn't this server offer any blocking call for handling incoming
requests?
Christian
right now the entire server is called using this
#include <string.h>
#include "mongoose.h"
static int event_handler(struct mg_connection *conn, enum mg_event ev) {
if (ev == MG_AUTH) {
return MG_TRUE; // Authorize all requests
} else if (ev == MG_REQUEST && !strcmp(conn->uri, "/")) {
mg_printf_data(conn, "%s", "{'requests': [{'type':'");
mg_printf_data(conn, "%s", conn->request_method);
mg_printf_data(conn, "%s", "' },{'query':'");
mg_printf_data(conn, "%s", conn->query_string);
mg_printf_data(conn, "%s", "'},{'requesting':'");
if( !strcmp(conn->query_string, "request=test") ){
mg_printf_data(conn, "%s", "test");
} else { }
mg_printf_data(conn, "%s", "'}],'hashrates': [{'last':'");
mg_printf_data(conn, "%s", "12687");
mg_printf_data(conn, "%s", "' }]}");
return MG_TRUE; // Mark as processed
} else {
return MG_FALSE; // Rest of the events are not processed
}
}
int main(void){
struct mg_server *server = mg_create_server(NULL, event_handler);
mg_set_option(server, "document_root", ".");
mg_set_option(server, "listening_port", "127.0.0.1:81");
mg_set_option(server, "enable_directory_listing", "no");
for (;;) {
mg_poll_server(server, 1000); // Infinite loop, Ctrl-C to stop
}
mg_destroy_server(&server);
return 0;
}
obviously the part in the main function is located elsewhere in ccminer,
but that is all the code i need to try and implement. right now running that code by itself works, its just putting that code into ccminer and replacing the part for hashrate with the actual hashrate code.
then implement a new case for the server port to be defined so every launched ccminer will have individual different ports for individual reporting
i am going to have a look at the pthread, by the looks of it i could declare a new pthread_join before the line
pthread_join(thr_info[work_thr_id].pth, NULL);
i then end the server just before where you end the timer
timeEndPeriod(1);
and i start it in the main just before you declare the main heading text