|
Boost : |
From: davlet_panech (davlet_panech_at_[hidden])
Date: 2002-01-22 15:24:51
--- In boost_at_y..., "dmoore99atwork" <dmoore_at_a...> wrote:
> > 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....
I suppose you could use a char buffer whose size equals to sizeof
(wrapped_type):
class socket_address {
public:
socket_address();
private:
// say, sizeof( sockaddr_in ) == 64
char buf_[ 64 ];
};
D.P.
>
>
> 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