MediaServ: Update to new SENF library API
g0dil [Fri, 29 Jun 2007 14:03:06 +0000 (14:03 +0000)]
15 files changed:
.gitignore
SConstruct
Server/.gitignore [new file with mode: 0644]
Server/HTTPConnection.cc
Server/HTTPConnection.hh
Server/HTTPRequest.cc
Server/HTTPRequest.hh
Server/SConscript
Server/SimpleHTTPServer.cc
Server/SimpleHTTPServer.hh
Server/StreamConnection.cc
Server/StreamConnection.cci
Server/StreamConnection.hh
main.cc
testclient.cc

index c4e36bd..fddf079 100644 (file)
@@ -5,3 +5,4 @@ libSocket.a
 libUtils.a
 libServer.a
 SConfig
+.sconsign*
index 3cf7202..2694141 100644 (file)
@@ -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 (file)
index 0000000..722bbfd
--- /dev/null
@@ -0,0 +1,2 @@
+.test.bin
+.test.stamp
index 33a4e1c..1c1f8e7 100644 (file)
@@ -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<ClientHandle>
-       ::dispatch(client_, MaxRequestSize, satcom::lib::ReadUntil("\r\n\r\n"),
-                  satcom::lib::membind(&HTTPConnection::handleRequest,this));
+    senf::ReadHelper<ClientHandle>
+       ::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<ClientHandle>::ptr helper)
+g0dil::mediaserv::HTTPConnection::handleRequest(senf::ReadHelper<ClientHandle>::ptr helper)
 {
 
     try {
@@ -63,18 +63,18 @@ g0dil::mediaserv::HTTPConnection::handleRequest(satcom::lib::ReadHelper<ClientHa
        if (++i != i_end) throw InvalidHTTPRequestException();
 
        fileFd_ = ::open(request_.url().c_str(),O_RDONLY);
-       if (fileFd_ < 0) throw satcom::lib::SystemException(errno);
+       if (fileFd_ < 0) throw senf::SystemException(errno);
        struct ::stat s;
-       if (::fstat(fileFd_,&s) < 0) throw satcom::lib::SystemException(errno);
+       if (::fstat(fileFd_,&s) < 0) throw senf::SystemException(errno);
        
        std::ostringstream response;
        response << request_.version() << (request_.version().empty() ? "" : " ") << "200 OK\r\n";
        response << "Content-Type: " << mimeType << "\r\n";
        response << "Content-Length: " << s.st_size << "\r\n\r\n";
        
-       satcom::lib::WriteHelper<ClientHandle>
+       senf::WriteHelper<ClientHandle>
            ::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<ClientHa
 }
 
 prefix_ void
-g0dil::mediaserv::HTTPConnection::startStream(satcom::lib::WriteHelper<ClientHandle>::ptr helper)
+g0dil::mediaserv::HTTPConnection::startStream(senf::WriteHelper<ClientHandle>::ptr helper)
 {
     try {
        helper->throw_error();
index e8b097e..178cec2 100644 (file)
@@ -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<HTTPConnection> ptr;
-       typedef satcom::lib::ClientSocketHandle<
-           satcom::lib::MakeSocketPolicy<satcom::lib::ConnectedCommunicationPolicy,
-                                         satcom::lib::StreamFramingPolicy,
-                                         satcom::lib::ReadablePolicy,
-                                         satcom::lib::WriteablePolicy>::policy> ClientHandle;
+       typedef senf::ClientSocketHandle<
+           senf::MakeSocketPolicy<senf::ConnectedCommunicationPolicy,
+                                         senf::StreamFramingPolicy,
+                                         senf::ReadablePolicy,
+                                         senf::WriteablePolicy>::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<ClientHandle>::ptr);
-       void startStream(satcom::lib::WriteHelper<ClientHandle>::ptr);
+       void handleRequest(senf::ReadHelper<ClientHandle>::ptr);
+       void startStream(senf::WriteHelper<ClientHandle>::ptr);
        
        ClientHandle client_;
        SimpleHTTPServer & server_;
index 4fb444e..31b546c 100644 (file)
 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<IPHandle>(handle).peer().host();
+       host_ = senf::dynamic_socket_cast<IPHandle>(handle).peer().host();
     }
     catch (std::bad_cast const *) {
        host_ = "(unidentified address)";
index 2a4e367..5217249 100644 (file)
@@ -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);
 
         ///@}
 
index 88ce6da..dc49b2f 100644 (file)
@@ -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' ])
index c749c59..178fb3b 100644 (file)
@@ -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 {
index 56c79c2..da4db78 100644 (file)
@@ -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<HTTPConnection::ptr> Connections;
 
index 130abf8..01b48eb 100644 (file)
@@ -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;
        }
index 8035dd4..d19a91b 100644 (file)
@@ -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///////////////////////////////////////
index ba71fe6..9bd4755 100644 (file)
 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<satcom::lib::ConnectedCommunicationPolicy,
-                                         satcom::lib::StreamFramingPolicy,
-                                         satcom::lib::WriteablePolicy>::policy> ClientHandle;
+       typedef senf::ClientSocketHandle<
+           senf::MakeSocketPolicy<senf::ConnectedCommunicationPolicy,
+                                         senf::StreamFramingPolicy,
+                                         senf::WriteablePolicy>::policy> ClientHandle;
 
        typedef boost::intrusive_ptr<StreamConnection> ptr;
        typedef boost::function<void ()> 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 (file)
--- 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());
index 1365600..f74f517 100644 (file)
@@ -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";
     }
 }