rpc_server3: Use fdopen_keepfd()
[Samba.git] / source3 / torture / test_pthreadpool_tevent.c
blobc90a3943a8b15d418486868244625ba5750a007d
1 /*
2 * Unix SMB/CIFS implementation.
3 * Test pthreadpool_tevent
4 * Copyright (C) Volker Lendecke 2016
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/>.
20 #include "includes.h"
21 #include "system/select.h"
22 #include "proto.h"
23 #include "lib/pthreadpool/pthreadpool_tevent.h"
25 static void job_fn(void *private_data);
27 bool run_pthreadpool_tevent(int dummy)
29 struct tevent_context *ev;
30 struct pthreadpool_tevent *pool;
31 struct tevent_req *req;
32 int ret, val;
33 bool ok;
35 ev = tevent_context_init_byname(NULL, "poll");
36 if (ev == NULL) {
37 fprintf(stderr, "tevent_context_init failed\n");
38 return false;
41 ret = pthreadpool_tevent_init(ev, 100, &pool);
42 if (ret != 0) {
43 fprintf(stderr, "pthreadpool_tevent_init failed: %s\n",
44 strerror(ret));
45 return false;
48 val = -1;
50 req = pthreadpool_tevent_job_send(ev, ev, pool, job_fn, &val);
51 if (req == NULL) {
52 fprintf(stderr, "pthreadpool_tevent_job_send failed\n");
53 return false;
56 ok = tevent_req_poll(req, ev);
57 if (!ok) {
58 fprintf(stderr, "tevent_req_poll failed\n");
59 return false;
62 ret = pthreadpool_tevent_job_recv(req);
63 if (ret != 0) {
64 fprintf(stderr, "pthreadpool_tevent_job failed: %s\n",
65 strerror(ret));
66 return false;
69 printf("%d\n", val);
71 TALLOC_FREE(pool);
72 TALLOC_FREE(ev);
73 return true;
76 static void job_fn(void *private_data)
78 int *pret = private_data;
79 *pret = 4711;
81 poll(NULL, 0, 100);