From: g0dil Date: Fri, 29 Jun 2007 14:03:06 +0000 (+0000) Subject: MediaServ: Update to new SENF library API X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=5d7ee80d33424ecc0b015cc22ae9ac70c0190719;p=mediaserv.git MediaServ: Update to new SENF library API --- diff --git a/.gitignore b/.gitignore index c4e36bd..fddf079 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ libSocket.a libUtils.a libServer.a SConfig +.sconsign* diff --git a/SConstruct b/SConstruct index 3cf7202..2694141 100644 --- a/SConstruct +++ b/SConstruct @@ -1,13 +1,12 @@ import sys, glob -sys.path.append('satscons') -import SatSCons +sys.path.append('senfscons') +import SENFSCons ########################################################################### -SatSCons.UseBoost(); -SatSCons.UseSTLPort(); -SatSCons.UseDoxygen(); -env = SatSCons.MakeEnvironment(); +SENFSCons.UseBoost(); +SENFSCons.UseSTLPort(); +env = SENFSCons.MakeEnvironment(); env.Append( CPPPATH = [ '#' ], @@ -18,11 +17,11 @@ Export('env') SConscript(glob.glob("*/SConscript")) -SatSCons.StandardTargets(env) -SatSCons.GlobalTargets(env) +SENFSCons.StandardTargets(env) +SENFSCons.GlobalTargets(env) -SatSCons.Binary(env, binary='mediaserv', sources=SatSCons.GlobSources(exclude='testclient.cc'), +SENFSCons.Binary(env, binary='mediaserv', sources=SENFSCons.GlobSources(exclude='testclient.cc'), LIBS = [ 'Server', 'Scheduler', 'Socket', 'Utils' ]) -SatSCons.Binary(env, binary='testclient', sources=['testclient.cc'], +SENFSCons.Binary(env, binary='testclient', sources=['testclient.cc'], LIBS = [ 'Socket', 'Utils' ]) diff --git a/Server/.gitignore b/Server/.gitignore new file mode 100644 index 0000000..722bbfd --- /dev/null +++ b/Server/.gitignore @@ -0,0 +1,2 @@ +.test.bin +.test.stamp diff --git a/Server/HTTPConnection.cc b/Server/HTTPConnection.cc index 33a4e1c..1c1f8e7 100644 --- a/Server/HTTPConnection.cc +++ b/Server/HTTPConnection.cc @@ -31,9 +31,9 @@ prefix_ g0dil::mediaserv::HTTPConnection::HTTPConnection(ClientHandle client, HTTPLogger & logger) : client_(client), server_(server), logger_(logger), fileFd_(-1), bandwidth_(0) { - satcom::lib::ReadHelper - ::dispatch(client_, MaxRequestSize, satcom::lib::ReadUntil("\r\n\r\n"), - satcom::lib::membind(&HTTPConnection::handleRequest,this)); + senf::ReadHelper + ::dispatch(client_, MaxRequestSize, senf::ReadUntil("\r\n\r\n"), + senf::membind(&HTTPConnection::handleRequest,this)); } prefix_ g0dil::mediaserv::HTTPConnection::~HTTPConnection() @@ -45,7 +45,7 @@ prefix_ g0dil::mediaserv::HTTPConnection::~HTTPConnection() } prefix_ void -g0dil::mediaserv::HTTPConnection::handleRequest(satcom::lib::ReadHelper::ptr helper) +g0dil::mediaserv::HTTPConnection::handleRequest(senf::ReadHelper::ptr helper) { try { @@ -63,18 +63,18 @@ g0dil::mediaserv::HTTPConnection::handleRequest(satcom::lib::ReadHelper + senf::WriteHelper ::dispatch(client_, response.str(), - satcom::lib::membind(&HTTPConnection::startStream,this)); + senf::membind(&HTTPConnection::startStream,this)); } catch (std::exception const & ex) { @@ -84,7 +84,7 @@ g0dil::mediaserv::HTTPConnection::handleRequest(satcom::lib::ReadHelper::ptr helper) +g0dil::mediaserv::HTTPConnection::startStream(senf::WriteHelper::ptr helper) { try { helper->throw_error(); diff --git a/Server/HTTPConnection.hh b/Server/HTTPConnection.hh index e8b097e..178cec2 100644 --- a/Server/HTTPConnection.hh +++ b/Server/HTTPConnection.hh @@ -26,18 +26,18 @@ namespace mediaserv { class StreamConnection; class HTTPConnection - : public satcom::lib::intrusive_refcount + : public senf::intrusive_refcount { public: /////////////////////////////////////////////////////////////////////////// // Types typedef boost::intrusive_ptr ptr; - typedef satcom::lib::ClientSocketHandle< - satcom::lib::MakeSocketPolicy::policy> ClientHandle; + typedef senf::ClientSocketHandle< + senf::MakeSocketPolicy::policy> ClientHandle; static const unsigned MaxRequestSize = 16384; static const unsigned StreamBufferMSecs = 4000; @@ -57,8 +57,8 @@ namespace mediaserv { protected: private: - void handleRequest(satcom::lib::ReadHelper::ptr); - void startStream(satcom::lib::WriteHelper::ptr); + void handleRequest(senf::ReadHelper::ptr); + void startStream(senf::WriteHelper::ptr); ClientHandle client_; SimpleHTTPServer & server_; diff --git a/Server/HTTPRequest.cc b/Server/HTTPRequest.cc index 4fb444e..31b546c 100644 --- a/Server/HTTPRequest.cc +++ b/Server/HTTPRequest.cc @@ -21,20 +21,20 @@ prefix_ g0dil::mediaserv::HTTPRequest::HTTPRequest() {} -prefix_ g0dil::mediaserv::HTTPRequest::HTTPRequest(satcom::lib::FileHandle handle, +prefix_ g0dil::mediaserv::HTTPRequest::HTTPRequest(senf::FileHandle handle, std::string const & request) { parseRequest(handle,request); } -prefix_ void g0dil::mediaserv::HTTPRequest::parseRequest(satcom::lib::FileHandle handle, +prefix_ void g0dil::mediaserv::HTTPRequest::parseRequest(senf::FileHandle handle, std::string const & request) { - typedef satcom::lib::ClientSocketHandle< satcom::lib::MakeSocketPolicy< - satcom::lib::INet4AddressingPolicy, - satcom::lib::ConnectedCommunicationPolicy >::policy> IPHandle; + typedef senf::ClientSocketHandle< senf::MakeSocketPolicy< + senf::INet4AddressingPolicy, + senf::ConnectedCommunicationPolicy >::policy> IPHandle; try { - host_ = satcom::lib::dynamic_socket_cast(handle).peer().host(); + host_ = senf::dynamic_socket_cast(handle).peer().host(); } catch (std::bad_cast const *) { host_ = "(unidentified address)"; diff --git a/Server/HTTPRequest.hh b/Server/HTTPRequest.hh index 2a4e367..5217249 100644 --- a/Server/HTTPRequest.hh +++ b/Server/HTTPRequest.hh @@ -29,7 +29,7 @@ namespace mediaserv { ///@{ HTTPRequest(); - HTTPRequest(satcom::lib::FileHandle handle, std::string const & request); + HTTPRequest(senf::FileHandle handle, std::string const & request); ///@} /////////////////////////////////////////////////////////////////////////// @@ -47,7 +47,7 @@ namespace mediaserv { ///\name Mutators ///@{ - void parseRequest(satcom::lib::FileHandle handle, std::string const & request); + void parseRequest(senf::FileHandle handle, std::string const & request); ///@} diff --git a/Server/SConscript b/Server/SConscript index 88ce6da..dc49b2f 100644 --- a/Server/SConscript +++ b/Server/SConscript @@ -1,9 +1,9 @@ Import('env') -import SatSCons +import SENFSCons ########################################################################### -SatSCons.StandardTargets(env) +SENFSCons.StandardTargets(env) -SatSCons.Lib(env, library = 'Server', sources = SatSCons.GlobSources(), +SENFSCons.Lib(env, library = 'Server', sources = SENFSCons.GlobSources(), LIBS = [ 'Socket', 'Scheduler', 'Utils' ]) diff --git a/Server/SimpleHTTPServer.cc b/Server/SimpleHTTPServer.cc index c749c59..178fb3b 100644 --- a/Server/SimpleHTTPServer.cc +++ b/Server/SimpleHTTPServer.cc @@ -24,10 +24,10 @@ prefix_ g0dil::mediaserv::SimpleHTTPServer::SimpleHTTPServer(ServerHandle socket : socket_(socket), logger_(logger) { instance_ = this; - satcom::lib::Scheduler::instance() + senf::Scheduler::instance() .add(socket_, - satcom::lib::membind(&SimpleHTTPServer::newConnection,this), - satcom::lib::Scheduler::EV_READ); + senf::membind(&SimpleHTTPServer::newConnection,this), + senf::Scheduler::EV_READ); } prefix_ g0dil::mediaserv::SimpleHTTPServer::~SimpleHTTPServer() @@ -37,11 +37,11 @@ prefix_ g0dil::mediaserv::SimpleHTTPServer::~SimpleHTTPServer() prefix_ void g0dil::mediaserv::SimpleHTTPServer::newConnection(ServerHandle handle, - satcom::lib::Scheduler::EventId event) + senf::Scheduler::EventId event) { - if (event != satcom::lib::Scheduler::EV_READ) { + if (event != senf::Scheduler::EV_READ) { logger_.failedRequest("unexpected event on server socket .. shuting down .."); - satcom::lib::Scheduler::instance().terminate(); + senf::Scheduler::instance().terminate(); return; } try { diff --git a/Server/SimpleHTTPServer.hh b/Server/SimpleHTTPServer.hh index 56c79c2..da4db78 100644 --- a/Server/SimpleHTTPServer.hh +++ b/Server/SimpleHTTPServer.hh @@ -49,7 +49,7 @@ namespace mediaserv { protected: private: - void newConnection(ServerHandle handle, satcom::lib::Scheduler::EventId event); + void newConnection(ServerHandle handle, senf::Scheduler::EventId event); typedef std::set Connections; diff --git a/Server/StreamConnection.cc b/Server/StreamConnection.cc index 130abf8..01b48eb 100644 --- a/Server/StreamConnection.cc +++ b/Server/StreamConnection.cc @@ -22,7 +22,7 @@ prefix_ g0dil::mediaserv::StreamConnection::StreamConnection(int fileFd, Callback callback) : fileFd_(fileFd), bytesPerSecond_(bytesPerSecond), client_(client), bufferMSecs_(bufferMSecs), callback_(callback), bytesWritten_(0), - start_(satcom::lib::now()), bufferSize_(0), terminate_(false) + start_(senf::now()), bufferSize_(0), terminate_(false) { fillBuffer(); } @@ -49,15 +49,15 @@ prefix_ void g0dil::mediaserv::StreamConnection::fillBuffer() } prefix_ void g0dil::mediaserv::StreamConnection::callback(ClientHandle client, - satcom::lib::Scheduler::EventId event) + senf::Scheduler::EventId event) { - if (event != satcom::lib::Scheduler::EV_WRITE) { + if (event != senf::Scheduler::EV_WRITE) { callback_(); return; } unsigned target (targetBytes()); if (target - bytesWritten_ >= bufferSize_) { - if (client_.write(buffer_,bufferSize_) < bufferSize_) { + if (client_.write(buffer_,buffer_+bufferSize_) < buffer_+bufferSize_) { callback_(); return; } diff --git a/Server/StreamConnection.cci b/Server/StreamConnection.cci index 8035dd4..d19a91b 100644 --- a/Server/StreamConnection.cci +++ b/Server/StreamConnection.cci @@ -17,25 +17,25 @@ prefix_ unsigned g0dil::mediaserv::StreamConnection::bytesSent() prefix_ void g0dil::mediaserv::StreamConnection::registerCallback() { - satcom::lib::Scheduler::instance() - .add(client_,satcom::lib::membind(&StreamConnection::callback,this), - satcom::lib::Scheduler::EV_WRITE); + senf::Scheduler::instance() + .add(client_,senf::membind(&StreamConnection::callback,this), + senf::Scheduler::EV_WRITE); } prefix_ void g0dil::mediaserv::StreamConnection::unregisterCallback() { - satcom::lib::Scheduler::instance().remove(client_,satcom::lib::Scheduler::EV_WRITE); + senf::Scheduler::instance().remove(client_,senf::Scheduler::EV_WRITE); } prefix_ void g0dil::mediaserv::StreamConnection::registerTimeout(unsigned timeout) { - satcom::lib::Scheduler::instance() - .timeout(timeout,satcom::lib::membind(&StreamConnection::timeout,this)); + senf::Scheduler::instance() + .timeout(timeout,senf::membind(&StreamConnection::timeout,this)); } prefix_ unsigned g0dil::mediaserv::StreamConnection::targetBytes() { - return ((bufferMSecs_ + ((satcom::lib::now()-start_)/1000u))*bytesPerSecond_)/1000u; + return ((bufferMSecs_ + ((senf::now()-start_)/1000u))*bytesPerSecond_)/1000u; } ///////////////////////////////cci.e/////////////////////////////////////// diff --git a/Server/StreamConnection.hh b/Server/StreamConnection.hh index ba71fe6..9bd4755 100644 --- a/Server/StreamConnection.hh +++ b/Server/StreamConnection.hh @@ -23,16 +23,16 @@ namespace g0dil { namespace mediaserv { - class StreamConnection : public satcom::lib::intrusive_refcount + class StreamConnection : public senf::intrusive_refcount { public: /////////////////////////////////////////////////////////////////////////// // Types - typedef satcom::lib::ClientSocketHandle< - satcom::lib::MakeSocketPolicy::policy> ClientHandle; + typedef senf::ClientSocketHandle< + senf::MakeSocketPolicy::policy> ClientHandle; typedef boost::intrusive_ptr ptr; typedef boost::function Callback; @@ -62,7 +62,7 @@ namespace mediaserv { unsigned targetBytes(); void fillBuffer(); - void callback(ClientHandle client, satcom::lib::Scheduler::EventId); + void callback(ClientHandle client, senf::Scheduler::EventId); void timeout(); @@ -73,7 +73,7 @@ namespace mediaserv { Callback callback_; unsigned bytesWritten_; - satcom::lib::MicroTime start_; + senf::MicroTime start_; unsigned bufferSize_; char buffer_[packetSize]; bool terminate_; diff --git a/main.cc b/main.cc index 36b0946..c1b4193 100644 --- a/main.cc +++ b/main.cc @@ -30,7 +30,7 @@ #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -#define THROW_SYSERR(cmd,e) if (e) throw satcom::lib::SystemException(#cmd,errno) +#define THROW_SYSERR(cmd,e) if (e) throw senf::SystemException(#cmd,errno) int main(int argc, char** argv) { @@ -45,19 +45,19 @@ int main(int argc, char** argv) try { // We have to make sure not to access any sytem files after the chroot // (initgroups accesses /etc/group, redirect_stdio accesses /dev/null) - satcom::lib::redirect_stdio(); + senf::redirect_stdio(); THROW_SYSERR( initgroups, ::initgroups("media",gr->gr_gid) < 0 ); THROW_SYSERR( chdir, chdir("wwwroot") < 0 ); THROW_SYSERR( chroot, chroot(".") < 0 ); - satcom::lib::TCPv4ServerSocketHandle socket (argv[1]); + senf::TCPv4ServerSocketHandle socket (argv[1]); THROW_SYSERR( setregid, ::setregid(gr->gr_gid,gr->gr_gid) < 0 ); THROW_SYSERR( setreuid, ::setreuid(pw->pw_uid,pw->pw_uid) < 0 ); - satcom::lib::daemonize(); + senf::daemonize(); socket.blocking(false); socket.protocol().reuseaddr(true); g0dil::mediaserv::SimpleHTTPServer server (socket,logger); - satcom::lib::Scheduler::instance().process(); + senf::Scheduler::instance().process(); } catch (std::exception const & ex) { logger.failedRequest(ex.what()); diff --git a/testclient.cc b/testclient.cc index 1365600..f74f517 100644 --- a/testclient.cc +++ b/testclient.cc @@ -18,7 +18,7 @@ int main(int argc, char** argv) { - satcom::lib::TCPv4ClientSocketHandle handle (argv[1]); + senf::TCPv4ClientSocketHandle handle (argv[1]); handle.write(argv[2]); handle.write(" HTTP/1.1\r\n"); if (argc>3) { @@ -28,10 +28,10 @@ int main(int argc, char** argv) } handle.write("\r\n"); unsigned size = 0; - satcom::lib::MicroTime offset = satcom::lib::now(); + senf::MicroTime offset = senf::now(); while (handle) { size += handle.read().size(); - std::cout << satcom::lib::now()-offset << " " << size << "\n"; + std::cout << senf::now()-offset << " " << size << "\n"; } }