summaryrefslogtreecommitdiff
path: root/reentr.c
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2002-03-17 18:39:22 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2002-03-17 18:39:22 +0000
commitedd309b7facc349294ca0ee12a41c07bb525e567 (patch)
treead42446abdab6bba10810e31c14e4feba7c65a18 /reentr.c
parentf272994b1ce9066a01ab0ed3d6c5353b37057838 (diff)
downloadperl-edd309b7facc349294ca0ee12a41c07bb525e567.tar.gz
Implement the retry-on-ERANGE for the get*_r().
The buffer will keep doubling until 64k. p4raw-id: //depot/perl@15272
Diffstat (limited to 'reentr.c')
-rw-r--r--reentr.c188
1 files changed, 186 insertions, 2 deletions
diff --git a/reentr.c b/reentr.c
index a054c06303..76098a9faf 100644
--- a/reentr.c
+++ b/reentr.c
@@ -42,7 +42,7 @@ Perl_reentrant_size(pTHX) {
# ifdef __sgi
PL_reentrant_buffer->_getgrent_size = BUFSIZ;
# else
- PL_reentrant_buffer->_getgrent_size = 2048;
+ PL_reentrant_buffer->_getgrent_size = 256;
# endif
# endif
# endif
@@ -75,7 +75,7 @@ Perl_reentrant_size(pTHX) {
# ifdef __sgi
PL_reentrant_buffer->_getpwent_size = BUFSIZ;
# else
- PL_reentrant_buffer->_getpwent_size = 2048;
+ PL_reentrant_buffer->_getpwent_size = 256;
# endif
# endif
# endif
@@ -269,3 +269,187 @@ Perl_reentrant_free(pTHX) {
#endif /* USE_REENTRANT_API */
}
+void*
+Perl_reentrant_retry(const char *f, ...)
+{
+ dTHX;
+ void *retptr = NULL;
+#ifdef USE_REENTRANT_API
+ void *p0, *p1;
+ size_t asize;
+ int anint;
+ va_list ap;
+
+ va_start(ap, f);
+
+#define REENTRANTHALFMAXSIZE 32768 /* The maximum may end up twice this. */
+
+ switch (PL_op->op_type) {
+#ifdef USE_GETHOSTENT_BUFFER
+ case OP_GHBYADDR:
+ case OP_GHBYNAME:
+ case OP_GHOSTENT:
+ {
+ if (PL_reentrant_buffer->_gethostent_size <= REENTRANTHALFMAXSIZE) {
+ PL_reentrant_buffer->_gethostent_size *= 2;
+ Renew(PL_reentrant_buffer->_gethostent_buffer,
+ PL_reentrant_buffer->_gethostent_size, char);
+ switch (PL_op->op_type) {
+ case OP_GHBYADDR:
+ p0 = va_arg(ap, void *);
+ asize = va_arg(ap, size_t);
+ anint = va_arg(ap, int);
+ retptr = gethostbyaddr(p0, asize, anint); break;
+ case OP_GHBYNAME:
+ p0 = va_arg(ap, void *);
+ retptr = gethostbyname(p0); break;
+ case OP_GHOSTENT:
+ retptr = gethostent(); break;
+ default:
+ break;
+ }
+ }
+ }
+ break;
+#endif
+#ifdef USE_GETGRENT_BUFFER
+ case OP_GGRNAM:
+ case OP_GGRGID:
+ case OP_GGRENT:
+ {
+ if (PL_reentrant_buffer->_getgrent_size <= REENTRANTHALFMAXSIZE) {
+ Gid_t gid;
+ PL_reentrant_buffer->_getgrent_size *= 2;
+ Renew(PL_reentrant_buffer->_getgrent_buffer,
+ PL_reentrant_buffer->_getgrent_size, char);
+ switch (PL_op->op_type) {
+ case OP_GGRNAM:
+ p0 = va_arg(ap, void *);
+ retptr = getgrnam(p0); break;
+ case OP_GGRGID:
+ gid = va_arg(ap, Gid_t);
+ retptr = getgrgid(gid); break;
+ case OP_GGRENT:
+ retptr = getgrent(); break;
+ default:
+ break;
+ }
+ }
+ }
+ break;
+#endif
+#ifdef USE_GETNETENT_BUFFER
+ case OP_GNBYADDR:
+ case OP_GNBYNAME:
+ case OP_GNETENT:
+ {
+ if (PL_reentrant_buffer->_getnetent_size <= REENTRANTHALFMAXSIZE) {
+ Netdb_net_t net;
+ PL_reentrant_buffer->_getnetent_size *= 2;
+ Renew(PL_reentrant_buffer->_getnetent_buffer,
+ PL_reentrant_buffer->_getnetent_size, char);
+ switch (PL_op->op_type) {
+ case OP_GNBYADDR:
+ net = va_arg(ap, Netdb_net_t);
+ anint = va_arg(ap, int);
+ retptr = getnetbyaddr(net, anint); break;
+ case OP_GNBYNAME:
+ p0 = va_arg(ap, void *);
+ retptr = getnetbyname(p0); break;
+ case OP_GNETENT:
+ retptr = getnetent(); break;
+ default:
+ break;
+ }
+ }
+ }
+ break;
+#endif
+#ifdef USE_GETPWENT_BUFFER
+ case OP_GPWNAM:
+ case OP_GPWUID:
+ case OP_GPWENT:
+ {
+ if (PL_reentrant_buffer->_getpwent_size <= REENTRANTHALFMAXSIZE) {
+ Uid_t uid;
+ PL_reentrant_buffer->_getpwent_size *= 2;
+ Renew(PL_reentrant_buffer->_getpwent_buffer,
+ PL_reentrant_buffer->_getpwent_size, char);
+ switch (PL_op->op_type) {
+ case OP_GPWNAM:
+ p0 = va_arg(ap, void *);
+ retptr = getpwnam(p0); break;
+ case OP_GPWUID:
+ uid = va_arg(ap, Uid_t);
+ retptr = getpwuid(uid); break;
+ case OP_GPWENT:
+ retptr = getpwent(); break;
+ default:
+ break;
+ }
+ }
+ }
+ break;
+#endif
+#ifdef USE_GETPROTOENT_BUFFER
+ case OP_GPBYNAME:
+ case OP_GPBYNUMBER:
+ case OP_GPROTOENT:
+ {
+ if (PL_reentrant_buffer->_getprotoent_size <= REENTRANTHALFMAXSIZE) {
+ PL_reentrant_buffer->_getprotoent_size *= 2;
+ Renew(PL_reentrant_buffer->_getprotoent_buffer,
+ PL_reentrant_buffer->_getprotoent_size, char);
+ switch (PL_op->op_type) {
+ case OP_GPBYNAME:
+ p0 = va_arg(ap, void *);
+ retptr = getprotobyname(p0); break;
+ case OP_GPBYNUMBER:
+ anint = va_arg(ap, int);
+ retptr = getprotobynumber(anint); break;
+ case OP_GPROTOENT:
+ retptr = getprotoent(); break;
+ default:
+ break;
+ }
+ }
+ }
+ break;
+#endif
+#ifdef USE_GETSERVENT_BUFFER
+ case OP_GSBYNAME:
+ case OP_GSBYPORT:
+ case OP_GSERVENT:
+ {
+ if (PL_reentrant_buffer->_getservent_size <= REENTRANTHALFMAXSIZE) {
+ PL_reentrant_buffer->_getservent_size *= 2;
+ Renew(PL_reentrant_buffer->_getservent_buffer,
+ PL_reentrant_buffer->_getservent_size, char);
+ switch (PL_op->op_type) {
+ case OP_GSBYNAME:
+ p0 = va_arg(ap, void *);
+ p1 = va_arg(ap, void *);
+ retptr = getservbyname(p0, p1); break;
+ case OP_GSBYPORT:
+ anint = va_arg(ap, int);
+ p0 = va_arg(ap, void *);
+ retptr = getservbyport(anint, p0); break;
+ case OP_GSERVENT:
+ retptr = getservent(); break;
+ default:
+ break;
+ }
+ }
+ }
+ break;
+#endif
+ default:
+ /* Not known how to retry, so just fail. */
+ break;
+ }
+
+ va_end(ap);
+#endif
+ return retptr;
+}
+