The current code is pretty ineffective. Since select() only tells you that at
least 1 byte is available, you still need to do a read to determine how many
bytes are actually there. Given that the descriptor is already open
non-blocking, this would probably be better:
--- rand_unix.c.O Thu Nov 28 00:08:40 2002
+++ rand_unix.c Wed Apr 2 01:15:22 2003
@@ -164,33 +164,25 @@
int r;
fd_set fset;
- do
+ r=read(fd,(unsigned char *)tmpbuf+n,
+ ENTROPY_NEEDED-n);
+ if (r > 0)
+ n += r;
+ if (n < ENTROPY_NEEDED)
{
FD_ZERO(&fset);
FD_SET(fd, &fset);
r = -1;
- if (select(fd+1,&fset,NULL,NULL,&t) < 0)
- t.tv_usec=0;
- else if (FD_ISSET(fd, &fset))
+ if (select(fd+1,&fset,NULL,NULL,&t) == 1)
{
r=read(fd,(unsigned char *)tmpbuf+n,
ENTROPY_NEEDED-n);
if (r > 0)
n += r;
- }
- /* Some Unixen will update t, some
- won't. For those who won't, give
- up here, otherwise, we will do
- this once again for the remaining
- time. */
- if (t.tv_usec == 10*1000)
- t.tv_usec=0;
+ }
}
- while ((r > 0 || (errno == EINTR || errno == EAGAIN))
- && t.tv_usec != 0 && n < ENTROPY_NEEDED);
-
close(fd);
}
}
I removed the loop; I doubt another one or two milliseconds will make any
difference if it fails to fulfill the original read requests.
-- Howard Chu
Chief Architect, Symas Corp. Director, Highland Sun
http://www.symas.com http://highlandsun.com/hyc
Symas: Premier OpenSource Development and Support
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]