summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>1998-08-28 21:46:29 +0000
committerJeremy Allison <jra@samba.org>1998-08-28 21:46:29 +0000
commit38142a1ebbe860778e26eaff68585726061c05e2 (patch)
tree0112dc0186d8088bab727ee8309c36986c9e72d4 /source3/lib
parentc077bce5c0f760dc918b0442346502ec96a92c1b (diff)
downloadsamba-38142a1ebbe860778e26eaff68585726061c05e2.tar.gz
samba-38142a1ebbe860778e26eaff68585726061c05e2.tar.bz2
samba-38142a1ebbe860778e26eaff68585726061c05e2.zip
This checking fixes the statcache bug that stopped NetBench from running
correctly. Added new parameter "stat cache size" - set to 50 by default. I now declare the statcache code officially "open" for business :-). It gets a hit rate of 97% with a NetBench run and seems to make using a case insensitive run as efficient as a case sensitive run. Also tidied up our sys_select usage - added a maxfd parameter and also added an implementation of select in terms of poll(), for systems where poll() is much faster. This is disabled by default. Jeremy. (This used to be commit 779b924ec1f6c81ff578d22295b20fece698d1fc)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/system.c70
-rw-r--r--source3/lib/util.c10
2 files changed, 57 insertions, 23 deletions
diff --git a/source3/lib/system.c b/source3/lib/system.c
index 255b1c7b49..d569b80a74 100644
--- a/source3/lib/system.c
+++ b/source3/lib/system.c
@@ -60,7 +60,7 @@ static int pollfd(int fd)
return(r);
}
-int sys_select(fd_set *fds,struct timeval *tval)
+int sys_select(int maxfd, fd_set *fds,struct timeval *tval)
{
fd_set fds2;
int counter=0;
@@ -69,41 +69,75 @@ int sys_select(fd_set *fds,struct timeval *tval)
FD_ZERO(&fds2);
while (1)
- {
- int i;
- for (i=0;i<255;i++) {
- if (FD_ISSET(i,fds) && pollfd(i)>0) {
- found++;
- FD_SET(i,&fds2);
- }
+ {
+ int i;
+ for (i=0;i<maxfd;i++) {
+ if (FD_ISSET(i,fds) && pollfd(i)>0) {
+ found++;
+ FD_SET(i,&fds2);
}
+ }
- if (found) {
- memcpy((void *)fds,(void *)&fds2,sizeof(fds2));
- return(found);
- }
+ if (found) {
+ memcpy((void *)fds,(void *)&fds2,sizeof(fds2));
+ return(found);
+ }
- if (tval && tval->tv_sec < counter) return(0);
+ if (tval && tval->tv_sec < counter) return(0);
sleep(1);
counter++;
- }
+ }
}
-#else
-int sys_select(fd_set *fds,struct timeval *tval)
+#else /* !NO_SELECT */
+int sys_select(int maxfd, fd_set *fds,struct timeval *tval)
{
+#ifdef USE_POLL
+ struct pollfd pfd[256];
+ int i;
+ int maxpoll;
+ int timeout;
+ int pollrtn;
+
+ maxpoll = 0;
+ for( i = 0; i < maxfd; i++) {
+ if(FD_ISSET(i,fds)) {
+ struct pollfd *pfdp = &pfd[maxpoll++];
+ pfdp->fd = i;
+ pfdp->events = POLLIN;
+ pfdp->revents = 0;
+ }
+ }
+
+ timeout = (tval != NULL) ? (tval->tv_sec * 1000) + (tval->tv_usec/1000) :
+ -1;
+ errno = 0;
+ do {
+ pollrtn = poll( &pfd[0], maxpoll, timeout);
+ } while (pollrtn<0 && errno == EINTR);
+
+ FD_ZERO(fds);
+
+ for( i = 0; i < maxpoll; i++)
+ if( pfd[i].revents & POLLIN )
+ FD_SET(pfd[i].fd,fds);
+
+ return pollrtn;
+#else /* USE_POLL */
+
struct timeval t2;
int selrtn;
do {
if (tval) memcpy((void *)&t2,(void *)tval,sizeof(t2));
errno = 0;
- selrtn = select(255,SELECT_CAST fds,NULL,NULL,tval?&t2:NULL);
+ selrtn = select(maxfd,SELECT_CAST fds,NULL,NULL,tval?&t2:NULL);
} while (selrtn<0 && errno == EINTR);
return(selrtn);
}
-#endif
+#endif /* USE_POLL */
+#endif /* NO_SELECT */
/*******************************************************************
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 4604836f77..414b54bd7c 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -1883,7 +1883,7 @@ int read_with_timeout(int fd,char *buf,int mincnt,int maxcnt,long time_out)
FD_ZERO(&fds);
FD_SET(fd,&fds);
- selrtn = sys_select(&fds,&timeout);
+ selrtn = sys_select(fd+1,&fds,&timeout);
/* Check if error */
if(selrtn == -1) {
@@ -1943,7 +1943,7 @@ int read_max_udp(int fd,char *buffer,int bufsize,int maxtime)
timeout.tv_sec = maxtime / 1000;
timeout.tv_usec = (maxtime % 1000) * 1000;
- selrtn = sys_select(&fds,maxtime>0?&timeout:NULL);
+ selrtn = sys_select(fd+1,&fds,maxtime>0?&timeout:NULL);
if (!FD_ISSET(fd,&fds))
return 0;
@@ -2269,7 +2269,7 @@ BOOL receive_local_message(int fd, char *buffer, int buffer_len, int timeout)
to.tv_sec = timeout / 1000;
to.tv_usec = (timeout % 1000) * 1000;
- selrtn = sys_select(&fds,&to);
+ selrtn = sys_select(fd+1,&fds,&to);
/* Check if error */
if(selrtn == -1)
@@ -2437,7 +2437,7 @@ BOOL receive_message_or_smb(int smbfd, int oplock_fd,
to.tv_sec = timeout / 1000;
to.tv_usec = (timeout % 1000) * 1000;
- selrtn = sys_select(&fds,timeout>0?&to:NULL);
+ selrtn = sys_select(MAX(smbfd,oplock_fd)+1,&fds,timeout>0?&to:NULL);
/* Check if error */
if(selrtn == -1) {
@@ -2601,7 +2601,7 @@ void msleep(int t)
FD_ZERO(&fds);
errno = 0;
- sys_select(&fds,&tval);
+ sys_select(0,&fds,&tval);
GetTimeOfDay(&t2);
tdiff = TvalDiff(&t1,&t2);