From: g0dil Date: Fri, 10 Nov 2006 23:14:58 +0000 (+0000) Subject: add optional 'limit' argument to read X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=b2d64a4084a053f0887c7845bb81074e0cd3a855;p=senf.git add optional 'limit' argument to read add missing retrive_filehandle overload fix operator bool (use safe bool idiom) add GenericSockAddr as default Address implementation git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@153 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Socket/ClientSocketHandle.ct b/Socket/ClientSocketHandle.ct index 1e7fa7b..50c80a8 100644 --- a/Socket/ClientSocketHandle.ct +++ b/Socket/ClientSocketHandle.ct @@ -30,17 +30,19 @@ ///////////////////////////////ct.p//////////////////////////////////////// template -prefix_ std::string satcom::lib::ClientSocketHandle::read() +prefix_ std::string satcom::lib::ClientSocketHandle::read(unsigned limit) { std::string rv; - this->read(rv); + this->read(rv,limit); return rv; } template -prefix_ void satcom::lib::ClientSocketHandle::read(std::string & buffer) +prefix_ void satcom::lib::ClientSocketHandle::read(std::string & buffer, unsigned limit) { unsigned nread = available(); + if (limit>0 && nread>limit) + nread = limit; // FIXME: This is not necessary correct and more or less a hack ... buffer.assign(nread,0); unsigned rv = this->read(const_cast(buffer.data()),nread); diff --git a/Socket/ClientSocketHandle.hh b/Socket/ClientSocketHandle.hh index 0e670ab..4f9b986 100644 --- a/Socket/ClientSocketHandle.hh +++ b/Socket/ClientSocketHandle.hh @@ -78,8 +78,8 @@ namespace lib { ///@{ // read from socket (connected or unconnected) - std::string read (); - void read (std::string & buffer); + std::string read (unsigned limit=0); + void read (std::string & buffer, unsigned limit=0); unsigned read (char * buffer, unsigned size); // read from unconnected socket returning peer address diff --git a/Socket/CommunicationPolicy.cc b/Socket/CommunicationPolicy.cc index 8523966..bc2fa33 100644 --- a/Socket/CommunicationPolicy.cc +++ b/Socket/CommunicationPolicy.cc @@ -53,7 +53,6 @@ prefix_ int satcom::lib::ConnectedCommunicationPolicy::do_accept(FileHandle hand switch (errno) { case EWOULDBLOCK: return -1; - break; case EINTR: break; default: diff --git a/Socket/FileHandle.cci b/Socket/FileHandle.cci index f633fdf..bb366ba 100644 --- a/Socket/FileHandle.cci +++ b/Socket/FileHandle.cci @@ -172,18 +172,12 @@ prefix_ bool satcom::lib::FileHandle::valid() return body().valid(); } -prefix_ satcom::lib::FileHandle::operator bool () +prefix_ bool satcom::lib::FileHandle::boolean_test() const { return valid() && !eof(); } -prefix_ bool satcom::lib::FileHandle::operator!() - const -{ - return ! (valid() && !eof()); -} - prefix_ int satcom::lib::FileHandle::fd() const { @@ -233,6 +227,11 @@ satcom::lib::FileHandle::cast_dynamic(FileHandle handle) return handle; } +prefix_ int satcom::lib::retrieve_filehandle(FileHandle handle) +{ + return handle.fd(); +} + ///////////////////////////////cci.e/////////////////////////////////////// #undef prefix_ diff --git a/Socket/FileHandle.hh b/Socket/FileHandle.hh index 3bc6155..febfa01 100644 --- a/Socket/FileHandle.hh +++ b/Socket/FileHandle.hh @@ -33,6 +33,7 @@ // Custom includes #include // std::auto_ptr +#include "Utils/SafeBool.hh" //#include "FileHandle.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -44,6 +45,7 @@ namespace lib { /** \brief */ class FileHandle + : public SafeBool { public: /////////////////////////////////////////////////////////////////////////// @@ -77,8 +79,7 @@ namespace lib { bool eof() const; bool valid() const; - operator bool () const; - bool operator!() const; + bool boolean_test() const; int fd() const; @@ -99,6 +100,8 @@ namespace lib { FileBody::ptr body_; }; + int retrieve_filehandle(FileHandle handle); + }} ///////////////////////////////hh.e//////////////////////////////////////// diff --git a/Socket/GenericSockAddr.cci b/Socket/GenericSockAddr.cci new file mode 100644 index 0000000..7ab4372 --- /dev/null +++ b/Socket/GenericSockAddr.cci @@ -0,0 +1,38 @@ +// $Id$ +// +// Copyright (C) 2006 + +// Definition of inline non-template functions + +// Custom includes + +#define prefix_ inline +///////////////////////////////cci.p/////////////////////////////////////// + +prefix_ satcom::lib::GenericSockAddr::GenericSockAddr() +{} + +prefix_ struct sockaddr * satcom::lib::GenericSockAddr::sockaddr_p() +{ + return reinterpret_cast(&addr_); +} + +prefix_ struct sockaddr const * satcom::lib::GenericSockAddr::sockaddr_p() + const +{ + return reinterpret_cast(&addr_); +} + +prefix_ unsigned satcom::lib::GenericSockAddr::sockaddr_len() + const +{ + return sizeof(addr_); +} + +///////////////////////////////cci.e/////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// End: diff --git a/Socket/GenericSockAddr.hh b/Socket/GenericSockAddr.hh new file mode 100644 index 0000000..c05d158 --- /dev/null +++ b/Socket/GenericSockAddr.hh @@ -0,0 +1,42 @@ +// $Id$ +// +// Copyright (C) 2006 + +#ifndef HH_GenericSockAddr_ +#define HH_GenericSockAddr_ 1 + +// Custom includes +#include + +//#include "GenericSockAddr.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +namespace satcom { +namespace lib { + + class GenericSockAddr + { + public: + GenericSockAddr(); + + struct sockaddr * sockaddr_p(); + struct sockaddr const * sockaddr_p() const; + unsigned sockaddr_len() const; + + private: + struct ::sockaddr_storage addr_; + }; + +}} + +///////////////////////////////hh.e//////////////////////////////////////// +#include "GenericSockAddr.cci" +//#include "GenericSockAddr.ct" +//#include "GenericSockAddr.cti" +//#include "GenericSockAddr.mpp" +#endif + + +// Local Variables: +// mode: c++ +// End: diff --git a/Socket/SocketHandle.cc b/Socket/SocketHandle.cc index 186953a..d0e7e91 100644 --- a/Socket/SocketHandle.cc +++ b/Socket/SocketHandle.cc @@ -99,12 +99,14 @@ prefix_ bool satcom::lib::detail::StateMapOrdering::operator()(std::string a1, s return false; if (contains(i2,i2_end,'.')) // the longer string is a sub-'directory' of the shorter + // FIXME: shouldn't this be *i2 == '.' ? return true; return *i1 < *i2; } else if (i2 == i2_end) { // && i1 != i1_end if (contains(i1,i1_end,'.')) // the longer string is a sub-'directory' of the shorter + // FIXME: shouldn't this be *i1 == '.' ? return false; return *i1 < *i2; } diff --git a/Socket/SocketPolicy.ih b/Socket/SocketPolicy.ih index 58fcba3..b60fd94 100644 --- a/Socket/SocketPolicy.ih +++ b/Socket/SocketPolicy.ih @@ -46,6 +46,8 @@ #include #include // for enable_if +#include "GenericSockAddr.hh" + ///////////////////////////////ih.p//////////////////////////////////////// namespace satcom { @@ -62,11 +64,7 @@ namespace lib { { virtual ~ AddressingPolicyBase() {} - class Address - { - private: - Address(); - }; + typedef GenericSockAddr Address; }; # define SP_DeclareBase(x1,x2,SomePolicy) \