libUtils.a
libServer.a
SConfig
+.sconsign*
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 = [ '#' ],
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' ])
--- /dev/null
+.test.bin
+.test.stamp
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()
}
prefix_ void
-g0dil::mediaserv::HTTPConnection::handleRequest(satcom::lib::ReadHelper<ClientHandle>::ptr helper)
+g0dil::mediaserv::HTTPConnection::handleRequest(senf::ReadHelper<ClientHandle>::ptr helper)
{
try {
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) {
}
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();
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;
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_;
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)";
///@{
HTTPRequest();
- HTTPRequest(satcom::lib::FileHandle handle, std::string const & request);
+ HTTPRequest(senf::FileHandle handle, std::string const & request);
///@}
///////////////////////////////////////////////////////////////////////////
///\name Mutators
///@{
- void parseRequest(satcom::lib::FileHandle handle, std::string const & request);
+ void parseRequest(senf::FileHandle handle, std::string const & request);
///@}
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' ])
: 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()
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 {
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;
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();
}
}
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;
}
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///////////////////////////////////////
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;
unsigned targetBytes();
void fillBuffer();
- void callback(ClientHandle client, satcom::lib::Scheduler::EventId);
+ void callback(ClientHandle client, senf::Scheduler::EventId);
void timeout();
Callback callback_;
unsigned bytesWritten_;
- satcom::lib::MicroTime start_;
+ senf::MicroTime start_;
unsigned bufferSize_;
char buffer_[packetSize];
bool terminate_;
#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)
{
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());
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) {
}
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";
}
}