2 Unix SMB/Netbios implementation.
4 Samba select/poll implementation
5 Copyright (C) Andrew Tridgell 1992-1998
6 Copyright (C) Derrell Lipman 2003-2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * This file implements the two functions in the select() family, as required
27 * by samba. The samba native functions, though, implement a pipe to help
28 * alleviate a deadlock problem, but which creates problems of its own (the
29 * timeout stops working correctly). Those functions also require that all
30 * signal handlers call a function which writes to the pipe -- a task which is
31 * difficult to do in the smbwrapper environment.
35 #include <sys/select.h>
39 int sys_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval)
42 fd_set *readfds2, readfds_buf;
44 /* If readfds is NULL we need to provide our own set. */
48 readfds2 = &readfds_buf;
53 ret = select(maxfd,readfds2,writefds,errorfds,tval);
66 /*******************************************************************
67 Similar to sys_select() but catch EINTR and continue.
68 This is what sys_select() used to do in Samba.
69 ********************************************************************/
71 int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval)
74 fd_set *readfds2, readfds_buf, *writefds2, writefds_buf, *errorfds2, errorfds_buf;
75 struct timeval tval2, *ptval, end_time, now_time;
76 extern void GetTimeOfDay(struct timeval *tval);
78 readfds2 = (readfds ? &readfds_buf : NULL);
79 writefds2 = (writefds ? &writefds_buf : NULL);
80 errorfds2 = (errorfds ? &errorfds_buf : NULL);
82 GetTimeOfDay(&end_time);
83 end_time.tv_sec += tval->tv_sec;
84 end_time.tv_usec += tval->tv_usec;
85 end_time.tv_sec += end_time.tv_usec / 1000000;
86 end_time.tv_usec %= 1000000;
94 readfds_buf = *readfds;
96 writefds_buf = *writefds;
98 errorfds_buf = *errorfds;
100 GetTimeOfDay(&now_time);
101 tval2.tv_sec = end_time.tv_sec - now_time.tv_sec;
102 tval2.tv_usec = end_time.tv_usec - now_time.tv_usec;
103 if ((signed long) tval2.tv_usec < 0) {
104 tval2.tv_usec += 1000000;
107 if ((signed long) tval2.tv_sec < 0) {
109 break; /* time has already elapsed */
113 ret = sys_select(maxfd, readfds2, writefds2, errorfds2, ptval);
114 } while (ret == -1 && errno == EINTR);
117 *readfds = readfds_buf;
119 *writefds = writefds_buf;
121 *errorfds = errorfds_buf;