Skip to content
Snippets Groups Projects
Commit dc166b28 authored by g0dil's avatar g0dil
Browse files

add optional 'limit' argument to read

add missing retrive_filehandle overload
fix operator bool (use safe bool idiom)
add GenericSockAddr as default Address implementation
parent bb868b47
No related branches found
No related tags found
No related merge requests found
......@@ -30,17 +30,19 @@
///////////////////////////////ct.p////////////////////////////////////////
template <class Policy>
prefix_ std::string satcom::lib::ClientSocketHandle<Policy>::read()
prefix_ std::string satcom::lib::ClientSocketHandle<Policy>::read(unsigned limit)
{
std::string rv;
this->read(rv);
this->read(rv,limit);
return rv;
}
template <class Policy>
prefix_ void satcom::lib::ClientSocketHandle<Policy>::read(std::string & buffer)
prefix_ void satcom::lib::ClientSocketHandle<Policy>::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<char *>(buffer.data()),nread);
......
......@@ -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
......
......@@ -53,7 +53,6 @@ prefix_ int satcom::lib::ConnectedCommunicationPolicy::do_accept(FileHandle hand
switch (errno) {
case EWOULDBLOCK:
return -1;
break;
case EINTR:
break;
default:
......
......@@ -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_
......
......@@ -33,6 +33,7 @@
// Custom includes
#include <memory> // std::auto_ptr
#include "Utils/SafeBool.hh"
//#include "FileHandle.mpp"
///////////////////////////////hh.p////////////////////////////////////////
......@@ -44,6 +45,7 @@ namespace lib {
/** \brief
*/
class FileHandle
: public SafeBool<FileHandle>
{
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////////////////////////////////////////
......
// $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<sockaddr *>(&addr_);
}
prefix_ struct sockaddr const * satcom::lib::GenericSockAddr::sockaddr_p()
const
{
return reinterpret_cast<sockaddr const *>(&addr_);
}
prefix_ unsigned satcom::lib::GenericSockAddr::sockaddr_len()
const
{
return sizeof(addr_);
}
///////////////////////////////cci.e///////////////////////////////////////
#undef prefix_
// Local Variables:
// mode: c++
// End:
// $Id$
//
// Copyright (C) 2006
#ifndef HH_GenericSockAddr_
#define HH_GenericSockAddr_ 1
// Custom includes
#include <sys/socket.h>
//#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:
......@@ -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;
}
......
......@@ -46,6 +46,8 @@
#include <boost/mpl/and.hpp>
#include <boost/utility.hpp> // 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) \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment