blob: 55bda8694e05315a3715826ad9855cc1dd8c33e4 (
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
/* -*- C++ -*- */
//=============================================================================
/**
* @file Asynch_Connector.h
*
* $Id$
*
* @author Alexander Libman <alibman@ihug.com.au>
*/
//=============================================================================
#ifndef ACE_ASYNCH_CONNECTOR_H
#define ACE_ASYNCH_CONNECTOR_H
#include "ace/pre.h"
#include "ace/OS.h"
#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
#if defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS)
// This only works on platforms that support async i/o.
#include "ace/Asynch_IO.h"
#include "ace/INET_Addr.h"
// Forward declarations
class ACE_Message_Block;
/**
* @class ACE_Asynch_Connector
*
* @brief This class is an example of the Connector pattern. This class
* will establish new connections and create new HANDLER objects to handle
* the new connections.
*
* Unlike the ACE_Connector, however, this class is designed to
* be used asynchronously with the ACE Proactor framework.
*/
template <class HANDLER>
class ACE_Asynch_Connector : public ACE_Handler
{
public:
/// A do nothing constructor.
ACE_Asynch_Connector (void);
/// Virtual destruction
virtual ~ACE_Asynch_Connector (void);
/**
* This opens asynch connector
*/
virtual int open (int pass_addresses = 0,
ACE_Proactor *proactor = 0,
int validate_new_connection = 0);
/// This initiates a new asynchronous connect
virtual int connect (const ACE_INET_Addr &remote_sap,
const ACE_INET_Addr &local_sap =
ACE_INET_Addr ((u_short)0),
int reuse_addr = 1,
const void *act = 0);
/**
* This cancels all pending accepts operations that were issued by
* the calling thread.
*
* @note On Windows, this method does not cancel connect operations
* issued by other threads.
*
* @note On POSIX, delegates cancelation to ACE_POSIX_Asynch_Connect.
*/
virtual int cancel (void);
/**
* Template method for address validation.
*
* Default implemenation always validates the remote address.
*/
virtual int validate_new_connection (const ACE_INET_Addr &remote_address);
//
// These are low level tweaking methods
//
/// Set and get flag that indicates if parsing and passing of
/// addresses to the service_handler is necessary.
virtual int pass_addresses (void) const;
virtual void pass_addresses (int new_value);
/// Set and get flag that indicates if address validation is
/// required.
virtual int validate_new_connection (void) const;
virtual void validate_new_connection (int new_value);
protected:
/// This is called when an outstanding accept completes.
virtual void handle_connect (const ACE_Asynch_Connect::Result &result);
/// This parses the address from read buffer.
void parse_address (const ACE_Asynch_Connect::Result &result,
ACE_INET_Addr &remote_address,
ACE_INET_Addr &local_address);
/// Return the asynch Connect object.
ACE_Asynch_Connect & asynch_connect (void);
/**
* This is the template method used to create new handler.
* Subclasses must overwrite this method if a new handler creation
* strategy is required.
*/
virtual HANDLER *make_handler (void);
private:
/// Asynch_Connect used to make life easier :-)
ACE_Asynch_Connect asynch_connect_;
/// Flag that indicates if parsing of addresses is necessary.
int pass_addresses_;
/// Flag that indicates if address validation is required.
int validate_new_connection_;
};
#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "ace/Asynch_Connector.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
#pragma implementation ("Asynch_Connector.cpp")
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
#endif /* ACE_WIN32 || ACE_HAS_AIO_CALLS */
#include "ace/post.h"
#endif /* ACE_ASYNCH_CONNECTOR_H */
|