Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenpoll.c
Go to the documentation of this file.
00001 /* 00002 * poll.c 00003 * - wrappers for poll(2) 00004 */ 00005 /* 00006 * This file is 00007 * Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk> 00008 * 00009 * It is part of adns, which is 00010 * Copyright (C) 1997-2000 Ian Jackson <ian@davenant.greenend.org.uk> 00011 * Copyright (C) 1999-2000 Tony Finch <dot@dotat.at> 00012 * 00013 * This program is free software; you can redistribute it and/or modify 00014 * it under the terms of the GNU General Public License as published by 00015 * the Free Software Foundation; either version 2, or (at your option) 00016 * any later version. 00017 * 00018 * This program is distributed in the hope that it will be useful, 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 * GNU General Public License for more details. 00022 * 00023 * You should have received a copy of the GNU General Public License 00024 * along with this program; if not, write to the Free Software Foundation, 00025 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00026 */ 00027 00028 #include <limits.h> 00029 #include <string.h> 00030 00031 #include "internal.h" 00032 00033 #ifdef HAVE_POLL 00034 00035 int adns_beforepoll(adns_state ads, struct pollfd *fds, int *nfds_io, int *timeout_io, 00036 const struct timeval *now) { 00037 struct timeval tv_nowbuf, tv_tobuf, *tv_to; 00038 int space, found, timeout_ms, r; 00039 struct pollfd fds_tmp[MAX_POLLFDS]; 00040 00041 adns__consistency(ads,0,cc_entex); 00042 00043 if (timeout_io) { 00044 adns__must_gettimeofday(ads,&now,&tv_nowbuf); 00045 if (!now) { *nfds_io= 0; r= 0; goto xit; } 00046 00047 timeout_ms= *timeout_io; 00048 if (timeout_ms == -1) { 00049 tv_to= 0; 00050 } else { 00051 tv_tobuf.tv_sec= timeout_ms / 1000; 00052 tv_tobuf.tv_usec= (timeout_ms % 1000)*1000; 00053 tv_to= &tv_tobuf; 00054 } 00055 00056 adns__timeouts(ads, 0, &tv_to,&tv_tobuf, *now); 00057 00058 if (tv_to) { 00059 assert(tv_to == &tv_tobuf); 00060 timeout_ms= (tv_tobuf.tv_usec+999)/1000; 00061 assert(tv_tobuf.tv_sec < (INT_MAX-timeout_ms)/1000); 00062 timeout_ms += tv_tobuf.tv_sec*1000; 00063 } else { 00064 timeout_ms= -1; 00065 } 00066 *timeout_io= timeout_ms; 00067 } 00068 00069 space= *nfds_io; 00070 if (space >= MAX_POLLFDS) { 00071 found= adns__pollfds(ads,fds); 00072 *nfds_io= found; 00073 } else { 00074 found= adns__pollfds(ads,fds_tmp); 00075 *nfds_io= found; 00076 if (space < found) { r= ERANGE; goto xit; } 00077 memcpy(fds,fds_tmp,sizeof(struct pollfd)*found); 00078 } 00079 r= 0; 00080 xit: 00081 adns__consistency(ads,0,cc_entex); 00082 return r; 00083 } 00084 00085 void adns_afterpoll(adns_state ads, const struct pollfd *fds, int nfds, 00086 const struct timeval *now) { 00087 struct timeval tv_buf; 00088 00089 adns__consistency(ads,0,cc_entex); 00090 adns__must_gettimeofday(ads,&now,&tv_buf); 00091 if (now) { 00092 adns__timeouts(ads, 1, 0,0, *now); 00093 adns__fdevents(ads, fds,nfds, 0,0,0,0, *now,0); 00094 } 00095 adns__consistency(ads,0,cc_entex); 00096 } 00097 00098 int adns_wait_poll(adns_state ads, 00099 adns_query *query_io, 00100 adns_answer **answer_r, 00101 void **context_r) { 00102 int r, nfds, to; 00103 struct pollfd fds[MAX_POLLFDS]; 00104 00105 adns__consistency(ads,0,cc_entex); 00106 00107 for (;;) { 00108 r= adns__internal_check(ads,query_io,answer_r,context_r); 00109 if (r != EAGAIN) goto xit; 00110 nfds= MAX_POLLFDS; to= -1; 00111 adns_beforepoll(ads,fds,&nfds,&to,0); 00112 r= poll(fds,nfds,to); 00113 if (r == -1) { 00114 if (errno == EINTR) { 00115 if (ads->iflags & adns_if_eintr) { r= EINTR; goto xit; } 00116 } else { 00117 adns__diag(ads,-1,0,"poll failed in wait: %s",strerror(errno)); 00118 adns_globalsystemfailure(ads); 00119 } 00120 } else { 00121 assert(r >= 0); 00122 adns_afterpoll(ads,fds,nfds,0); 00123 } 00124 } 00125 00126 xit: 00127 adns__consistency(ads,0,cc_entex); 00128 return r; 00129 } 00130 00131 #endif Generated on Fri May 25 2012 04:31:58 for ReactOS by
1.7.6.1
|