HTTP usage optimizes

This commit is contained in:
Thulinma 2014-03-06 16:25:47 +01:00
parent 7a7e860bf2
commit 8cba8e597c
10 changed files with 11 additions and 44 deletions

View file

@ -463,9 +463,8 @@ namespace Connector_HTTP {
//wait for a response //wait for a response
while (myCConn->conn->connected() && conn.connected()){ while (myCConn->conn->connected() && conn.connected()){
conn.spool(); conn.spool();
if (myCConn->conn->Received().size() || myCConn->conn->spool()){
//check if the whole header was received //check if the whole header was received
if (H.Read(*(myCConn->conn))){ if (myCConn->conn->spool() && H.Read(*(myCConn->conn))){
//208 means the fragment is too new, retry in 3s //208 means the fragment is too new, retry in 3s
if (H.url == "208"){ if (H.url == "208"){
while (myCConn->conn->Received().size() > 0){ while (myCConn->conn->Received().size() > 0){
@ -489,7 +488,6 @@ namespace Connector_HTTP {
} }
break; //continue down below this while loop break; //continue down below this while loop
} }
}
//keep trying unless the timeout triggers //keep trying unless the timeout triggers
if (timeout++ > 4000){ if (timeout++ > 4000){
DEBUG_MSG(DLVL_HIGH, "Canceled connection %s, 4s timeout", uid.c_str()); DEBUG_MSG(DLVL_HIGH, "Canceled connection %s, 4s timeout", uid.c_str());
@ -632,8 +630,7 @@ namespace Connector_HTTP {
conn.setBlocking(false); //do not block on conn.spool() when no data is available conn.setBlocking(false); //do not block on conn.spool() when no data is available
HTTP::Parser Client; HTTP::Parser Client;
while (conn.connected()){ while (conn.connected()){
if (conn.spool() || conn.Received().size()){ if (conn.spool() && Client.Read(conn)){
if (Client.Read(conn)){
std::string handler = proxyGetHandleType(Client); std::string handler = proxyGetHandleType(Client);
DEBUG_MSG(DLVL_HIGH, "Received request: %s (%d) => %s (%s)", Client.getUrl().c_str(), conn.getSocket(), handler.c_str(), Client.GetVar("stream").c_str()); DEBUG_MSG(DLVL_HIGH, "Received request: %s (%d) => %s (%s)", Client.getUrl().c_str(), conn.getSocket(), handler.c_str(), Client.GetVar("stream").c_str());
#if DEBUG >= DLVL_HIGH #if DEBUG >= DLVL_HIGH
@ -665,7 +662,6 @@ namespace Connector_HTTP {
break; break;
} }
Client.Clean(); //clean for any possible next requests Client.Clean(); //clean for any possible next requests
}
}else{ }else{
Util::sleep(10); //sleep 10ms Util::sleep(10); //sleep 10ms
} }

View file

@ -163,8 +163,7 @@ namespace Connector_HTTP {
while (conn.connected()){ while (conn.connected()){
if ( !handlingRequest){ if ( !handlingRequest){
if (conn.spool() || conn.Received().size()){ if (conn.spool() && HTTP_R.Read(conn)){
if (HTTP_R.Read(conn)){
#if DEBUG >= 5 #if DEBUG >= 5
std::cout << "Received request: " << HTTP_R.getUrl() << std::endl; std::cout << "Received request: " << HTTP_R.getUrl() << std::endl;
#endif #endif
@ -267,7 +266,6 @@ namespace Connector_HTTP {
HTTP_S.SendResponse("200", "OK", conn); HTTP_S.SendResponse("200", "OK", conn);
} }
HTTP_R.Clean(); //clean for any possible next requests HTTP_R.Clean(); //clean for any possible next requests
}
}else{ }else{
//sleep for 250ms before next attempt //sleep for 250ms before next attempt
Util::sleep(250); Util::sleep(250);

View file

@ -44,18 +44,7 @@ namespace Connector_HTTP {
while (conn.connected()){ while (conn.connected()){
//Only attempt to parse input when not yet init'ed. //Only attempt to parse input when not yet init'ed.
if ( !inited){ if ( !inited){
if (conn.Received().size() || conn.spool()){ if (conn.spool() && HTTP_R.Read(conn)){
//make sure it ends in a \n
if ( *(conn.Received().get().rbegin()) != '\n'){
std::string tmp = conn.Received().get();
conn.Received().get().clear();
if (conn.Received().size()){
conn.Received().get().insert(0, tmp);
}else{
conn.Received().append(tmp);
}
}
if (HTTP_R.Read(conn.Received().get())){
#if DEBUG >= 5 #if DEBUG >= 5
std::cout << "Received request: " << HTTP_R.getUrl() << std::endl; std::cout << "Received request: " << HTTP_R.getUrl() << std::endl;
#endif #endif
@ -143,7 +132,6 @@ namespace Connector_HTTP {
} }
} }
}
if (inited){ if (inited){
unsigned int now = Util::epoch(); unsigned int now = Util::epoch();

View file

@ -128,8 +128,7 @@ namespace Connector_HTTP {
while (conn.connected()){ while (conn.connected()){
if ( !handlingRequest){ if ( !handlingRequest){
if (conn.spool() || conn.Received().size()){ if (conn.spool() && HTTP_R.Read(conn)){
if (HTTP_R.Read(conn)){
#if DEBUG >= 5 #if DEBUG >= 5
std::cout << "Received request: " << HTTP_R.getUrl() << std::endl; std::cout << "Received request: " << HTTP_R.getUrl() << std::endl;
#endif #endif
@ -217,7 +216,6 @@ namespace Connector_HTTP {
} }
ready4data = true; ready4data = true;
HTTP_R.Clean(); //clean for any possible next requests HTTP_R.Clean(); //clean for any possible next requests
}
}else{ }else{
Util::sleep(250); Util::sleep(250);
} }

View file

@ -46,8 +46,7 @@ namespace Connector_HTTP {
while (conn.connected()){ while (conn.connected()){
//Only attempt to parse input when not yet init'ed. //Only attempt to parse input when not yet init'ed.
if ( !inited){ if ( !inited){
if (conn.Received().size() || conn.spool()){ if (conn.spool() && HTTP_R.Read(conn)){
if (HTTP_R.Read(conn)){
#if DEBUG >= 5 #if DEBUG >= 5
std::cout << "Received request: " << HTTP_R.getUrl() << std::endl; std::cout << "Received request: " << HTTP_R.getUrl() << std::endl;
#endif #endif
@ -81,7 +80,6 @@ namespace Connector_HTTP {
HTTP_R.Clean(); //clean for any possible next requests HTTP_R.Clean(); //clean for any possible next requests
} }
} }
}
if (ready4data){ if (ready4data){
if ( !inited){ if ( !inited){
//we are ready, connect the socket! //we are ready, connect the socket!

View file

@ -45,8 +45,7 @@ namespace Connector_HTTP {
while (conn.connected()){ while (conn.connected()){
//Only attempt to parse input when not yet init'ed. //Only attempt to parse input when not yet init'ed.
if ( !inited){ if ( !inited){
if (conn.Received().size() || conn.spool()){ if (conn.spool() && HTTP_R.Read(conn)){
if (HTTP_R.Read(conn)){
#if DEBUG >= 5 #if DEBUG >= 5
std::cout << "Received request: " << HTTP_R.getUrl() << std::endl; std::cout << "Received request: " << HTTP_R.getUrl() << std::endl;
#endif #endif
@ -78,7 +77,6 @@ namespace Connector_HTTP {
HTTP_R.Clean(); //clean for any possible next requests HTTP_R.Clean(); //clean for any possible next requests
} }
} }
}
if (ready4data){ if (ready4data){
if ( !inited){ if ( !inited){
//we are ready, connect the socket! //we are ready, connect the socket!

View file

@ -445,8 +445,7 @@ namespace Connector_HTTP {
while (conn.connected()){ while (conn.connected()){
//Only attempt to parse input when not yet init'ed. //Only attempt to parse input when not yet init'ed.
if ( !inited){ if ( !inited){
if (conn.Received().size() || conn.spool()){ if (conn.spool() && HTTP_R.Read(conn)){
if (HTTP_R.Read(conn)){
DEBUG_MSG(DLVL_DEVEL, "Received request: %s", HTTP_R.getUrl().c_str()); DEBUG_MSG(DLVL_DEVEL, "Received request: %s", HTTP_R.getUrl().c_str());
conn.setHost(HTTP_R.GetHeader("X-Origin")); conn.setHost(HTTP_R.GetHeader("X-Origin"));
streamname = HTTP_R.GetHeader("X-Stream"); streamname = HTTP_R.GetHeader("X-Stream");
@ -560,7 +559,6 @@ namespace Connector_HTTP {
} }
inited = true; inited = true;
} }
}
}else{ }else{
unsigned int now = Util::epoch(); unsigned int now = Util::epoch();
if (now != lastStats){ if (now != lastStats){

View file

@ -53,8 +53,7 @@ namespace Connector_HTTP {
while (conn.connected()){ while (conn.connected()){
//Only attempt to parse input when not yet init'ed. //Only attempt to parse input when not yet init'ed.
if ( !inited){ if ( !inited){
if (conn.Received().size() || conn.spool()){ if (conn.spool() && HTTP_R.Read(conn)){
if (HTTP_R.Read(conn)){
#if DEBUG >= 5 #if DEBUG >= 5
std::cout << "Received request: " << HTTP_R.getUrl() << std::endl; std::cout << "Received request: " << HTTP_R.getUrl() << std::endl;
#endif #endif
@ -64,7 +63,6 @@ namespace Connector_HTTP {
HTTP_R.Clean(); //clean for any possible next requests HTTP_R.Clean(); //clean for any possible next requests
} }
} }
}
if (ready4data){ if (ready4data){
if ( !inited){ if ( !inited){
//we are ready, connect the socket! //we are ready, connect the socket!

View file

@ -217,8 +217,7 @@ namespace Connector_HTTP {
while (conn.connected()){ while (conn.connected()){
if ( !handlingRequest){ if ( !handlingRequest){
if (conn.spool() || conn.Received().size()){ if (conn.spool() && HTTP_R.Read(conn)){
if (HTTP_R.Read(conn)){
#if DEBUG >= 5 #if DEBUG >= 5
std::cout << "Received request: " << HTTP_R.getUrl() << std::endl; std::cout << "Received request: " << HTTP_R.getUrl() << std::endl;
#endif #endif
@ -443,8 +442,6 @@ namespace Connector_HTTP {
ready4data = true; ready4data = true;
//Clean for any possible next requests //Clean for any possible next requests
HTTP_R.Clean(); HTTP_R.Clean();
}
}else{ }else{
//Wait 250ms before checking for new data. //Wait 250ms before checking for new data.
Util::sleep(250); Util::sleep(250);

View file

@ -47,8 +47,7 @@ namespace Connector_HTTP {
while (conn.connected()){ while (conn.connected()){
//Only attempt to parse input when not yet init'ed. //Only attempt to parse input when not yet init'ed.
if ( !inited){ if ( !inited){
if (conn.Received().size() || conn.spool()){ if (conn.spool() && HTTP_R.Read(conn)){
if (HTTP_R.Read(conn)){
#if DEBUG >= 5 #if DEBUG >= 5
std::cout << "Received request: " << HTTP_R.getUrl() << std::endl; std::cout << "Received request: " << HTTP_R.getUrl() << std::endl;
#endif #endif
@ -143,7 +142,6 @@ namespace Connector_HTTP {
curIndex = 1; // set to 1, first srt 'track' curIndex = 1; // set to 1, first srt 'track'
} }
} }
}
unsigned int now = Util::epoch(); unsigned int now = Util::epoch();
if (now != lastStats){ if (now != lastStats){