C++ Network Programming, Volume I: Mastering Complexity with ACE and Patterns
I l @ ve RuBoard |
Motivation
Network addressing is a trouble spot in the Socket API. Socket API network addressing mechanisms use C structures and typecasts , which are tedious and error-prone to program. The address family is the first member of the generic addressing structure, sockaddr . Other address structures, such as sockaddr_in for Internet-domain addresses and sockaddr_un for UNIX-domain addresses, also have an address family member that occupies the same position and size as in the sockaddr struct . Applications use these specific address family structures by
To minimize the complexity of all these low-level details, ACE defines a hierarchy of classes that provide a uniform interface for all ACE network addressing objects. Class Capabilities
The ACE_Addr class is the root of the ACE network addressing hierarchy. The interface of this class is shown in Figure 3.4 and its key methods provide the following capabilities that are common to all the ACE network addressing classes:
Figure 3.4. The ACE_Addr and ACE_INET_Addr Class Diagrams
The ACE_Addr class also defines a sap_any static data member that both client and server applications can use as a "wildcard" if they don't care what address they're assigned. For example,
Concrete address classes for each IPC mechanism, such as Internet-domain sockets and UNIX-domain sockets, derive from ACE_Addr and add their addressing needs. For example, TCP/IP and UDP/IP addressing information is represented in the ACE_INET_Addr class shown in Figure 3.4. In addition to implementing the ACE_Addr base interface, ACE_INET_Addr provides the following key methods:
The use of the ACE Socket wrapper facades for network addressing avoids common traps and pitfalls that can arise when using the C sockaddr family of data structures. For example, consider the ACE_INET_Addr constructor shown in Figure 3.4. This constructor creates an ACE_INET_ Addr from a port number and host name, thereby eliminating common programming errors by
ACE_INET_Addr allows developers to write networked applications without concern for low-level address initialization details. There are many other overloaded constructors and set() methods in ACE _INET_Addr that can be used to initialize Internet-domain network address objects using various combinations of host names, IP addresses, and/or TCP/UDP port names and numbers. |
I l @ ve RuBoard |