lib/select.c

ソースコードを見る。

関数

void sys_select_signal (char c)
int sys_select (int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval)
int sys_select_intr (int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval)

変数

static pid_t initialised
static int select_pipe [2]
static VOLATILE unsigned pipe_written
static VOLATILE unsigned pipe_read


関数

void sys_select_signal ( char  c  ) 

select.c41 行で定義されています。

参照先 initialisedpipe_readpipe_writtenselect_pipe.

参照元 sig_cld()sig_hup()sig_term()sig_usr1()sigchld_handler()sighup_handler()signal_handler()sigusr2_handler()termination_handler().

00042 {
00043         if (!initialised) return;
00044 
00045         if (pipe_written > pipe_read+256) return;
00046 
00047         if (write(select_pipe[1], &c, 1) == 1) pipe_written++;
00048 }

int sys_select ( int  maxfd,
fd_set *  readfds,
fd_set *  writefds,
fd_set *  errorfds,
struct timeval *  tval 
)

select.c56 行で定義されています。

参照先 cerrnoinitialisedpipe_readselect_pipeset_blocking()smb_panic()sys_getpid().

参照元 listen_for_packets()open_sockets_smbd()receive_message_or_smb().

00057 {
00058         int ret, saved_errno;
00059         fd_set *readfds2, readfds_buf;
00060 
00061         if (initialised != sys_getpid()) {
00062                 pipe(select_pipe);
00063 
00064                 /*
00065                  * These next two lines seem to fix a bug with the Linux
00066                  * 2.0.x kernel (and probably other UNIXes as well) where
00067                  * the one byte read below can block even though the
00068                  * select returned that there is data in the pipe and
00069                  * the pipe_written variable was incremented. Thanks to
00070                  * HP for finding this one. JRA.
00071                  */
00072 
00073                 if(set_blocking(select_pipe[0],0)==-1)
00074                         smb_panic("select_pipe[0]: O_NONBLOCK failed.\n");
00075                 if(set_blocking(select_pipe[1],0)==-1)
00076                         smb_panic("select_pipe[1]: O_NONBLOCK failed.\n");
00077 
00078                 initialised = sys_getpid();
00079         }
00080 
00081         maxfd = MAX(select_pipe[0]+1, maxfd);
00082 
00083         /* If readfds is NULL we need to provide our own set. */
00084         if (readfds) {
00085                 readfds2 = readfds;
00086         } else {
00087                 readfds2 = &readfds_buf;
00088                 FD_ZERO(readfds2);
00089         }
00090         FD_SET(select_pipe[0], readfds2);
00091 
00092         errno = 0;
00093         ret = select(maxfd,readfds2,writefds,errorfds,tval);
00094 
00095         if (ret <= 0) {
00096                 FD_ZERO(readfds2);
00097                 if (writefds)
00098                         FD_ZERO(writefds);
00099                 if (errorfds)
00100                         FD_ZERO(errorfds);
00101         } else if (FD_ISSET(select_pipe[0], readfds2)) {
00102                 char c;
00103                 saved_errno = errno;
00104                 if (read(select_pipe[0], &c, 1) == 1) {
00105                         pipe_read++;
00106                         /* Mark Weaver <mark-clist@npsl.co.uk> pointed out a critical
00107                            fix to ensure we don't lose signals. We must always
00108                            return -1 when the select pipe is set, otherwise if another
00109                            fd is also ready (so ret == 2) then we used to eat the
00110                            byte in the pipe and lose the signal. JRA.
00111                         */
00112                         ret = -1;
00113 #if 0
00114                         /* JRA - we can use this to debug the signal messaging... */
00115                         DEBUG(0,("select got %u signal\n", (unsigned int)c));
00116 #endif
00117                         errno = EINTR;
00118                 } else {
00119                         FD_CLR(select_pipe[0], readfds2);
00120                         ret--;
00121                         errno = saved_errno;
00122                 }
00123         }
00124 
00125         return ret;
00126 }

int sys_select_intr ( int  maxfd,
fd_set *  readfds,
fd_set *  writefds,
fd_set *  errorfds,
struct timeval *  tval 
)

select.c133 行で定義されています。

参照先 errnoGetTimeOfDay()usec_time_diff().

参照元 filter_child()irix_oplock_msg_waiting()open_any_socket_out()read_data_until()read_socket_with_timeout()readline_callback()receive_packet()smb_msleep()smb_readline_replacement()start_filter().

00134 {
00135         int ret;
00136         fd_set *readfds2, readfds_buf, *writefds2, writefds_buf, *errorfds2, errorfds_buf;
00137         struct timeval tval2, *ptval, end_time;
00138 
00139         readfds2 = (readfds ? &readfds_buf : NULL);
00140         writefds2 = (writefds ? &writefds_buf : NULL);
00141         errorfds2 = (errorfds ? &errorfds_buf : NULL);
00142         if (tval) {
00143                 GetTimeOfDay(&end_time);
00144                 end_time.tv_sec += tval->tv_sec;
00145                 end_time.tv_usec += tval->tv_usec;
00146                 end_time.tv_sec += end_time.tv_usec / 1000000;
00147                 end_time.tv_usec %= 1000000;
00148                 errno = 0;
00149                 tval2 = *tval;
00150                 ptval = &tval2;
00151         } else {
00152                 ptval = NULL;
00153         }
00154 
00155         do {
00156                 if (readfds)
00157                         readfds_buf = *readfds;
00158                 if (writefds)
00159                         writefds_buf = *writefds;
00160                 if (errorfds)
00161                         errorfds_buf = *errorfds;
00162                 if (ptval && (errno == EINTR)) {
00163                         struct timeval now_time;
00164                         SMB_BIG_INT tdif;
00165 
00166                         GetTimeOfDay(&now_time);
00167                         tdif = usec_time_diff(&end_time, &now_time);
00168                         if (tdif <= 0) {
00169                                 ret = 0; /* time expired. */
00170                                 break;
00171                         }
00172                         ptval->tv_sec = tdif / 1000000;
00173                         ptval->tv_usec = tdif % 1000000;
00174                 }
00175 
00176                 /* We must use select and not sys_select here. If we use
00177                    sys_select we'd lose the fact a signal occurred when sys_select
00178                    read a byte from the pipe. Fix from Mark Weaver
00179                    <mark-clist@npsl.co.uk>
00180                 */
00181                 ret = select(maxfd, readfds2, writefds2, errorfds2, ptval);
00182         } while (ret == -1 && errno == EINTR);
00183 
00184         if (readfds)
00185                 *readfds = readfds_buf;
00186         if (writefds)
00187                 *writefds = writefds_buf;
00188         if (errorfds)
00189                 *errorfds = errorfds_buf;
00190 
00191         return ret;
00192 }


変数

pid_t initialised [static]

select.c32 行で定義されています。

参照元 debug_init()lang_tdb_init()load_case_tables()lookup_byaddr_backend()lookup_byname_backend()map_to_os2_driver()map_username()nss_wins_init()py_samba_init()sys_select()sys_select_signal().

int select_pipe[2] [static]

select.c33 行で定義されています。

参照元 sys_select()sys_select_signal().

VOLATILE unsigned pipe_written [static]

select.c34 行で定義されています。

参照元 sys_select_signal().

VOLATILE unsigned pipe_read [static]

select.c34 行で定義されています。

参照元 sys_select()sys_select_signal().


Sambaに対してSat Aug 29 21:23:37 2009に生成されました。  doxygen 1.4.7