Line data Source code
1 : /*
2 : * Unix SMB/CIFS implementation.
3 : * Test pthreadpool_tevent
4 : * Copyright (C) Volker Lendecke 2016
5 : *
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.
10 : *
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.
15 : *
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/>.
18 : */
19 :
20 : #include "includes.h"
21 : #include "system/select.h"
22 : #include "proto.h"
23 : #include "lib/pthreadpool/pthreadpool_tevent.h"
24 :
25 : static void job_fn(void *private_data);
26 :
27 0 : bool run_pthreadpool_tevent(int dummy)
28 : {
29 : struct tevent_context *ev;
30 : struct pthreadpool_tevent *pool;
31 : struct tevent_req *req;
32 : int ret, val;
33 : bool ok;
34 :
35 0 : ev = tevent_context_init_byname(NULL, "poll");
36 0 : if (ev == NULL) {
37 0 : fprintf(stderr, "tevent_context_init failed\n");
38 0 : return false;
39 : }
40 :
41 0 : ret = pthreadpool_tevent_init(ev, 100, &pool);
42 0 : if (ret != 0) {
43 0 : fprintf(stderr, "pthreadpool_tevent_init failed: %s\n",
44 : strerror(ret));
45 0 : return false;
46 : }
47 :
48 0 : val = -1;
49 :
50 0 : req = pthreadpool_tevent_job_send(ev, ev, pool, job_fn, &val);
51 0 : if (req == NULL) {
52 0 : fprintf(stderr, "pthreadpool_tevent_job_send failed\n");
53 0 : return false;
54 : }
55 :
56 0 : ok = tevent_req_poll(req, ev);
57 0 : if (!ok) {
58 0 : fprintf(stderr, "tevent_req_poll failed\n");
59 0 : return false;
60 : }
61 :
62 0 : ret = pthreadpool_tevent_job_recv(req);
63 0 : if (ret != 0) {
64 0 : fprintf(stderr, "pthreadpool_tevent_job failed: %s\n",
65 : strerror(ret));
66 0 : return false;
67 : }
68 :
69 0 : printf("%d\n", val);
70 :
71 0 : TALLOC_FREE(pool);
72 0 : TALLOC_FREE(ev);
73 0 : return true;
74 : }
75 :
76 0 : static void job_fn(void *private_data)
77 : {
78 0 : int *pret = private_data;
79 0 : *pret = 4711;
80 :
81 0 : poll(NULL, 0, 100);
82 0 : }
|