From: g0dil Date: Fri, 5 Dec 2008 10:27:39 +0000 (+0000) Subject: Socket: Add timeout arg to FileHandle 'wait' members X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=04181eba2e5e1dd0a8552b69905d7a3d493e2d77;p=senf.git Socket: Add timeout arg to FileHandle 'wait' members Fix emacs auto-indentation of namespaces git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1004 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Scheduler/Console/ParsedCommand.ih b/Scheduler/Console/ParsedCommand.ih index 0e22021..65a02f7 100644 --- a/Scheduler/Console/ParsedCommand.ih +++ b/Scheduler/Console/ParsedCommand.ih @@ -38,7 +38,7 @@ namespace console { template < class FunctionTraits, class ReturnType=typename FunctionTraits::result_type, - unsigned arity=FunctionTraits::arity > + unsigned arity=FunctionTraits::arity > class ParsedCommandOverload; template < class Overload, diff --git a/Socket/FileHandle.cc b/Socket/FileHandle.cc index 5ee1afe..bc8ea9c 100644 --- a/Socket/FileHandle.cc +++ b/Socket/FileHandle.cc @@ -111,7 +111,7 @@ prefix_ void senf::FileBody::blocking(bool status) /* We don't take POLLIN/POLLOUT as argument to avoid having to include sys/poll.h in the .cci file (and therefore indirectly into the .hh and then every file which uses FileHandle) */ -prefix_ bool senf::FileBody::pollCheck(int fd, bool incoming, bool block, bool oob) +prefix_ bool senf::FileBody::pollCheck(int fd, bool incoming, int timeout, bool oob) const { struct ::pollfd pfd; @@ -120,7 +120,7 @@ prefix_ bool senf::FileBody::pollCheck(int fd, bool incoming, bool block, bool o pfd.events = incoming?(oob?POLLPRI:POLLIN):POLLOUT; int rv = -1; do { - rv = ::poll(&pfd,1,block?-1:0); + rv = ::poll(&pfd,1,timeout); if (rv<0) switch (errno) { case EINTR: diff --git a/Socket/FileHandle.cci b/Socket/FileHandle.cci index 5cbfce4..6db39f5 100644 --- a/Socket/FileHandle.cci +++ b/Socket/FileHandle.cci @@ -72,37 +72,40 @@ prefix_ bool senf::FileBody::valid() 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_ void senf::FileBody::waitWriteable() +prefix_ bool senf::FileBody::waitWriteable(senf::ClockService::clock_type timeout) const { - pollCheck(fd(),false,true); + return pollCheck(fd(), false, + (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)) ); } prefix_ bool senf::FileBody::oobReadable() const { - return pollCheck(fd(),true,false,true); + return pollCheck(fd(),true,0,true); } -prefix_ void senf::FileBody::waitOOBReadable() +prefix_ bool senf::FileBody::waitOOBReadable(senf::ClockService::clock_type timeout) const { - pollCheck(fd(),true,true,true); + return pollCheck(fd(), true, + (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)), true); } /////////////////////////////////////////////////////////////////////////// @@ -137,10 +140,10 @@ prefix_ bool senf::FileHandle::readable() 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() @@ -149,10 +152,10 @@ prefix_ bool senf::FileHandle::writeable() return body().writeable(); } -prefix_ void senf::FileHandle::waitWriteable() +prefix_ bool senf::FileHandle::waitWriteable(senf::ClockService::clock_type timeout) const { - body().waitWriteable(); + return body().waitWriteable(timeout); } prefix_ bool senf::FileHandle::oobReadable() @@ -161,10 +164,10 @@ prefix_ bool senf::FileHandle::oobReadable() return body().oobReadable(); } -prefix_ void senf::FileHandle::waitOOBReadable() +prefix_ bool senf::FileHandle::waitOOBReadable(senf::ClockService::clock_type timeout) const { - body().waitOOBReadable(); + return body().waitOOBReadable(timeout); } prefix_ bool senf::FileHandle::blocking() diff --git a/Socket/FileHandle.hh b/Socket/FileHandle.hh index cf3fc67..377a8a6 100644 --- a/Socket/FileHandle.hh +++ b/Socket/FileHandle.hh @@ -68,6 +68,7 @@ // Custom includes #include // std::auto_ptr #include "../Utils/safe_bool.hh" +#include "../Scheduler/ClockService.hh" //#include "FileHandle.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -137,16 +138,31 @@ namespace senf { bool readable() const; ///< Check, whether a read on the handle would not block ///< (ignoring blocking state) - void waitReadable() const; ///< Wait, until read on the handle would not block (ignoring + bool waitReadable(senf::ClockService::clock_type timeout = -1) const; + ///< Wait, until read on the handle would not block (ignoring ///< blocking state) + /**< \param[in] timeout max time to wait, default is to wait + forever. + \returns \c true, if handle became readable or \c false on + timeout. */ bool writeable() const; ///< Check, whether a write on the handle would not block ///< (ignoring blocking state) - void waitWriteable() const; ///< Wait, until a write on the handle would not block + bool waitWriteable(senf::ClockService::clock_type timeout = -1) const; + ///< Wait, until a write on the handle would not block ///< (ignoring blocking state) + /**< \param[in] timeout max time to wait, default is to wait + forever. + \returns \c true, if handle became writable or \c false on + timeout. */ bool oobReadable() const; ///< Check, whether a read of prioritized data on the handle ///< would not block (ignoring blocking state) - void waitOOBReadable() const; ///< Wait, until read of prioritized data on the handle does + bool waitOOBReadable(senf::ClockService::clock_type timeout = -1) const; + ///< Wait, until read of prioritized data on the handle does ///< not block (ignoring blocking state) + /**< \param[in] timeout max time to wait, default is to wait + forever. + \returns \c true, if handle became readable for + out-of-band data or \c false on timeout. */ bool blocking() const; ///< Return current blocking state void blocking(bool status); ///< Set blocking state diff --git a/Socket/FileHandle.ih b/Socket/FileHandle.ih index 87b1920..b13f2fe 100644 --- a/Socket/FileHandle.ih +++ b/Socket/FileHandle.ih @@ -105,11 +105,11 @@ namespace senf { void destroyClose(); bool readable() const; - void waitReadable() const; + bool waitReadable(senf::ClockService::clock_type timeout) const; bool writeable() const; - void waitWriteable() const; + bool waitWriteable(senf::ClockService::clock_type timeout) const; bool oobReadable() const; - void waitOOBReadable() const; + bool waitOOBReadable(senf::ClockService::clock_type timeout) const; bool blocking() const; void blocking(bool status); @@ -142,7 +142,7 @@ namespace senf { protected: private: - bool pollCheck(int fd, bool incoming, bool block=false, bool oob=false) const; + bool pollCheck(int fd, bool incoming, int timeout, bool oob=false) const; int fd_; }; diff --git a/project.el b/project.el index 37d2b69..703309f 100644 --- a/project.el +++ b/project.el @@ -1,6 +1,11 @@ ;; Configuration file for cc-ide.el (Emacs C++ IDE extension, see http://g0dil.de) - (defvar senf-c-style +(defun check-namespace-indent (arg) + (save-excursion + (back-to-indentation) + (if (looking-at "namespace") [0] '+))) + + (defconst senf-c-style '((c-basic-offset . 4) (c-backslash-column . 98) (c-cleanup-list . (empty-defun-braces @@ -16,9 +21,9 @@ (extern-lang-open after) (inexpr-class-open after) (inexpr-class-close before))) - (c-offsets-alist . ((namespace-open . 0) - (namespace-close . 0) - (innamespace . +) + (c-offsets-alist . ((namespace-open . [0]) + (namespace-close . [0]) + (innamespace . check-namespace-indent) (statement-block-intro . +) (substatement-open . 0) (label . 0)