source: vendor/current/lib/util/select.c

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 1.5 KB
Line 
1/*
2 Unix SMB/Netbios implementation.
3 Version 3.0
4 Samba select/poll implementation
5 Copyright (C) Andrew Tridgell 1992-1998
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#include "includes.h"
22#include "system/filesys.h"
23#include "system/select.h"
24#include "lib/util/select.h"
25
26int sys_poll_intr(struct pollfd *fds, int num_fds, int timeout)
27{
28 int orig_timeout = timeout;
29 struct timespec start;
30 int ret;
31
32 clock_gettime_mono(&start);
33
34 while (true) {
35 struct timespec now;
36 int64_t elapsed;
37
38 ret = poll(fds, num_fds, timeout);
39 if (ret != -1) {
40 break;
41 }
42 if (errno != EINTR) {
43 break;
44 }
45 /* Infinite timeout, no need to adjust. */
46 if (timeout < 0) {
47 continue;
48 }
49 clock_gettime_mono(&now);
50 elapsed = nsec_time_diff(&now, &start) / 1000000;
51 timeout = orig_timeout - elapsed;
52 /* Unlikely, but might happen eg. when getting traced.
53 * Make sure we're not hanging in this case.
54 */
55 if (timeout < 0) {
56 timeout = 0;
57 }
58 };
59 return ret;
60}
Note: See TracBrowser for help on using the repository browser.