LCOV - code coverage report
Current view: top level - lib/util - select.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 13 22 59.1 %
Date: 2024-04-21 15:09:00 Functions: 1 1 100.0 %

          Line data    Source code
       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 "replace.h"
      22             : #include "system/filesys.h"
      23             : #include "system/select.h"
      24             : #include "lib/util/select.h"
      25             : #include "lib/util/time.h"
      26             : 
      27      619856 : int sys_poll_intr(struct pollfd *fds, int num_fds, int timeout)
      28             : {
      29      619856 :         int orig_timeout = timeout;
      30      397815 :         struct timespec start;
      31      397815 :         int ret;
      32             : 
      33      619856 :         clock_gettime_mono(&start);
      34             : 
      35      397815 :         while (true) {
      36      397815 :                 struct timespec now;
      37      397815 :                 int64_t elapsed;
      38             : 
      39      619856 :                 ret = poll(fds, num_fds, timeout);
      40      619856 :                 if (ret != -1) {
      41      222041 :                         break;
      42             :                 }
      43           0 :                 if (errno != EINTR) {
      44           0 :                         break;
      45             :                 }
      46             :                 /* Infinite timeout, no need to adjust. */
      47           0 :                 if (timeout < 0) {
      48           0 :                         continue;
      49             :                 }
      50           0 :                 clock_gettime_mono(&now);
      51           0 :                 elapsed = nsec_time_diff(&now, &start) / 1000000;
      52           0 :                 timeout = orig_timeout - elapsed;
      53             :                 /* Unlikely, but might happen eg. when getting traced.
      54             :                  * Make sure we're not hanging in this case.
      55             :                  */
      56           0 :                 if (timeout < 0) {
      57           0 :                         timeout = 0;
      58             :                 }
      59      397815 :         };
      60      619856 :         return ret;
      61             : }

Generated by: LCOV version 1.14