Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / ACE / apps / JAWS2 / JAWS / IO_Acceptor.h
blob35a7473ece611cecc7cd3d4d3ffd2b9dc0c12693
1 /* -*- c++ -*- */
2 #ifndef JAWS_IO_ACCEPTOR_H
3 #define JAWS_IO_ACCEPTOR_H
5 // Use the Adapter pattern to encapsulate either a LOCK_SOCK_Acceptor or
6 // an ACE_Asynch_Acceptor
8 #include "ace/Asynch_Acceptor.h"
10 #if !defined (ACE_LACKS_PRAGMA_ONCE)
11 # pragma once
12 #endif /* ACE_LACKS_PRAGMA_ONCE */
14 #include "ace/LOCK_SOCK_Acceptor.h"
15 #include "ace/Singleton.h"
17 #include "JAWS/Export.h"
18 #include "JAWS/Jaws_IO.h"
19 #include "JAWS/IO_Handler.h"
21 // Forward declaration.
22 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
23 class ACE_Proactor;
24 class ACE_Reactor;
25 ACE_END_VERSIONED_NAMESPACE_DECL
27 #if defined (JAWS_HAS_THREAD_SAFE_ACCEPT)
28 typedef ACE_LOCK_SOCK_Acceptor<ACE_SYNCH_NULL_MUTEX> JAWS_IO_SOCK_Acceptor;
29 #else
30 typedef ACE_LOCK_SOCK_Acceptor<ACE_SYNCH_MUTEX> JAWS_IO_SOCK_Acceptor;
31 #endif /* JAWS_HAS_THREAD_SAFE_ACCEPT */
33 class JAWS_Export JAWS_IO_Acceptor
35 public:
37 JAWS_IO_Acceptor (void);
38 virtual ~JAWS_IO_Acceptor (void);
40 virtual int open (const ACE_INET_Addr &address, int backlog = 20);
41 // Initiate a passive mode socket.
43 virtual int open (const ACE_HANDLE &socket);
44 // Initiate a passive mode socket.
46 virtual int accept (ACE_SOCK_Stream &new_stream,
47 ACE_Addr *remote_addr = 0,
48 ACE_Time_Value *timeout = 0,
49 int restart = 1,
50 int reset_new_handle = 0) const;
51 // Synchronously accept the connection
53 virtual int accept (size_t bytes_to_read = 0, const void *act = 0);
54 // This initiates a new asynchronous accept through the AcceptEx call.
56 virtual ACE_HANDLE get_handle (void);
57 // Get the listener's handle
59 virtual void close (void);
60 // Close the acceptor.
62 enum { ASYNC = 0, SYNCH = 1 };
63 // identify if this is being used for asynchronous or synchronous
64 // accept calls
68 class JAWS_Export JAWS_IO_Synch_Acceptor : public JAWS_IO_Acceptor
70 public:
72 virtual int open (const ACE_INET_Addr &local_sap, int backlog = 20);
73 // Initiate a passive mode socket.
75 virtual int open (const ACE_HANDLE &socket);
76 // Initiate a passive mode socket.
78 virtual int accept (ACE_SOCK_Stream &new_stream,
79 ACE_Addr *remote_addr = 0,
80 ACE_Time_Value *timeout = 0,
81 int restart = 1,
82 int reset_new_handle = 0) const;
83 // Accept the connection
85 virtual ACE_HANDLE get_handle (void);
86 // Get the listener's handle
88 private:
89 virtual int accept (size_t bytes_to_read = 0, const void *act = 0);
91 private:
92 JAWS_IO_SOCK_Acceptor acceptor_;
96 class JAWS_Export JAWS_IO_Asynch_Acceptor : public JAWS_IO_Acceptor
98 public:
100 JAWS_IO_Asynch_Acceptor (void);
101 virtual ~JAWS_IO_Asynch_Acceptor (void);
103 virtual int open (const ACE_INET_Addr &address, int backlog = 20);
104 // Initiate an asynchronous passive connection
106 virtual int open (const ACE_HANDLE &socket);
107 // Initiate an asynchronous passive connection
109 virtual int accept (size_t bytes_to_read = 0, const void *act = 0);
110 // This initiates a new asynchronous accept through the AcceptEx call.
112 virtual ACE_HANDLE get_handle (void);
113 // Get the listener's handle
115 virtual void close (void);
117 private:
119 virtual int accept (ACE_SOCK_Stream &new_stream,
120 ACE_Addr *remote_addr = 0,
121 ACE_Time_Value *timeout = 0,
122 int restart = 1,
123 int reset_new_handle = 0) const;
125 private:
126 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined (ACE_HAS_AIO_CALLS)
127 ACE_Asynch_Acceptor<JAWS_Asynch_Handler> &acceptor_;
128 ACE_Asynch_Acceptor<JAWS_Asynch_Handler> *acceptor_ptr_;
129 ACE_HANDLE handle_;
130 #endif /* ACE_HAS_WIN32_OVERLAPPED_IO || ACE_HAS_AIO_CALLS */
133 typedef ACE_Singleton<JAWS_IO_Synch_Acceptor, ACE_SYNCH_MUTEX>
134 JAWS_IO_Synch_Acceptor_Singleton;
136 typedef ACE_Singleton<JAWS_IO_Asynch_Acceptor, ACE_SYNCH_MUTEX>
137 JAWS_IO_Asynch_Acceptor_Singleton;
139 #endif /* !defined (JAWS_IO_ACCEPTOR_H) */