// $Id$
//
// Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-// Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Stefan Bund <g0dil@berlios.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
//#include "FileHandle.ih"
// Custom includes
+#include "../Utils/senfassert.hh"
#include <errno.h>
#include "../Utils/Exception.hh"
: fd_(fd)
{}
-prefix_ senf::FileBody::~FileBody()
-{
- if (valid())
- try {
- close();
- }
- catch (...) {
- terminate();
- }
-}
-
-prefix_ void senf::FileBody::close()
-{
- if (!valid())
- throwErrno(EBADF);
- v_close();
- fd_ = -1;
-}
-
-prefix_ void senf::FileBody::terminate()
-{
- if (valid()) {
- v_terminate();
- fd_ = -1;
- }
-}
-
prefix_ senf::FileHandle senf::FileBody::handle()
{
return FileHandle(ptr(this));
prefix_ bool senf::FileBody::readable()
const
{
- return pollCheck(fd(),true);
+ return pollCheck(fd(),true,0);
}
-prefix_ void senf::FileBody::waitReadable()
+prefix_ bool senf::FileBody::waitReadable(senf::ClockService::clock_type timeout)
const
{
- pollCheck(fd(),true,true);
+ return pollCheck(fd(), true,
+ (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)) );
}
prefix_ bool senf::FileBody::writeable()
const
{
- return pollCheck(fd(),false);
+ return pollCheck(fd(),false,0);
+}
+
+prefix_ bool senf::FileBody::waitWriteable(senf::ClockService::clock_type timeout)
+ const
+{
+ return pollCheck(fd(), false,
+ (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)) );
}
-prefix_ void senf::FileBody::waitWriteable()
+prefix_ bool senf::FileBody::oobReadable()
const
{
- pollCheck(fd(),false,true);
+ return pollCheck(fd(),true,0,true);
+}
+
+prefix_ bool senf::FileBody::waitOOBReadable(senf::ClockService::clock_type timeout)
+ const
+{
+ return pollCheck(fd(), true,
+ (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)), true);
}
///////////////////////////////////////////////////////////////////////////
// senf::FileHandle
+prefix_ senf::FileBody & senf::FileHandle::body()
+{
+ SENF_ASSERT(body_);
+ return *body_;
+}
+
+prefix_ senf::FileBody const & senf::FileHandle::body()
+ const
+{
+ SENF_ASSERT(body_);
+ return *body_;
+}
+
prefix_ void senf::FileHandle::close()
{
body().close();
return body().readable();
}
-prefix_ void senf::FileHandle::waitReadable()
+prefix_ bool senf::FileHandle::waitReadable(senf::ClockService::clock_type timeout)
const
{
- body().waitReadable();
+ return body().waitReadable(timeout);
}
prefix_ bool senf::FileHandle::writeable()
return body().writeable();
}
-prefix_ void senf::FileHandle::waitWriteable()
+prefix_ bool senf::FileHandle::waitWriteable(senf::ClockService::clock_type timeout)
+ const
+{
+ return body().waitWriteable(timeout);
+}
+
+prefix_ bool senf::FileHandle::oobReadable()
const
{
- body().waitWriteable();
+ return body().oobReadable();
+}
+
+prefix_ bool senf::FileHandle::waitOOBReadable(senf::ClockService::clock_type timeout)
+ const
+{
+ return body().waitOOBReadable(timeout);
}
prefix_ bool senf::FileHandle::blocking()
: body_(0)
{}
+prefix_ senf::FileHandle::~FileHandle()
+{
+ if (body_ && ! body().is_shared())
+ body().destroyClose();
+}
+
prefix_ senf::FileHandle::FileHandle(std::auto_ptr<FileBody> body)
: body_(body.release())
{}
: body_(body)
{}
-prefix_ senf::FileBody & senf::FileHandle::body()
-{
- BOOST_ASSERT(body_);
- return *body_;
-}
-
-prefix_ senf::FileBody const & senf::FileHandle::body()
- const
-{
- BOOST_ASSERT(body_);
- return *body_;
-}
-
prefix_ senf::FileBody & senf::FileHandle::body(FileHandle & handle)
{
return handle.body();