summaryrefslogtreecommitdiff
path: root/ace/CLASSIX/CLASSIX_CLD_Connector.cpp
blob: a054213561ae27deb0163235ae8fbaf8854aa59c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// $Id$
/*
// ============================================================================
//
// = LIBRARY
//     ace
// 
// = FILENAME
//     CLASSIX_CLD_Connector.cpp
//
// = AUTHOR(S)
//     Nokia Telecommunications
// 
//
// ============================================================================
*/
#define ACE_BUILD_DLL
#include "ace/CLASSIX/CLASSIX_CLD_Connector.h"
#include "ace/CLASSIX/CLASSIX_Addr.h"

ACE_ALLOC_HOOK_DEFINE(ACE_CLASSIX_CLD_Connector)

#if !defined (__ACE_INLINE__)
#include "CLASSIX_CLD_Connector.i"
#endif /* __ACE_INLINE__ */
/* ------------------------------------------------------------------------- */

ACE_CLASSIX_CLD_Connector::ACE_CLASSIX_CLD_Connector (
    ACE_CLASSIX_Stream &new_stream, 
    const ACE_Addr &remote_sap, 
    ACE_Time_Value *timeout,
    const ACE_Addr &local_sap,
    int reuse_addr,
    int flags,
    int perms,
    int protocol_family,
    int protocol)
{
  ACE_TRACE ("ACE_CLASSIX_CLD_Connector::ACE_CLASSIX_CLD_Connector");
  if (this->connect (new_stream, remote_sap, timeout, local_sap,
		     reuse_addr, flags, perms, 
		     protocol_family, protocol) == -1)
      ACE_ERROR ((LM_ERROR, 
		  ASYS_TEXT ("%p\n"),  ASYS_TEXT 
		  ("ACE_CLASSIX_CLD_Connector::ACE_CLASSIX_CLD_Connector")));
}

// Set up remote port information
int
ACE_CLASSIX_CLD_Connector::connect (ACE_CLASSIX_Stream &new_stream, 
				    const ACE_Addr & theRemote,/* remote_sap */
				    ACE_Time_Value *, /* timeout */
				    const ACE_Addr & theLocal,
                                    int, /* reuse_addr */
				    int theFlag, /* flags */
				    int, /* perms */
				    int theProtocolFamily, 
				    int /* protocol */)

{
    ACE_TRACE ("ACE_CLASSIX_CLD_Connector::connect");
    //
    // Set up peer SAP
    // 
    if (theRemote == ACE_Addr::sap_any ||
	new_stream.set_peer_sap(theRemote) != 0)
	ACE_ERROR_RETURN((LM_ERROR, "ACE_CLASSIX_CLD_Connector::connect()::"
			  "Invalid Connector SAP\n"), -1);

    //
    // Set up local SAP
    // 
    if (theLocal == ACE_Addr::sap_any)
    {
	// if local sap has not been configured
	// create a port and use it as the local SAP 
	new_stream.open();
    }
    else
    {
	// replace the local SAP information
	new_stream.close();
	new_stream.open(theLocal);
    }
    
    //
    // Make the local SAP "selectable", if requested via the flag
    // 
    if (new_stream.local_sap().is_configured() && 
	new_stream.peer_sap().is_configured() &&  /* remote sap info exist */
	theProtocolFamily == ACE_CLASSIX_Addr::AF_CLASSIX)
    {
	new_stream.control();
	// setup the default delivery mode, if applicable
	if (theFlag & ACE_CLASSIX_CLD_Connector::ENABLE)
	{
	    if (new_stream.selectable() == 0)
		return 0;
	    else
		return -1;
	}
	return 0;
    }
    else
    {
	return -1;
    }
}

void
ACE_CLASSIX_CLD_Connector::dump (void) const
{
  ACE_TRACE ("ACE_CLASSIX_CLD_Connector::dump");
}

/* ------------------------------------------------------------------------- */