RWSockAddrFactoryRWSockAddrFactoryBaseRWSockAddrBase
Networking Tools: Network Communication Classes (net library)
#include <rw/toolpro/sockfact.h>
net, tls (and possibly std)
RWSockAddrFactory builds addresses of any (registered) type. This class is used by the network communication classes implementation and is not normally used explicitly. The global object rwSockAddrFactory is used by functions like RWSocket::getsockname, which do not know the type of socket address they need to build.
There are two stages to building an address using this factory. First, the type of address is determined. Next, the type of address is used to look up an RWSockAddrFactoryBase object, which is used to actually construct the address. Note that since an RWSockAddrFactory is itself an RWSockAddrFactoryBase, this scheme can be used in a hierarchical fashion.
The types are indicated to the factory by either the address family integer identifier (as defined by the C sockets API) or by a string. From there, the factory invokes a factory that is specific to the address family. It finds the specific factory using a dictionary kept with the factory.
Specific address factory objects need to be registered with the factory via the general factory's register() method. Check RWInetAddrFactory for an example of a specific address family factory.
These singleton objects are constructed explicitly rather than relying on static initialization. This way we have no dependence on order of static initialization.
RWSockAddrFactory();
Creates a factory with no create methods attached.
void registerWithFactory(const RWSockType& family, RWSockAddrFactoryBase *factory); void registerWithFactory(int family, RWSockAddrFactoryBase *factory); void registerWithFactory(const RWCString& family, RWSockAddrFactoryBase *factory);
Registers maker objects. Duplicate registration is a no-op. If you attempt to register two different factories with the same family, an exception is thrown. The variant that takes a socket type argument registers both the standard family name for that socket type and the family number. The pointer to the factory must remain valid as long as self is used to build addresses.
void unRegister(const RWSockType&); void unRegister(int family); void unRegister(const RWCString& family);
Removes all knowledge of how to build addresses of the indicated family from the factory. This is useful if you want to explicitly replace one factory with another for the same family. Unless you first unRegister, you get an exception. It is not an error to unregister a type that has never been registered.
virtual RWSockAddrBase* operator()(struct sockaddr *addr, int addrLen) const; virtual RWSockAddrBase* operator()(struct sockaddr *addr, int addrLen, int type) const; virtual RWSockAddrBase* operator()(const RWCString& str) const;
Constructs a socket address. First, you need to extract the family name (from the string) or identifier (from the sockaddr), then look up the appropriate factory object and use it. If no factory has been registered for the family, an exception is thrown.
The newly created socket address is allocated on the heap. The caller is responsible for deleting it. Often, this is managed by wrapping the object using an RWSockAddr.
static RWGenSockAddrFactory& theGlobalRWSockAddrFactory();
Returns the global factory that is used by the network communication classes. This is more conveniently accessed via the rwSockAddrFactory macro. If the factory has not yet been constructed, it is constructed and the well known families are registered.
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.