move multi_handle curl var into webserver class
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6265 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 4d181decedbb2c237d93c817461b944b730a39d4 Former-commit-id: 76ba7aa123e510d5b3961560ac0915671a4a65e7
This commit is contained in:
parent
2e008d8803
commit
c2ba6d3c56
2 changed files with 30 additions and 26 deletions
|
@ -25,7 +25,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <curl/multi.h>
|
|
||||||
#include <playerpref.h>
|
#include <playerpref.h>
|
||||||
#include <tgf.h>
|
#include <tgf.h>
|
||||||
#include "tgfclient.h"
|
#include "tgfclient.h"
|
||||||
|
@ -360,39 +359,23 @@ void NotificationManager::updateWebserverStatusUi(){
|
||||||
//initialize the notification manager
|
//initialize the notification manager
|
||||||
NotificationManager notifications;
|
NotificationManager notifications;
|
||||||
|
|
||||||
CURLM* multi_handle;
|
|
||||||
|
|
||||||
/* START webserver*/
|
|
||||||
WebServer::WebServer(){
|
WebServer::WebServer(){
|
||||||
|
|
||||||
void *configHandle;
|
|
||||||
char configFileUrl[256];
|
|
||||||
|
|
||||||
//initialize some curl var
|
//initialize some curl var
|
||||||
multi_handle = curl_multi_init();
|
this->multi_handle = curl_multi_init();
|
||||||
this->handle_count = 0;
|
this->handle_count = 0;
|
||||||
|
|
||||||
//get the preferencies file location
|
this->readConfiguration();
|
||||||
sprintf(configFileUrl, "%s%s", GfLocalDir(), "config/webserver.xml");
|
|
||||||
/*
|
|
||||||
//read the preferencies file
|
|
||||||
configHandle = GfParmReadFile(configFileUrl, GFPARM_RMODE_REREAD);
|
|
||||||
|
|
||||||
//get webServer url from the config
|
|
||||||
this->url = GfParmGetStr(configHandle, "WebServer Settings", "url","val");
|
|
||||||
|
|
||||||
GfLogInfo("WebServer - webserver url is: %s\n", this->url);
|
|
||||||
*/
|
|
||||||
this->url ="http://www.madbad.altervista.org/speed-dreams/webserver.php";
|
|
||||||
}
|
}
|
||||||
WebServer::~WebServer(){
|
WebServer::~WebServer(){
|
||||||
//cleanup curl
|
//cleanup curl
|
||||||
curl_multi_cleanup(multi_handle);
|
curl_multi_cleanup(this->multi_handle);
|
||||||
}
|
}
|
||||||
int WebServer::updateAsyncStatus(){
|
int WebServer::updateAsyncStatus(){
|
||||||
|
|
||||||
//perform the pending requests
|
//perform the pending requests
|
||||||
curl_multi_perform(multi_handle, &this->handle_count);
|
curl_multi_perform(this->multi_handle, &this->handle_count);
|
||||||
|
|
||||||
if( this->handle_count>0){
|
if( this->handle_count>0){
|
||||||
GfLogInfo("############################# ASYNC WAITING UPDATES: %i\n", this->handle_count);
|
GfLogInfo("############################# ASYNC WAITING UPDATES: %i\n", this->handle_count);
|
||||||
|
@ -408,7 +391,7 @@ int WebServer::updateAsyncStatus(){
|
||||||
int http_status_code;
|
int http_status_code;
|
||||||
const char *szUrl;
|
const char *szUrl;
|
||||||
|
|
||||||
while ((msg = curl_multi_info_read(multi_handle, &this->handle_count))) {
|
while ((msg = curl_multi_info_read(this->multi_handle, &this->handle_count))) {
|
||||||
if (msg->msg == CURLMSG_DONE) {
|
if (msg->msg == CURLMSG_DONE) {
|
||||||
eh = msg->easy_handle;
|
eh = msg->easy_handle;
|
||||||
|
|
||||||
|
@ -475,7 +458,7 @@ int WebServer::updateAsyncStatus(){
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "GET of %s returned http status code %d\n", szUrl, http_status_code);
|
fprintf(stderr, "GET of %s returned http status code %d\n", szUrl, http_status_code);
|
||||||
}
|
}
|
||||||
curl_multi_remove_handle(multi_handle, eh);
|
curl_multi_remove_handle(this->multi_handle, eh);
|
||||||
curl_easy_cleanup(eh);
|
curl_easy_cleanup(eh);
|
||||||
/* then cleanup the formpost chain */
|
/* then cleanup the formpost chain */
|
||||||
//curl_formfree(formpost);
|
//curl_formfree(formpost);
|
||||||
|
@ -524,7 +507,7 @@ int WebServer::addAsyncRequest(std::string const data){
|
||||||
}
|
}
|
||||||
|
|
||||||
//add the request to the queque
|
//add the request to the queque
|
||||||
curl_multi_add_handle(multi_handle, curl);
|
curl_multi_add_handle(this->multi_handle, curl);
|
||||||
|
|
||||||
//pending request
|
//pending request
|
||||||
webserverState=WEBSERVER_SENDING;
|
webserverState=WEBSERVER_SENDING;
|
||||||
|
@ -602,6 +585,25 @@ int WebServer::sendGenericRequest (std::string data, std::string& serverReply){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebServer::readConfiguration (){
|
||||||
|
|
||||||
|
void *configHandle;
|
||||||
|
char configFileUrl[256];
|
||||||
|
/*
|
||||||
|
//get the preferencies file location
|
||||||
|
sprintf(configFileUrl, "%s%s", GfLocalDir(), "config/webserver.xml");
|
||||||
|
|
||||||
|
//read the preferencies file
|
||||||
|
configHandle = GfParmReadFile(configFileUrl, GFPARM_RMODE_REREAD);
|
||||||
|
|
||||||
|
//get webServer url from the config
|
||||||
|
this->url = GfParmGetStr(configHandle, "WebServer Settings", "url","val");
|
||||||
|
*/
|
||||||
|
this->url ="http://www.madbad.altervista.org/speed-dreams/webserver.php";
|
||||||
|
|
||||||
|
//GfLogInfo("WebServer - webserver url is: %s\n", this->url);
|
||||||
|
}
|
||||||
|
|
||||||
int WebServer::readUserConfig (int userId){
|
int WebServer::readUserConfig (int userId){
|
||||||
void *prHandle;
|
void *prHandle;
|
||||||
char prefFileUrl[256];
|
char prefFileUrl[256];
|
||||||
|
@ -624,6 +626,7 @@ int WebServer::readUserConfig (int userId){
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebServer::sendLogin (int userId){
|
int WebServer::sendLogin (int userId){
|
||||||
std::string serverReply;
|
std::string serverReply;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <curl/multi.h>
|
||||||
class NotificationManager {
|
class NotificationManager {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -72,6 +72,7 @@ class NotificationManager {
|
||||||
class WebServer {
|
class WebServer {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void readConfiguration();
|
||||||
int readUserConfig(int userId);
|
int readUserConfig(int userId);
|
||||||
|
|
||||||
int sendGenericRequest (std::string data, std::string& serverReply);
|
int sendGenericRequest (std::string data, std::string& serverReply);
|
||||||
|
@ -97,7 +98,7 @@ class WebServer {
|
||||||
int addAsyncRequest(std::string const data);
|
int addAsyncRequest(std::string const data);
|
||||||
|
|
||||||
//curl
|
//curl
|
||||||
//CURLM multi_handle;
|
CURLM* multi_handle;
|
||||||
int handle_count;
|
int handle_count;
|
||||||
std::string curlServerReply;
|
std::string curlServerReply;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue