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)
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
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
;
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
37 virtual ~JAWS_IO_Acceptor ();
39 virtual int open (const ACE_INET_Addr
&address
, int backlog
= 20);
40 // Initiate a passive mode socket.
42 virtual int open (const ACE_HANDLE
&socket
);
43 // Initiate a passive mode socket.
45 virtual int accept (ACE_SOCK_Stream
&new_stream
,
46 ACE_Addr
*remote_addr
= 0,
47 ACE_Time_Value
*timeout
= 0,
49 int reset_new_handle
= 0) const;
50 // Synchronously accept the connection
52 virtual int accept (size_t bytes_to_read
= 0, const void *act
= 0);
53 // This initiates a new asynchronous accept through the AcceptEx call.
55 virtual ACE_HANDLE
get_handle ();
56 // Get the listener's handle
58 virtual void close ();
59 // Close the acceptor.
61 enum { ASYNC
= 0, SYNCH
= 1 };
62 // identify if this is being used for asynchronous or synchronous
66 class JAWS_Export JAWS_IO_Synch_Acceptor
: public JAWS_IO_Acceptor
69 virtual int open (const ACE_INET_Addr
&local_sap
, int backlog
= 20);
70 // Initiate a passive mode socket.
72 virtual int open (const ACE_HANDLE
&socket
);
73 // Initiate a passive mode socket.
75 virtual int accept (ACE_SOCK_Stream
&new_stream
,
76 ACE_Addr
*remote_addr
= 0,
77 ACE_Time_Value
*timeout
= 0,
79 int reset_new_handle
= 0) const;
80 // Accept the connection
82 virtual ACE_HANDLE
get_handle ();
83 // Get the listener's handle
86 virtual int accept (size_t bytes_to_read
= 0, const void *act
= 0);
89 JAWS_IO_SOCK_Acceptor acceptor_
;
93 class JAWS_Export JAWS_IO_Asynch_Acceptor
: public JAWS_IO_Acceptor
96 JAWS_IO_Asynch_Acceptor ();
97 virtual ~JAWS_IO_Asynch_Acceptor ();
99 virtual int open (const ACE_INET_Addr
&address
, int backlog
= 20);
100 // Initiate an asynchronous passive connection
102 virtual int open (const ACE_HANDLE
&socket
);
103 // Initiate an asynchronous passive connection
105 virtual int accept (size_t bytes_to_read
= 0, const void *act
= 0);
106 // This initiates a new asynchronous accept through the AcceptEx call.
108 virtual ACE_HANDLE
get_handle ();
109 // Get the listener's handle
111 virtual void close ();
114 virtual int accept (ACE_SOCK_Stream
&new_stream
,
115 ACE_Addr
*remote_addr
= 0,
116 ACE_Time_Value
*timeout
= 0,
118 int reset_new_handle
= 0) const;
121 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined (ACE_HAS_AIO_CALLS)
122 ACE_Asynch_Acceptor
<JAWS_Asynch_Handler
> &acceptor_
;
123 ACE_Asynch_Acceptor
<JAWS_Asynch_Handler
> *acceptor_ptr_
;
125 #endif /* ACE_HAS_WIN32_OVERLAPPED_IO || ACE_HAS_AIO_CALLS */
128 typedef ACE_Singleton
<JAWS_IO_Synch_Acceptor
, ACE_SYNCH_MUTEX
>
129 JAWS_IO_Synch_Acceptor_Singleton
;
131 typedef ACE_Singleton
<JAWS_IO_Asynch_Acceptor
, ACE_SYNCH_MUTEX
>
132 JAWS_IO_Asynch_Acceptor_Singleton
;
134 #endif /* !defined (JAWS_IO_ACCEPTOR_H) */