3
A brief file description
5
@section license License
7
Licensed to the Apache Software Foundation (ASF) under one
8
or more contributor license agreements. See the NOTICE file
9
distributed with this work for additional information
10
regarding copyright ownership. The ASF licenses this file
11
to you under the Apache License, Version 2.0 (the
12
"License"); you may not use this file except in compliance
13
with the License. You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
17
Unless required by applicable law or agreed to in writing, software
18
distributed under the License is distributed on an "AS IS" BASIS,
19
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
See the License for the specific language governing permissions and
21
limitations under the License.
24
/****************************************************************************
29
****************************************************************************/
33
extern Continuation *aio_err_callbck;
36
extern uint64_t aio_num_read;
37
extern uint64_t aio_bytes_read;
38
extern uint64_t aio_num_write;
39
extern uint64_t aio_bytes_written;
41
NTIOCompletionPort aio_completion_port(1);
45
init_op_sequence(AIOCallback * op, int opcode)
48
// zero aio_result's and init opcodes
50
for (cur_op = op; cur_op; cur_op = cur_op->then) {
51
cur_op->aio_result = 0;
52
cur_op->aiocb.aio_lio_opcode = opcode;
53
// set the last op to point to the first op
54
if (cur_op->then == NULL)
55
((AIOCallbackInternal *) cur_op)->first = op;
60
cache_op(AIOCallback * op)
65
// make op continuation share op->action's mutex
66
op->mutex = op->action.mutex;
68
// construct a continuation to handle the io completion
69
NTCompletionEvent *ce = NTCompletionEvent_alloc(op);
70
OVERLAPPED *overlapped = ce->get_overlapped();
71
overlapped->Offset = (unsigned long) (op->aiocb.aio_offset & 0xFFFFFFFF);
72
overlapped->OffsetHigh = (unsigned long)
73
(op->aiocb.aio_offset >> 32) & 0xFFFFFFFF;
76
switch (op->aiocb.aio_lio_opcode) {
78
ret = ReadFile((HANDLE) op->aiocb.aio_fildes,
79
op->aiocb.aio_buf, (unsigned long) op->aiocb.aio_nbytes, &bytes_trans, overlapped);
82
ret = WriteFile((HANDLE) op->aiocb.aio_fildes,
83
op->aiocb.aio_buf, (unsigned long) op->aiocb.aio_nbytes, &bytes_trans, overlapped);
86
ink_debug_assert(!"unknown aio_lio_opcode");
88
DWORD lerror = GetLastError();
89
if (ret == FALSE && lerror != ERROR_IO_PENDING) {
91
op->aio_result = -((int) lerror);
92
eventProcessor.schedule_imm(op);
98
ink_aio_read(AIOCallback * op)
100
init_op_sequence(op, LIO_READ);
106
ink_aio_write(AIOCallback * op)
108
init_op_sequence(op, LIO_WRITE);
114
struct AIOMissEvent:Continuation
118
int mainEvent(int event, Event * e)
120
if (!cb->action.cancelled)
121
cb->action.continuation->handleEvent(AIO_EVENT_DONE, cb);
126
AIOMissEvent(ProxyMutex * amutex, AIOCallback * acb)
127
: Continuation(amutex), cb(acb)
129
SET_HANDLER(&AIOMissEvent::mainEvent);
134
AIOCallbackInternal::io_complete(int event, void *data)
138
NTCompletionEvent *ce = (NTCompletionEvent *) data;
140
// if aio_result is set, the original Read/Write call failed
143
aio_result = lerror ? -lerror : ce->_bytes_transferred;
146
if ((lerror != 0) && aio_err_callbck) {
147
// schedule aio_err_callbck to be called-back
148
// FIXME: optimization, please... ^_^
149
AIOCallback *op = NEW(new AIOCallbackInternal());
150
op->aiocb.aio_fildes = aiocb.aio_fildes;
151
op->action = aio_err_callbck;
152
eventProcessor.schedule_imm(NEW(new AIOMissEvent(op->action.mutex, op)));
154
ink_debug_assert(ce->_bytes_transferred == aiocb.aio_nbytes);
158
// more op's in this sequence
161
// we're done! callback action
162
if (!first->action.cancelled) {
163
first->action.continuation->handleEvent(AIO_EVENT_DONE, first);