Updated connectors to make use of the new Util::Config::serveForkedSocket function, fixed several open-socket-related issues.
This commit is contained in:
parent
ebf0b41039
commit
c9ac10ebe4
12 changed files with 60 additions and 306 deletions
|
@ -102,13 +102,13 @@ namespace Connector_HTTP {
|
||||||
///\param H The request to be handled.
|
///\param H The request to be handled.
|
||||||
///\param conn The connection to the client that issued the request.
|
///\param conn The connection to the client that issued the request.
|
||||||
///\return A timestamp indicating when the request was parsed.
|
///\return A timestamp indicating when the request was parsed.
|
||||||
long long int proxyHandleUnsupported(HTTP::Parser & H, Socket::Connection * conn){
|
long long int proxyHandleUnsupported(HTTP::Parser & H, Socket::Connection & conn){
|
||||||
H.Clean();
|
H.Clean();
|
||||||
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver);
|
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver);
|
||||||
H.SetBody(
|
H.SetBody(
|
||||||
"<!DOCTYPE html><html><head><title>Unsupported Media Type</title></head><body><h1>Unsupported Media Type</h1>The server isn't quite sure what you wanted to receive from it.</body></html>");
|
"<!DOCTYPE html><html><head><title>Unsupported Media Type</title></head><body><h1>Unsupported Media Type</h1>The server isn't quite sure what you wanted to receive from it.</body></html>");
|
||||||
long long int ret = Util::getMS();
|
long long int ret = Util::getMS();
|
||||||
conn->SendNow(H.BuildResponse("415", "Unsupported Media Type"));
|
conn.SendNow(H.BuildResponse("415", "Unsupported Media Type"));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,13 +118,13 @@ namespace Connector_HTTP {
|
||||||
///\param H The request that was being handled upon timeout.
|
///\param H The request that was being handled upon timeout.
|
||||||
///\param conn The connection to the client that issued the request.
|
///\param conn The connection to the client that issued the request.
|
||||||
///\return A timestamp indicating when the request was parsed.
|
///\return A timestamp indicating when the request was parsed.
|
||||||
long long int proxyHandleTimeout(HTTP::Parser & H, Socket::Connection * conn){
|
long long int proxyHandleTimeout(HTTP::Parser & H, Socket::Connection & conn){
|
||||||
H.Clean();
|
H.Clean();
|
||||||
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver);
|
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver);
|
||||||
H.SetBody(
|
H.SetBody(
|
||||||
"<!DOCTYPE html><html><head><title>Gateway timeout</title></head><body><h1>Gateway timeout</h1>Though the server understood your request and attempted to handle it, somehow handling it took longer than it should. Your request has been cancelled - please try again later.</body></html>");
|
"<!DOCTYPE html><html><head><title>Gateway timeout</title></head><body><h1>Gateway timeout</h1>Though the server understood your request and attempted to handle it, somehow handling it took longer than it should. Your request has been cancelled - please try again later.</body></html>");
|
||||||
long long int ret = Util::getMS();
|
long long int ret = Util::getMS();
|
||||||
conn->SendNow(H.BuildResponse("504", "Gateway Timeout"));
|
conn.SendNow(H.BuildResponse("504", "Gateway Timeout"));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ namespace Connector_HTTP {
|
||||||
///\param H The request to be handled.
|
///\param H The request to be handled.
|
||||||
///\param conn The connection to the client that issued the request.
|
///\param conn The connection to the client that issued the request.
|
||||||
///\return A timestamp indicating when the request was parsed.
|
///\return A timestamp indicating when the request was parsed.
|
||||||
long long int proxyHandleInternal(HTTP::Parser & H, Socket::Connection * conn){
|
long long int proxyHandleInternal(HTTP::Parser & H, Socket::Connection & conn){
|
||||||
|
|
||||||
std::string url = H.getUrl();
|
std::string url = H.getUrl();
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ namespace Connector_HTTP {
|
||||||
H.SetBody(
|
H.SetBody(
|
||||||
"<?xml version=\"1.0\"?><!DOCTYPE cross-domain-policy SYSTEM \"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd\"><cross-domain-policy><allow-access-from domain=\"*\" /><site-control permitted-cross-domain-policies=\"all\"/></cross-domain-policy>");
|
"<?xml version=\"1.0\"?><!DOCTYPE cross-domain-policy SYSTEM \"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd\"><cross-domain-policy><allow-access-from domain=\"*\" /><site-control permitted-cross-domain-policies=\"all\"/></cross-domain-policy>");
|
||||||
long long int ret = Util::getMS();
|
long long int ret = Util::getMS();
|
||||||
conn->SendNow(H.BuildResponse("200", "OK"));
|
conn.SendNow(H.BuildResponse("200", "OK"));
|
||||||
return ret;
|
return ret;
|
||||||
} //crossdomain.xml
|
} //crossdomain.xml
|
||||||
|
|
||||||
|
@ -255,7 +255,7 @@ namespace Connector_HTTP {
|
||||||
H.SetBody(
|
H.SetBody(
|
||||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?><access-policy><cross-domain-access><policy><allow-from http-methods=\"*\" http-request-headers=\"*\"><domain uri=\"*\"/></allow-from><grant-to><resource path=\"/\" include-subpaths=\"true\"/></grant-to></policy></cross-domain-access></access-policy>");
|
"<?xml version=\"1.0\" encoding=\"utf-8\"?><access-policy><cross-domain-access><policy><allow-from http-methods=\"*\" http-request-headers=\"*\"><domain uri=\"*\"/></allow-from><grant-to><resource path=\"/\" include-subpaths=\"true\"/></grant-to></policy></cross-domain-access></access-policy>");
|
||||||
long long int ret = Util::getMS();
|
long long int ret = Util::getMS();
|
||||||
conn->SendNow(H.BuildResponse("200", "OK"));
|
conn.SendNow(H.BuildResponse("200", "OK"));
|
||||||
return ret;
|
return ret;
|
||||||
} //clientaccesspolicy.xml
|
} //clientaccesspolicy.xml
|
||||||
|
|
||||||
|
@ -268,8 +268,8 @@ namespace Connector_HTTP {
|
||||||
H.SetHeader("Content-Length", icon_len);
|
H.SetHeader("Content-Length", icon_len);
|
||||||
H.SetBody("");
|
H.SetBody("");
|
||||||
long long int ret = Util::getMS();
|
long long int ret = Util::getMS();
|
||||||
conn->SendNow(H.BuildResponse("200", "OK"));
|
conn.SendNow(H.BuildResponse("200", "OK"));
|
||||||
conn->SendNow((const char*)icon_data, icon_len);
|
conn.SendNow((const char*)icon_data, icon_len);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ namespace Connector_HTTP {
|
||||||
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver);
|
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver);
|
||||||
H.SetBody("<!DOCTYPE html><html><head><title>Stream "+streamname+"</title><style>BODY{color:white;background:black;}</style></head><body><script src=\"embed_"+streamname+".js\"></script></body></html>");
|
H.SetBody("<!DOCTYPE html><html><head><title>Stream "+streamname+"</title><style>BODY{color:white;background:black;}</style></head><body><script src=\"embed_"+streamname+".js\"></script></body></html>");
|
||||||
long long int ret = Util::getMS();
|
long long int ret = Util::getMS();
|
||||||
conn->SendNow(H.BuildResponse("200", "OK"));
|
conn.SendNow(H.BuildResponse("200", "OK"));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,7 +379,7 @@ namespace Connector_HTTP {
|
||||||
}
|
}
|
||||||
H.SetBody(response);
|
H.SetBody(response);
|
||||||
long long int ret = Util::getMS();
|
long long int ret = Util::getMS();
|
||||||
conn->SendNow(H.BuildResponse("200", "OK"));
|
conn.SendNow(H.BuildResponse("200", "OK"));
|
||||||
return ret;
|
return ret;
|
||||||
} //embed code generator
|
} //embed code generator
|
||||||
|
|
||||||
|
@ -391,12 +391,12 @@ namespace Connector_HTTP {
|
||||||
///\param conn The connection to the client that issued the request.
|
///\param conn The connection to the client that issued the request.
|
||||||
///\param connector The type of connector to be invoked.
|
///\param connector The type of connector to be invoked.
|
||||||
///\return A timestamp indicating when the request was parsed.
|
///\return A timestamp indicating when the request was parsed.
|
||||||
long long int proxyHandleThroughConnector(HTTP::Parser & H, Socket::Connection * conn, std::string & connector){
|
long long int proxyHandleThroughConnector(HTTP::Parser & H, Socket::Connection & conn, std::string & connector){
|
||||||
//create a unique ID based on a hash of the user agent and host, followed by the stream name and connector
|
//create a unique ID based on a hash of the user agent and host, followed by the stream name and connector
|
||||||
std::string uid = Secure::md5(H.GetHeader("User-Agent") + conn->getHost()) + "_" + H.GetVar("stream") + "_" + connector;
|
std::string uid = Secure::md5(H.GetHeader("User-Agent") + conn.getHost()) + "_" + H.GetVar("stream") + "_" + connector;
|
||||||
H.SetHeader("X-Stream", H.GetVar("stream"));
|
H.SetHeader("X-Stream", H.GetVar("stream"));
|
||||||
H.SetHeader("X-UID", uid); //add the UID to the headers before copying
|
H.SetHeader("X-UID", uid); //add the UID to the headers before copying
|
||||||
H.SetHeader("X-Origin", conn->getHost()); //add the UID to the headers before copying
|
H.SetHeader("X-Origin", conn.getHost()); //add the UID to the headers before copying
|
||||||
std::string request = H.BuildRequest(); //copy the request for later forwarding to the connector
|
std::string request = H.BuildRequest(); //copy the request for later forwarding to the connector
|
||||||
std::string orig_url = H.getUrl();
|
std::string orig_url = H.getUrl();
|
||||||
H.Clean();
|
H.Clean();
|
||||||
|
@ -462,8 +462,8 @@ namespace Connector_HTTP {
|
||||||
//set to only read headers
|
//set to only read headers
|
||||||
H.headerOnly = true;
|
H.headerOnly = true;
|
||||||
//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()){
|
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 (H.Read(*(myCConn->conn))){
|
||||||
|
@ -505,7 +505,7 @@ namespace Connector_HTTP {
|
||||||
}
|
}
|
||||||
//unset to only read headers
|
//unset to only read headers
|
||||||
H.headerOnly = false;
|
H.headerOnly = false;
|
||||||
if ( !myCConn->conn->connected() || !conn->connected()){
|
if ( !myCConn->conn->connected() || !conn.connected()){
|
||||||
//failure, disconnect and sent error to user
|
//failure, disconnect and sent error to user
|
||||||
myCConn->conn->close();
|
myCConn->conn->close();
|
||||||
myCConn->inUse.unlock();
|
myCConn->inUse.unlock();
|
||||||
|
@ -518,23 +518,23 @@ namespace Connector_HTTP {
|
||||||
H.SetHeader("X-UID", uid);
|
H.SetHeader("X-UID", uid);
|
||||||
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver);
|
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver);
|
||||||
H.body = "";
|
H.body = "";
|
||||||
H.Proxy(*(myCConn->conn), *conn);
|
H.Proxy(*(myCConn->conn), conn);
|
||||||
myCConn->inUse.unlock();
|
myCConn->inUse.unlock();
|
||||||
}else{
|
}else{
|
||||||
//unknown length
|
//unknown length
|
||||||
H.SetHeader("X-UID", uid);
|
H.SetHeader("X-UID", uid);
|
||||||
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver);
|
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver);
|
||||||
conn->SendNow(H.BuildResponse("200", "OK"));
|
conn.SendNow(H.BuildResponse("200", "OK"));
|
||||||
//switch out the connection for an empty one - it makes no sense to keep these globally
|
//switch out the connection for an empty one - it makes no sense to keep these globally
|
||||||
Socket::Connection * myConn = myCConn->conn;
|
Socket::Connection * myConn = myCConn->conn;
|
||||||
myCConn->conn = new Socket::Connection();
|
myCConn->conn = new Socket::Connection();
|
||||||
myCConn->inUse.unlock();
|
myCConn->inUse.unlock();
|
||||||
long long int last_data_time = Util::getMS();
|
long long int last_data_time = Util::getMS();
|
||||||
//continue sending data from this socket and keep it permanently in use
|
//continue sending data from this socket and keep it permanently in use
|
||||||
while (myConn->connected() && conn->connected()){
|
while (myConn->connected() && conn.connected()){
|
||||||
if (myConn->Received().size() || myConn->spool()){
|
if (myConn->Received().size() || myConn->spool()){
|
||||||
//forward any and all incoming data directly without parsing
|
//forward any and all incoming data directly without parsing
|
||||||
conn->SendNow(myConn->Received().get());
|
conn.SendNow(myConn->Received().get());
|
||||||
myConn->Received().get().clear();
|
myConn->Received().get().clear();
|
||||||
last_data_time = Util::getMS();
|
last_data_time = Util::getMS();
|
||||||
}else{
|
}else{
|
||||||
|
@ -547,7 +547,7 @@ namespace Connector_HTTP {
|
||||||
}
|
}
|
||||||
myConn->close();
|
myConn->close();
|
||||||
delete myConn;
|
delete myConn;
|
||||||
conn->close();
|
conn.close();
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -622,17 +622,16 @@ namespace Connector_HTTP {
|
||||||
}
|
}
|
||||||
|
|
||||||
///\brief Function run as a thread to handle a single HTTP connection.
|
///\brief Function run as a thread to handle a single HTTP connection.
|
||||||
///\param pointer A Socket::Connection* indicating the connection to th client.
|
///\param conn A Socket::Connection indicating the connection to th client.
|
||||||
void proxyHandleHTTPConnection(void * pointer){
|
int proxyHandleHTTPConnection(Socket::Connection & conn){
|
||||||
Socket::Connection * conn = (Socket::Connection *)pointer;
|
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() || conn.Received().size()){
|
||||||
if (Client.Read(*conn)){
|
if (Client.Read(conn)){
|
||||||
std::string handler = proxyGetHandleType(Client);
|
std::string handler = proxyGetHandleType(Client);
|
||||||
#if DEBUG >= 4
|
#if DEBUG >= 4
|
||||||
std::cout << "Received request: " << Client.getUrl() << " (" << conn->getSocket() << ") => " << handler << " (" << Client.GetVar("stream")
|
std::cout << "Received request: " << Client.getUrl() << " (" << conn.getSocket() << ") => " << handler << " (" << Client.GetVar("stream")
|
||||||
<< ")" << std::endl;
|
<< ")" << std::endl;
|
||||||
long long int startms = Util::getMS();
|
long long int startms = Util::getMS();
|
||||||
#endif
|
#endif
|
||||||
|
@ -653,7 +652,7 @@ namespace Connector_HTTP {
|
||||||
}
|
}
|
||||||
#if DEBUG >= 4
|
#if DEBUG >= 4
|
||||||
long long int nowms = Util::getMS();
|
long long int nowms = Util::getMS();
|
||||||
std::cout << "Completed request " << conn->getSocket() << " " << handler << " in " << (midms - startms) << " ms (processing) / " << (nowms - midms) << " ms (transfer)" << std::endl;
|
std::cout << "Completed request " << conn.getSocket() << " " << handler << " in " << (midms - startms) << " ms (processing) / " << (nowms - midms) << " ms (transfer)" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if (closeConnection){
|
if (closeConnection){
|
||||||
break;
|
break;
|
||||||
|
@ -665,8 +664,8 @@ namespace Connector_HTTP {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//close and remove the connection
|
//close and remove the connection
|
||||||
conn->close();
|
conn.close();
|
||||||
delete conn;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} //Connector_HTTP namespace
|
} //Connector_HTTP namespace
|
||||||
|
@ -699,24 +698,8 @@ int main(int argc, char ** argv){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket::Server server_socket = Socket::Server(conf.getInteger("listen_port"), conf.getString("listen_interface"));
|
return conf.serveThreadedSocket(Connector_HTTP::proxyHandleHTTPConnection);
|
||||||
if ( !server_socket.connected()){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
conf.activate();
|
|
||||||
|
|
||||||
while (server_socket.connected() && conf.is_active){
|
|
||||||
Socket::Connection S = server_socket.accept();
|
|
||||||
if (S.connected()){ //check if the new connection is valid
|
|
||||||
//spawn a new thread for this connection
|
|
||||||
tthread::thread T(Connector_HTTP::proxyHandleHTTPConnection, (void *)(new Socket::Connection(S)));
|
|
||||||
//detach it, no need to keep track of it anymore
|
|
||||||
T.detach();
|
|
||||||
}else{
|
|
||||||
Util::sleep(10); //sleep 10ms
|
|
||||||
}
|
|
||||||
} //while connected and not requested to stop
|
|
||||||
server_socket.close();
|
|
||||||
if (Connector_HTTP::timeouter){
|
if (Connector_HTTP::timeouter){
|
||||||
Connector_HTTP::timeouter->detach();
|
Connector_HTTP::timeouter->detach();
|
||||||
delete Connector_HTTP::timeouter;
|
delete Connector_HTTP::timeouter;
|
||||||
|
|
|
@ -143,7 +143,7 @@ namespace Connector_HTTP {
|
||||||
///\brief Main function for the HTTP Dynamic Connector
|
///\brief Main function for the HTTP Dynamic Connector
|
||||||
///\param conn A socket describing the connection the client.
|
///\param conn A socket describing the connection the client.
|
||||||
///\return The exit code of the connector.
|
///\return The exit code of the connector.
|
||||||
int dynamicConnector(Socket::Connection conn){
|
int dynamicConnector(Socket::Connection & conn){
|
||||||
FLV::Tag tmp; //temporary tag
|
FLV::Tag tmp; //temporary tag
|
||||||
|
|
||||||
DTSC::Stream Strm; //Incoming stream buffer.
|
DTSC::Stream Strm; //Incoming stream buffer.
|
||||||
|
@ -330,26 +330,5 @@ int main(int argc, char ** argv){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket::Server server_socket = Socket::Server(Util::getTmpFolder() + capa["socket"].asStringRef());
|
return conf.serveForkedSocket(Connector_HTTP::dynamicConnector);
|
||||||
if ( !server_socket.connected()){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
conf.activate();
|
|
||||||
|
|
||||||
while (server_socket.connected() && conf.is_active){
|
|
||||||
Socket::Connection S = server_socket.accept();
|
|
||||||
if (S.connected()){ //check if the new connection is valid
|
|
||||||
pid_t myid = fork();
|
|
||||||
if (myid == 0){ //if new child, start MAINHANDLER
|
|
||||||
return Connector_HTTP::dynamicConnector(S);
|
|
||||||
}else{ //otherwise, do nothing or output debugging text
|
|
||||||
#if DEBUG >= 3
|
|
||||||
fprintf(stderr, "Spawned new process %i for socket %i\n", (int)myid, S.getSocket());
|
|
||||||
#endif
|
|
||||||
S.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} //while connected
|
|
||||||
server_socket.close();
|
|
||||||
return 0;
|
|
||||||
} //main
|
} //main
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace Connector_HTTP {
|
||||||
///\brief Main function for the HTTP Progressive Connector
|
///\brief Main function for the HTTP Progressive Connector
|
||||||
///\param conn A socket describing the connection the client.
|
///\param conn A socket describing the connection the client.
|
||||||
///\return The exit code of the connector.
|
///\return The exit code of the connector.
|
||||||
int JSONConnector(Socket::Connection conn){
|
int JSONConnector(Socket::Connection & conn){
|
||||||
DTSC::Stream Strm; //Incoming stream buffer.
|
DTSC::Stream Strm; //Incoming stream buffer.
|
||||||
HTTP::Parser HTTP_R, HTTP_S;//HTTP Receiver en HTTP Sender.
|
HTTP::Parser HTTP_R, HTTP_S;//HTTP Receiver en HTTP Sender.
|
||||||
bool inited = false;//Whether the stream is initialized
|
bool inited = false;//Whether the stream is initialized
|
||||||
|
@ -208,26 +208,5 @@ int main(int argc, char ** argv){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket::Server server_socket = Socket::Server(Util::getTmpFolder() + capa["socket"].asStringRef());
|
return conf.serveForkedSocket(Connector_HTTP::JSONConnector);
|
||||||
if ( !server_socket.connected()){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
conf.activate();
|
|
||||||
|
|
||||||
while (server_socket.connected() && conf.is_active){
|
|
||||||
Socket::Connection S = server_socket.accept();
|
|
||||||
if (S.connected()){ //check if the new connection is valid
|
|
||||||
pid_t myid = fork();
|
|
||||||
if (myid == 0){ //if new child, start MAINHANDLER
|
|
||||||
return Connector_HTTP::JSONConnector(S);
|
|
||||||
}else{ //otherwise, do nothing or output debugging text
|
|
||||||
#if DEBUG >= 5
|
|
||||||
fprintf(stderr, "Spawned new process %i for socket %i\n", (int)myid, S.getSocket());
|
|
||||||
#endif
|
|
||||||
S.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} //while connected
|
|
||||||
server_socket.close();
|
|
||||||
return 0;
|
|
||||||
} //main
|
} //main
|
||||||
|
|
|
@ -92,7 +92,7 @@ namespace Connector_HTTP {
|
||||||
///\brief Main function for the HTTP Live Connector
|
///\brief Main function for the HTTP Live Connector
|
||||||
///\param conn A socket describing the connection the client.
|
///\param conn A socket describing the connection the client.
|
||||||
///\return The exit code of the connector.
|
///\return The exit code of the connector.
|
||||||
int liveConnector(Socket::Connection conn){
|
int liveConnector(Socket::Connection & conn){
|
||||||
DTSC::Stream Strm; //Incoming stream buffer.
|
DTSC::Stream Strm; //Incoming stream buffer.
|
||||||
HTTP::Parser HTTP_R, HTTP_S; //HTTP Receiver en HTTP Sender.
|
HTTP::Parser HTTP_R, HTTP_S; //HTTP Receiver en HTTP Sender.
|
||||||
|
|
||||||
|
@ -351,26 +351,5 @@ int main(int argc, char ** argv){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket::Server server_socket = Socket::Server(Util::getTmpFolder() + capa["socket"].asStringRef());
|
return conf.serveForkedSocket(Connector_HTTP::liveConnector);
|
||||||
if ( !server_socket.connected()){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
conf.activate();
|
|
||||||
|
|
||||||
while (server_socket.connected() && conf.is_active){
|
|
||||||
Socket::Connection S = server_socket.accept();
|
|
||||||
if (S.connected()){ //check if the new connection is valid
|
|
||||||
pid_t myid = fork();
|
|
||||||
if (myid == 0){ //if new child, start MAINHANDLER
|
|
||||||
return Connector_HTTP::liveConnector(S);
|
|
||||||
}else{ //otherwise, do nothing or output debugging text
|
|
||||||
#if DEBUG >= 5
|
|
||||||
fprintf(stderr, "Spawned new process %i for socket %i\n", (int)myid, S.getSocket());
|
|
||||||
#endif
|
|
||||||
S.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} //while connected
|
|
||||||
server_socket.close();
|
|
||||||
return 0;
|
|
||||||
} //main
|
} //main
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace Connector_HTTP {
|
||||||
///\brief Main function for the HTTP Progressive Connector
|
///\brief Main function for the HTTP Progressive Connector
|
||||||
///\param conn A socket describing the connection the client.
|
///\param conn A socket describing the connection the client.
|
||||||
///\return The exit code of the connector.
|
///\return The exit code of the connector.
|
||||||
int progressiveConnector(Socket::Connection conn){
|
int progressiveConnector(Socket::Connection & conn){
|
||||||
bool progressive_has_sent_header = false;//Indicates whether we have sent a header.
|
bool progressive_has_sent_header = false;//Indicates whether we have sent a header.
|
||||||
bool ready4data = false; //Set to true when streaming is to begin.
|
bool ready4data = false; //Set to true when streaming is to begin.
|
||||||
DTSC::Stream Strm; //Incoming stream buffer.
|
DTSC::Stream Strm; //Incoming stream buffer.
|
||||||
|
@ -215,27 +215,5 @@ int main(int argc, char ** argv){
|
||||||
std::cout << capa.toString() << std::endl;
|
std::cout << capa.toString() << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
return conf.serveForkedSocket(Connector_HTTP::progressiveConnector);
|
||||||
Socket::Server server_socket = Socket::Server(Util::getTmpFolder() + capa["socket"].asStringRef());
|
|
||||||
if ( !server_socket.connected()){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
conf.activate();
|
|
||||||
|
|
||||||
while (server_socket.connected() && conf.is_active){
|
|
||||||
Socket::Connection S = server_socket.accept();
|
|
||||||
if (S.connected()){ //check if the new connection is valid
|
|
||||||
pid_t myid = fork();
|
|
||||||
if (myid == 0){ //if new child, start MAINHANDLER
|
|
||||||
return Connector_HTTP::progressiveConnector(S);
|
|
||||||
}else{ //otherwise, do nothing or output debugging text
|
|
||||||
#if DEBUG >= 5
|
|
||||||
fprintf(stderr, "Spawned new process %i for socket %i\n", (int)myid, S.getSocket());
|
|
||||||
#endif
|
|
||||||
S.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} //while connected
|
|
||||||
server_socket.close();
|
|
||||||
return 0;
|
|
||||||
} //main
|
} //main
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace Connector_HTTP {
|
||||||
///\brief Main function for the HTTP Progressive Connector
|
///\brief Main function for the HTTP Progressive Connector
|
||||||
///\param conn A socket describing the connection the client.
|
///\param conn A socket describing the connection the client.
|
||||||
///\return The exit code of the connector.
|
///\return The exit code of the connector.
|
||||||
int progressiveConnector(Socket::Connection conn){
|
int progressiveConnector(Socket::Connection & conn){
|
||||||
bool progressive_has_sent_header = false;//Indicates whether we have sent a header.
|
bool progressive_has_sent_header = false;//Indicates whether we have sent a header.
|
||||||
bool ready4data = false; //Set to true when streaming is to begin.
|
bool ready4data = false; //Set to true when streaming is to begin.
|
||||||
DTSC::Stream Strm; //Incoming stream buffer.
|
DTSC::Stream Strm; //Incoming stream buffer.
|
||||||
|
@ -182,26 +182,5 @@ int main(int argc, char ** argv){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket::Server server_socket = Socket::Server(Util::getTmpFolder() + capa["socket"].asStringRef());
|
return conf.serveForkedSocket(Connector_HTTP::progressiveConnector);
|
||||||
if ( !server_socket.connected()){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
conf.activate();
|
|
||||||
|
|
||||||
while (server_socket.connected() && conf.is_active){
|
|
||||||
Socket::Connection S = server_socket.accept();
|
|
||||||
if (S.connected()){ //check if the new connection is valid
|
|
||||||
pid_t myid = fork();
|
|
||||||
if (myid == 0){ //if new child, start MAINHANDLER
|
|
||||||
return Connector_HTTP::progressiveConnector(S);
|
|
||||||
}else{ //otherwise, do nothing or output debugging text
|
|
||||||
#if DEBUG >= 5
|
|
||||||
fprintf(stderr, "Spawned new process %i for socket %i\n", (int)myid, S.getSocket());
|
|
||||||
#endif
|
|
||||||
S.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} //while connected
|
|
||||||
server_socket.close();
|
|
||||||
return 0;
|
|
||||||
} //main
|
} //main
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace Connector_HTTP {
|
||||||
///\brief Main function for the HTTP Progressive Connector
|
///\brief Main function for the HTTP Progressive Connector
|
||||||
///\param conn A socket describing the connection the client.
|
///\param conn A socket describing the connection the client.
|
||||||
///\return The exit code of the connector.
|
///\return The exit code of the connector.
|
||||||
int progressiveConnector(Socket::Connection conn){
|
int progressiveConnector(Socket::Connection & conn){
|
||||||
bool ready4data = false; //Set to true when streaming is to begin.
|
bool ready4data = false; //Set to true when streaming is to begin.
|
||||||
DTSC::Stream Strm; //Incoming stream buffer.
|
DTSC::Stream Strm; //Incoming stream buffer.
|
||||||
HTTP::Parser HTTP_R, HTTP_S;//HTTP Receiver en HTTP Sender.
|
HTTP::Parser HTTP_R, HTTP_S;//HTTP Receiver en HTTP Sender.
|
||||||
|
@ -189,26 +189,5 @@ int main(int argc, char ** argv){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket::Server server_socket = Socket::Server(Util::getTmpFolder() + capa["socket"].asStringRef());
|
return conf.serveForkedSocket(Connector_HTTP::progressiveConnector);
|
||||||
if ( !server_socket.connected()){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
conf.activate();
|
|
||||||
|
|
||||||
while (server_socket.connected() && conf.is_active){
|
|
||||||
Socket::Connection S = server_socket.accept();
|
|
||||||
if (S.connected()){ //check if the new connection is valid
|
|
||||||
pid_t myid = fork();
|
|
||||||
if (myid == 0){ //if new child, start MAINHANDLER
|
|
||||||
return Connector_HTTP::progressiveConnector(S);
|
|
||||||
}else{ //otherwise, do nothing or output debugging text
|
|
||||||
#if DEBUG >= 5
|
|
||||||
fprintf(stderr, "Spawned new process %i for socket %i\n", (int)myid, S.getSocket());
|
|
||||||
#endif
|
|
||||||
S.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} //while connected
|
|
||||||
server_socket.close();
|
|
||||||
return 0;
|
|
||||||
} //main
|
} //main
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace Connector_HTTP {
|
||||||
///\brief Main function for the HTTP Progressive Connector
|
///\brief Main function for the HTTP Progressive Connector
|
||||||
///\param conn A socket describing the connection the client.
|
///\param conn A socket describing the connection the client.
|
||||||
///\return The exit code of the connector.
|
///\return The exit code of the connector.
|
||||||
int progressiveConnector(Socket::Connection conn){
|
int progressiveConnector(Socket::Connection & conn){
|
||||||
bool progressive_has_sent_header = false;//Indicates whether we have sent a header.
|
bool progressive_has_sent_header = false;//Indicates whether we have sent a header.
|
||||||
bool ready4data = false; //Set to true when streaming is to begin.
|
bool ready4data = false; //Set to true when streaming is to begin.
|
||||||
DTSC::Stream Strm; //Incoming stream buffer.
|
DTSC::Stream Strm; //Incoming stream buffer.
|
||||||
|
@ -185,26 +185,5 @@ int main(int argc, char ** argv){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket::Server server_socket = Socket::Server(Util::getTmpFolder() + capa["socket"].asStringRef());
|
return conf.serveForkedSocket(Connector_HTTP::progressiveConnector);
|
||||||
if ( !server_socket.connected()){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
conf.activate();
|
|
||||||
|
|
||||||
while (server_socket.connected() && conf.is_active){
|
|
||||||
Socket::Connection S = server_socket.accept();
|
|
||||||
if (S.connected()){ //check if the new connection is valid
|
|
||||||
pid_t myid = fork();
|
|
||||||
if (myid == 0){ //if new child, start MAINHANDLER
|
|
||||||
return Connector_HTTP::progressiveConnector(S);
|
|
||||||
}else{ //otherwise, do nothing or output debugging text
|
|
||||||
#if DEBUG >= 5
|
|
||||||
fprintf(stderr, "Spawned new process %i for socket %i\n", (int)myid, S.getSocket());
|
|
||||||
#endif
|
|
||||||
S.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} //while connected
|
|
||||||
server_socket.close();
|
|
||||||
return 0;
|
|
||||||
} //main
|
} //main
|
||||||
|
|
|
@ -195,7 +195,7 @@ namespace Connector_HTTP {
|
||||||
///\brief Main function for the HTTP Smooth Connector
|
///\brief Main function for the HTTP Smooth Connector
|
||||||
///\param conn A socket describing the connection the client.
|
///\param conn A socket describing the connection the client.
|
||||||
///\return The exit code of the connector.
|
///\return The exit code of the connector.
|
||||||
int smoothConnector(Socket::Connection conn){
|
int smoothConnector(Socket::Connection & conn){
|
||||||
std::deque<std::string> dataBuffer;//A buffer for the data that needs to be sent to the client.
|
std::deque<std::string> dataBuffer;//A buffer for the data that needs to be sent to the client.
|
||||||
|
|
||||||
DTSC::Stream Strm;//Incoming stream buffer.
|
DTSC::Stream Strm;//Incoming stream buffer.
|
||||||
|
@ -545,26 +545,5 @@ int main(int argc, char ** argv){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket::Server server_socket = Socket::Server(Util::getTmpFolder() + capa["socket"].asStringRef());
|
return conf.serveForkedSocket(Connector_HTTP::smoothConnector);
|
||||||
if ( !server_socket.connected()){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
conf.activate();
|
|
||||||
|
|
||||||
while (server_socket.connected() && conf.is_active){
|
|
||||||
Socket::Connection S = server_socket.accept();
|
|
||||||
if (S.connected()){ //check if the new connection is valid
|
|
||||||
pid_t myid = fork();
|
|
||||||
if (myid == 0){ //if new child, start MAINHANDLER
|
|
||||||
return Connector_HTTP::smoothConnector(S);
|
|
||||||
}else{ //otherwise, do nothing or output debugging text
|
|
||||||
#if DEBUG >= 5
|
|
||||||
fprintf(stderr, "Spawned new process %i for socket %i\n", (int)myid, S.getSocket());
|
|
||||||
#endif
|
|
||||||
S.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} //while connected
|
|
||||||
server_socket.close();
|
|
||||||
return 0;
|
|
||||||
} //main
|
} //main
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace Connector_HTTP {
|
||||||
///\brief Main function for the HTTP Progressive Connector
|
///\brief Main function for the HTTP Progressive Connector
|
||||||
///\param conn A socket describing the connection the client.
|
///\param conn A socket describing the connection the client.
|
||||||
///\return The exit code of the connector.
|
///\return The exit code of the connector.
|
||||||
int SRTConnector(Socket::Connection conn){
|
int SRTConnector(Socket::Connection & conn){
|
||||||
DTSC::Stream Strm; //Incoming stream buffer.
|
DTSC::Stream Strm; //Incoming stream buffer.
|
||||||
HTTP::Parser HTTP_R, HTTP_S;//HTTP Receiver en HTTP Sender.
|
HTTP::Parser HTTP_R, HTTP_S;//HTTP Receiver en HTTP Sender.
|
||||||
bool inited = false;//Whether the stream is initialized
|
bool inited = false;//Whether the stream is initialized
|
||||||
|
@ -221,26 +221,5 @@ int main(int argc, char ** argv){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket::Server server_socket = Socket::Server(Util::getTmpFolder() + capa["socket"].asStringRef());
|
return conf.serveForkedSocket(Connector_HTTP::SRTConnector);
|
||||||
if ( !server_socket.connected()){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
conf.activate();
|
|
||||||
|
|
||||||
while (server_socket.connected() && conf.is_active){
|
|
||||||
Socket::Connection S = server_socket.accept();
|
|
||||||
if (S.connected()){ //check if the new connection is valid
|
|
||||||
pid_t myid = fork();
|
|
||||||
if (myid == 0){ //if new child, start MAINHANDLER
|
|
||||||
return Connector_HTTP::SRTConnector(S);
|
|
||||||
}else{ //otherwise, do nothing or output debugging text
|
|
||||||
#if DEBUG >= 5
|
|
||||||
fprintf(stderr, "Spawned new process %i for socket %i\n", (int)myid, S.getSocket());
|
|
||||||
#endif
|
|
||||||
S.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} //while connected
|
|
||||||
server_socket.close();
|
|
||||||
return 0;
|
|
||||||
} //main
|
} //main
|
||||||
|
|
|
@ -513,7 +513,7 @@ namespace Connector_RTMP {
|
||||||
///\brief Main function for the RTMP Connector
|
///\brief Main function for the RTMP Connector
|
||||||
///\param conn A socket describing the connection the client.
|
///\param conn A socket describing the connection the client.
|
||||||
///\return The exit code of the connector.
|
///\return The exit code of the connector.
|
||||||
int rtmpConnector(Socket::Connection conn){
|
int rtmpConnector(Socket::Connection & conn){
|
||||||
Socket = conn;
|
Socket = conn;
|
||||||
Socket.setBlocking(false);
|
Socket.setBlocking(false);
|
||||||
FLV::Tag tag, init_tag;
|
FLV::Tag tag, init_tag;
|
||||||
|
@ -696,26 +696,5 @@ int main(int argc, char ** argv){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket::Server server_socket = Socket::Server(conf.getInteger("listen_port"), conf.getString("listen_interface"));
|
return conf.serveForkedSocket(Connector_RTMP::rtmpConnector);
|
||||||
if ( !server_socket.connected()){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
conf.activate();
|
|
||||||
|
|
||||||
while (server_socket.connected() && conf.is_active){
|
|
||||||
Socket::Connection S = server_socket.accept();
|
|
||||||
if (S.connected()){ //check if the new connection is valid
|
|
||||||
pid_t myid = fork();
|
|
||||||
if (myid == 0){ //if new child, start MAINHANDLER
|
|
||||||
return Connector_RTMP::rtmpConnector(S);
|
|
||||||
}else{ //otherwise, do nothing or output debugging text
|
|
||||||
#if DEBUG >= 5
|
|
||||||
fprintf(stderr, "Spawned new process %i for socket %i\n", (int)myid, S.getSocket());
|
|
||||||
#endif
|
|
||||||
S.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} //while connected
|
|
||||||
server_socket.close();
|
|
||||||
return 0;
|
|
||||||
} //main
|
} //main
|
||||||
|
|
|
@ -25,12 +25,13 @@
|
||||||
|
|
||||||
///\brief Holds everything unique to the TS Connector
|
///\brief Holds everything unique to the TS Connector
|
||||||
namespace Connector_TS {
|
namespace Connector_TS {
|
||||||
|
std::string streamName;
|
||||||
|
std::string trackIDs;
|
||||||
|
|
||||||
///\brief Main function for the TS Connector
|
///\brief Main function for the TS Connector
|
||||||
///\param conn A socket describing the connection the client.
|
///\param conn A socket describing the connection the client.
|
||||||
///\param streamName The stream to connect to.
|
|
||||||
///\param trackIDs Space separated list of wanted tracks.
|
|
||||||
///\return The exit code of the connector.
|
///\return The exit code of the connector.
|
||||||
int tsConnector(Socket::Connection conn, std::string streamName, std::string trackIDs){
|
int tsConnector(Socket::Connection & conn){
|
||||||
std::string ToPack;
|
std::string ToPack;
|
||||||
TS::Packet PackData;
|
TS::Packet PackData;
|
||||||
std::string DTMIData;
|
std::string DTMIData;
|
||||||
|
@ -206,27 +207,8 @@ int main(int argc, char ** argv){
|
||||||
conf.printHelp(std::cout);
|
conf.printHelp(std::cout);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket::Server server_socket = Socket::Server(conf.getInteger("listen_port"), conf.getString("listen_interface"));
|
|
||||||
if ( !server_socket.connected()){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
conf.activate();
|
|
||||||
|
|
||||||
while (server_socket.connected() && conf.is_active){
|
Connector_TS::streamName = conf.getString("streamname");
|
||||||
Socket::Connection S = server_socket.accept();
|
Connector_TS::trackIDs = conf.getString("tracks");
|
||||||
if (S.connected()){ //check if the new connection is valid
|
return conf.serveForkedSocket(Connector_TS::tsConnector);
|
||||||
pid_t myid = fork();
|
|
||||||
if (myid == 0){ //if new child, start MAINHANDLER
|
|
||||||
return Connector_TS::tsConnector(S, conf.getString("streamname"), conf.getString("tracks"));
|
|
||||||
}else{ //otherwise, do nothing or output debugging text
|
|
||||||
#if DEBUG >= 5
|
|
||||||
fprintf(stderr, "Spawned new process %i for socket %i\n", (int)myid, S.getSocket());
|
|
||||||
#endif
|
|
||||||
S.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} //while connected
|
|
||||||
server_socket.close();
|
|
||||||
return 0;
|
|
||||||
} //main
|
} //main
|
||||||
|
|
Loading…
Add table
Reference in a new issue