In VxWorks, STREAMS sockets serve as one interface to the STREAMS protocol suites. Sockets are designed to provide a consistent communication facility for tasks, regardless of whether or not the tasks are on the same machine. In addition, sockets are designed to hide as much detail as possible regarding the way in which the underlying communication occurs.
A socket is an endpoint for communication that gets bound to a port within the node. Each socket in use has a type and is associated with a communication domain when it is created. Domains are abstractions that imply both an addressing structure and a set of protocols that implement socket types within the domain.
Figure 8 shows the architecture for socket communication in a VxWorks environment. Applications make calls that are handled by the socket layer. The socket layer translates a file descriptor to a socket and invokes a routine in the protocol layer to service the call. The socket data structure is shared between the socket layer and protocol layer. The protocol layer communicates with the network driver to send and receive packets to or from the network.
The socket mechanism is implemented in the STREAMS framework, as shown in Figure 9. A user-level library (configured by defining INCLUDE_STREAMS_SOCKET in configAll.h; see §6.1 Configuring VxWorks for WindNet STREAMS) provides socket calls, such as socket( ), connect( ) , bind( ), etc. These library routines interact with a STREAMS module, sockmod, that is pushed on top of a STREAMS-based transport provider. The socket library and sockmod work in close cooperation. When semantics allow, the socket library creates TPI messages equivalent to socket( ), and sockmod passes the message to the transport provider. For other calls, the socket library does almost nothing except issue an ioctl( ) that is intercepted by sockmod, which in turn creates a TPI message and interacts with the transport provider to complete the request. §3.2.4 Addition of Transport Providers to WindNet STREAMS Sockets explains how this implementation has the undesirable effect of making it difficult to provide transport independence at the socket layer.
The WindNet STREAMS socket library is provided to enable porting of existing socket applications to a STREAMS environment by relinking object code with the library. No source code changes should be required. Table 2 lists the basic socket routines found in the WindNet STREAMS socket library.
|
|||||||||||||||||||
|
|||||||||||||||||||
|
|||||||||||||||||||
|
|||||||||||||||||||
WindNet STREAMS sockets are compatible with the VxWorks BSD 4.3 interface. However, there are known differences between STREAMS sockets and BSD sockets. Those differences are listed in Table 3.
|
|||||||||||||||||||
|
|||||||||||||||||||
|
|||||||||||||||||||
|
|||||||||||||||||||
The STREAMS socket library has an inherent deficiency that has been remedied by WindNet STREAMS: In STREAMS, there is no transport provider independence at the socket layer because the socket associates itself with the transport provider by opening the transport provider device; thus, socket( ) cannot open different providers based on socket parameter values. The WindNet STREAMS socket implementation provides transport independence through a routine, strmSockProtoAdd( ).
The strmSockProtoAdd( ) routine registers a new transport provider by adding an entry to an internally-maintained table that contains information about available transport providers. The table's data is based on the following three parameters passed by strmSockProtoAdd( ):
When a socket call is made, the socket library, where the table is located, decides which transport provider to use based on the parameters passed by the socket call. The strmSockProtoAdd( ) routine is usually invoked at system initialization. It must be called before socket( ).
The strmSockProtoAdd( ) routine creates an association among the parameter values--for a unique family and type, there is a unique transport provider specified by devName-- so when socket( ) is called, the parameters that have been passed to it prompt the library to select the appropriate transport provider. For example, the following code fragment associates socket calls using the address family AF_INET and the socket type SOCK_STREAM with the transport provider /dev/tcp. The socket call establishes the transport endpoint using the TCP transport provider.
strmSockProtoAdd (AF_INET, SOCK_STREAM,"/dev/tcp"); socket (AF_INET,SOCK_STREAM,0);
In the following code fragment, socket calls that use the address family AF_INET and socket type SOCK_DGRAM are associated with the transport provider /dev/udp. The socket call establishes the transport endpoint using the UDP transport provider.
strmSockProtoAdd (AF_INET, SOCK_DGRAM,"/dev/udp"); socket (AF_INET,SOCK_DGRAM,0);
In this third example, socket calls that use the address family AF_CCITT have been associated with the socket type SOCK_STREAM with the transport provider /dev/x25.
strmSockProtoAdd (AF_CCITT,SOCK_STREAM,"/dev/x25"); socket (AF_CCITT,SOCK_STREAM,0);
WindNet STREAMS sockets are designed to co-exist with VxWorks BSD sockets, which are discussed in the VxWorks Programmer's Guide: Network. This is achieved using a layered operating environment, that is, the VxWorks socket library is a layer above the BSD socket and WindNet STREAMS socket layers, as shown in Figure 10.
Calls to routines in the VxWorks socket library are directed to the appropriate underlying socket library, either BSD or WindNet STREAMS, based on the default defined in configAll.h or the parameters passed to the socket layer. The BSD socket library is configured into the VxWorks system image, making it the system default. You can define configuration constants to make WindNet STREAMS sockets an alternate default. The routine socket( )creates a communication endpoint in either the BSD or WindNet STREAMS socket library based on the parameters passed to it, and thus designates the socket library to be used by your application.
The following constants have been newly added to configAll.h and configure the specified socket library into VxWorks and make it the default choice:
To configure your environment for BSD sockets, no new steps need be taken because INCLUDE_BSD_SOCKETS is defined in configAll.h by default.
To configure your environment for WindNet STREAMS sockets, define INCLUDE_STREAMS_SOCKET in configAll.h. This constant alone does not make the default socket layer the WindNet STREAMS socket library; it only configures into VxWorks WindNet STREAMS sockets. To change the default, you must define DEFAULT_STREAMS_SOCKET in configAll.h.
The following examples show how to use WindNet STREAMS sockets and BSD sockets separately or concurrently:
socket (AF_INET, SOCK_STREAM,0)
socket (AF_INET_BSD, SOCK_STREAM,0)
socket (AF_INET, SOCK_STREAM,0)
socket (AF_INET_STREAMS, SOCK_STREAM, 0)