Boost logo

Boost :

From: dmoore99atwork (dmoore_at_[hidden])
Date: 2002-01-22 08:29:14


> I do have a couple of questions for other people who have spent
time thinking on this problem...

I forgot one!

5. In the requirements document, it is suggested that since platform
header files for socket APIs are notorious for poor macro practices
like redefining "send", etc., that these headers should never be
included by any Boost socket headers that are a part of the public
interface. I understand the rationale, but... Wrapper classes for
in_addr and sockaddr_in would need to use heap allocation for their
wrapped structures. Is this worth it? I'm leaning towards "yes", as
the heap allocation doesn't seem to be anything to be afraid of,
except perhaps in busy servers....

Example using platform headers in interface header:

// socket_address.hpp
#include <winsock2.h>

class socket_address
{
public:
   socket_address();
private:
   sockaddr_in _addr;
};

// socket_address.cpp
socket_address::
socket_address()
{
  memset(&_addr,0,sizeof(addr);
}

-or-

Example not including platform socket API

// socket_address.hpp

struct sockaddr_in;

class socket_address
{
public:
  socket_address();
private:
  // don't know size, so can only point to the forward declared
  // structure
  sockaddr_in *_paddr;
};

// socket_address.cpp
#include <winsock2.h>

socket_address::
socket_address() : _paddr(new sockaddr_in);
{
  memset(_paddr,0,sizeof(sockaddr_in));
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk