2 Unix SMB/CIFS implementation.
3 Infrastructure for async requests
4 Copyright (C) Volker Lendecke 2008
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 char *async_req_print(TALLOC_CTX
*mem_ctx
, struct async_req
*req
)
24 return talloc_asprintf(mem_ctx
, "async_req: state=%d, status=%s, "
25 "priv=%s", req
->state
, nt_errstr(req
->status
),
26 talloc_get_name(req
->private_data
));
29 struct async_req
*async_req_new(TALLOC_CTX
*mem_ctx
, struct event_context
*ev
)
31 struct async_req
*result
;
33 result
= TALLOC_ZERO_P(mem_ctx
, struct async_req
);
37 result
->state
= ASYNC_REQ_IN_PROGRESS
;
38 result
->event_ctx
= ev
;
39 result
->print
= async_req_print
;
43 void async_req_done(struct async_req
*req
)
45 req
->status
= NT_STATUS_OK
;
46 req
->state
= ASYNC_REQ_DONE
;
47 if (req
->async
.fn
!= NULL
) {
52 void async_req_error(struct async_req
*req
, NTSTATUS status
)
55 req
->state
= ASYNC_REQ_ERROR
;
56 if (req
->async
.fn
!= NULL
) {
61 static void async_trigger(struct event_context
*ev
, struct timed_event
*te
,
62 const struct timeval
*now
, void *priv
)
64 struct async_req
*req
= talloc_get_type_abort(priv
, struct async_req
);
67 if (NT_STATUS_IS_OK(req
->status
)) {
71 async_req_error(req
, req
->status
);
75 bool async_post_status(struct async_req
*req
, NTSTATUS status
)
78 * Used if a request is finished before it even started
83 if (event_add_timed(req
->event_ctx
, req
, timeval_zero(),
85 async_trigger
, req
) == NULL
) {
91 bool async_req_nomem(const void *p
, struct async_req
*req
)
96 async_req_error(req
, NT_STATUS_NO_MEMORY
);