summaryrefslogtreecommitdiff
path: root/apps/JAWS2/JAWS/IO_Acceptor.cpp
blob: adb42fe16e078318c71e7eaa849ebc7e9494bf42 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// $Id$

#include "JAWS/Data_Block.h"
#include "JAWS/IO_Acceptor.h"

ACE_RCSID(JAWS, IO_Acceptor, "$Id$")

JAWS_IO_Acceptor::JAWS_IO_Acceptor (void)
{
}

JAWS_IO_Acceptor::~JAWS_IO_Acceptor (void)
{
}

int
JAWS_IO_Acceptor::open (const ACE_INET_Addr &, int)
{
  return -1;
}

int
JAWS_IO_Acceptor::open (const ACE_HANDLE &)
{
  return -1;
}

void
JAWS_IO_Acceptor::close (void)
{
}

int
JAWS_IO_Acceptor::accept (ACE_SOCK_Stream &, ACE_Addr *, ACE_Time_Value *,
                          int, int) const
{
  return -1;
}

int
JAWS_IO_Acceptor::accept (size_t, const void *)
{
  return -1;
}

ACE_HANDLE
JAWS_IO_Acceptor::get_handle (void)
{
  return ACE_INVALID_HANDLE;
}

int
JAWS_IO_Synch_Acceptor::open (const ACE_INET_Addr &local_sap, int backlog)
{
  return this->acceptor_.open (local_sap, 1, PF_INET, backlog);
}

int
JAWS_IO_Synch_Acceptor::open (const ACE_HANDLE &socket)
{
  ACE_HANDLE handle = this->acceptor_.get_handle ();
  if (handle == socket)
    return 0;

  if (handle != ACE_INVALID_HANDLE)
    ACE_OS::closesocket (this->acceptor_.get_handle ());
  this->acceptor_.set_handle (socket);

  return 0;
}

int
JAWS_IO_Synch_Acceptor::accept (ACE_SOCK_Stream &new_stream,
                                ACE_Addr *remote_addr,
                                ACE_Time_Value *timeout,
                                int restart,
                                int reset_new_handle) const
{
  return this->acceptor_.accept (new_stream, remote_addr, timeout,
                                 restart, reset_new_handle);
}

int
JAWS_IO_Synch_Acceptor::accept (size_t, const void *)
{
  return -1;
}

ACE_HANDLE
JAWS_IO_Synch_Acceptor::get_handle (void)
{
  return this->acceptor_.get_handle ();
}



JAWS_IO_Asynch_Acceptor::JAWS_IO_Asynch_Acceptor (void)
#if defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS)
  : acceptor_ (*(new ACE_Asynch_Acceptor<JAWS_Asynch_Handler>)),
    acceptor_ptr_ (&acceptor_)
#endif
{
}

JAWS_IO_Asynch_Acceptor::~JAWS_IO_Asynch_Acceptor (void)
{
#if defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS)
  delete this->acceptor_ptr_;
  this->acceptor_ptr_ = 0;
#endif
}

int
JAWS_IO_Asynch_Acceptor::open (const ACE_INET_Addr &address, int backlog)
{
#if defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS)
  // Tell the acceptor to listen on this->port_, which sets up an
  // asynchronous I/O request to the OS.

  return this->acceptor_.open (address,
                               JAWS_Data_Block::JAWS_DATA_BLOCK_SIZE,
                               1,
                               backlog,
                               1,
                               0,
                               0,
                               0,
                               0);

#else
  ACE_UNUSED_ARG (address);
  return -1;
#endif /* defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS) */
}

int
JAWS_IO_Asynch_Acceptor::open (const ACE_HANDLE &socket)
{
#if defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS)
  ACE_HANDLE handle = this->handle_;
  if (handle == socket)
    return 0;

  if (handle != ACE_INVALID_HANDLE)
    ACE_OS::closesocket (handle);
  this->handle_ = socket;

  return 0;
#else
  ACE_UNUSED_ARG (socket);
  return -1;
#endif /* defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS) */
}

int
JAWS_IO_Asynch_Acceptor::accept (size_t bytes_to_read, const void *act)
{
#if defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS)
  return this->acceptor_.accept (bytes_to_read, act);
#else
  ACE_UNUSED_ARG (bytes_to_read);
  return -1;
#endif /* defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS) */
}

int
JAWS_IO_Asynch_Acceptor::accept (ACE_SOCK_Stream &, ACE_Addr *,
                                 ACE_Time_Value *, int, int) const
{
  return -1;
}

ACE_HANDLE
JAWS_IO_Asynch_Acceptor::get_handle (void)
{
#if defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS)
  return this->acceptor_.get_handle ();
#else
  return ACE_INVALID_HANDLE;
#endif /* defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS) */
}


void
JAWS_IO_Asynch_Acceptor::close (void)
{
#if defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS)
  delete this->acceptor_ptr_;
  this->acceptor_ptr_ = 0;
#endif /* defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS) */
}


#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
#if defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS)
template class ACE_Asynch_Acceptor<JAWS_Asynch_Handler>;
#endif /* defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS) */
template class ACE_Singleton<JAWS_IO_Asynch_Acceptor, ACE_SYNCH_MUTEX>;
template class ACE_Singleton<JAWS_IO_Synch_Acceptor, ACE_SYNCH_MUTEX>;
template class ACE_LOCK_SOCK_Acceptor<ACE_SYNCH_MUTEX>;
template class ACE_LOCK_SOCK_Acceptor<ACE_SYNCH_NULL_MUTEX>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#if defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS)
#pragma instantiate ACE_Asynch_Acceptor<JAWS_Asynch_Handler>
#pragma instantiate  ACE_Singleton<JAWS_IO_Asynch_Acceptor, ACE_SYNCH_MUTEX>
#endif /* defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS) */
#pragma instantiate  ACE_Singleton<JAWS_IO_Synch_Acceptor, ACE_SYNCH_MUTEX>
#pragma instantiate ACE_LOCK_SOCK_Acceptor<ACE_SYNCH_MUTEX>
#pragma instantiate ACE_LOCK_SOCK_Acceptor<ACE_SYNCH_NULL_MUTEX>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */