summaryrefslogtreecommitdiff
path: root/apps/JAWS2/JAWS/IO_Acceptor.h
blob: 78e861ec12e5ba3b27831588921d81c73ca15ea6 (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
/* -*- c++ -*- */
// $Id$

#ifndef JAWS_IO_ACCEPTOR_H
#define JAWS_IO_ACCEPTOR_H

// Use the Adapter pattern to encapsulate either a LOCK_SOCK_Acceptor or
// an ACE_Asynch_Acceptor

#include "ace/Asynch_Acceptor.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/LOCK_SOCK_Acceptor.h"
#include "ace/Singleton.h"

#include "JAWS/Export.h"
#include "JAWS/IO.h"
#include "JAWS/IO_Handler.h"

// Forward declaration.
class ACE_Proactor;
class ACE_Reactor;

#if defined (JAWS_HAS_THREAD_SAFE_ACCEPT)
typedef ACE_LOCK_SOCK_Acceptor<ACE_SYNCH_NULL_MUTEX> JAWS_IO_SOCK_Acceptor;
#else
typedef ACE_LOCK_SOCK_Acceptor<ACE_SYNCH_MUTEX> JAWS_IO_SOCK_Acceptor;
#endif /* JAWS_HAS_THREAD_SAFE_ACCEPT */

class JAWS_Export JAWS_IO_Acceptor
{
public:

  JAWS_IO_Acceptor (void);
  virtual ~JAWS_IO_Acceptor (void);

  virtual int open (const ACE_INET_Addr &address, int backlog = 20);
  // Initiate a passive mode socket.

  virtual int open (const ACE_HANDLE &socket);
  // Initiate a passive mode socket.

  virtual int accept (ACE_SOCK_Stream &new_stream,
                      ACE_Addr *remote_addr = 0,
                      ACE_Time_Value *timeout = 0,
                      int restart = 1,
                      int reset_new_handle = 0) const;
  // Synchronously accept the connection

  virtual int accept (size_t bytes_to_read = 0, const void *act = 0);
  // This initiates a new asynchronous accept through the AcceptEx call.

  virtual ACE_HANDLE get_handle (void);
  // Get the listener's handle

  virtual void close (void);
  // Close the acceptor.

  enum { ASYNC = 0, SYNCH = 1 };
  // identify if this is being used for asynchronous or synchronous
  // accept calls

};

class JAWS_Export JAWS_IO_Synch_Acceptor : public JAWS_IO_Acceptor
{
public:

  virtual int open (const ACE_INET_Addr &local_sap, int backlog = 20);
  // Initiate a passive mode socket.

  virtual int open (const ACE_HANDLE &socket);
  // Initiate a passive mode socket.

  virtual int accept (ACE_SOCK_Stream &new_stream,
                      ACE_Addr *remote_addr = 0,
                      ACE_Time_Value *timeout = 0,
                      int restart = 1,
                      int reset_new_handle = 0) const;
  // Accept the connection

  virtual ACE_HANDLE get_handle (void);
  // Get the listener's handle

private:
  virtual int accept (size_t bytes_to_read = 0, const void *act = 0);

private:
  JAWS_IO_SOCK_Acceptor acceptor_;
};


class JAWS_Export JAWS_IO_Asynch_Acceptor : public JAWS_IO_Acceptor
{
public:

  JAWS_IO_Asynch_Acceptor (void);
  virtual ~JAWS_IO_Asynch_Acceptor (void);

  virtual int open (const ACE_INET_Addr &address, int backlog = 20);
  // Initiate an asynchronous passive connection

  virtual int open (const ACE_HANDLE &socket);
  // Initiate an asynchronous passive connection

  virtual int accept (size_t bytes_to_read = 0, const void *act = 0);
  // This initiates a new asynchronous accept through the AcceptEx call.

  virtual ACE_HANDLE get_handle (void);
  // Get the listener's handle

  virtual void close (void);

private:

  virtual int accept (ACE_SOCK_Stream &new_stream,
                      ACE_Addr *remote_addr = 0,
                      ACE_Time_Value *timeout = 0,
                      int restart = 1,
                      int reset_new_handle = 0) const;

private:
#if defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS)
  ACE_Asynch_Acceptor<JAWS_Asynch_Handler> &acceptor_;
  ACE_Asynch_Acceptor<JAWS_Asynch_Handler> *acceptor_ptr_;
  ACE_HANDLE handle_;
#endif /* defined (ACE_WIN32) */
};

typedef ACE_Singleton<JAWS_IO_Synch_Acceptor, ACE_SYNCH_MUTEX>
        JAWS_IO_Synch_Acceptor_Singleton;

typedef ACE_Singleton<JAWS_IO_Asynch_Acceptor, ACE_SYNCH_MUTEX>
        JAWS_IO_Asynch_Acceptor_Singleton;

#endif /* !defined (JAWS_IO_ACCEPTOR_H) */