]> git.sur5r.net Git - openldap/commitdiff
preemptive time limit check in proxy backends
authorPierangelo Masarati <ando@openldap.org>
Mon, 13 Jun 2005 19:14:40 +0000 (19:14 +0000)
committerPierangelo Masarati <ando@openldap.org>
Mon, 13 Jun 2005 19:14:40 +0000 (19:14 +0000)
servers/slapd/back-ldap/search.c
servers/slapd/back-meta/search.c

index 3a16c4d8185125c55d23f5a84d140a7bb80a0091..19bddf422ccb4528de93ce5742557e7c31a11429 100644 (file)
@@ -137,6 +137,7 @@ ldap_back_search(
 {
        struct ldapconn *lc;
        struct timeval  tv;
+       time_t          stoptime;
        LDAPMessage     *res,
                        *e;
        int             rc = 0,
@@ -171,6 +172,7 @@ ldap_back_search(
        if ( op->ors_tlimit != SLAP_NO_LIMIT ) {
                tv.tv_sec = op->ors_tlimit;
                tv.tv_usec = 0;
+               stoptime = op->o_time + op->ors_tlimit;
 
        } else {
                tv.tv_sec = 0;
@@ -260,9 +262,18 @@ fail:;
                        tv.tv_usec = 100000;
                        ldap_pvt_thread_yield();
 
+                       /* check time limit */
+                       if ( op->ors_tlimit != SLAP_NO_LIMIT
+                                       && slap_get_time() > stoptime )
+                       {
+                               ldap_abandon_ext( lc->lc_ld, msgid, NULL, NULL );
+                               rc = rs->sr_err = LDAP_TIMELIMIT_EXCEEDED;
+                               goto finish;
+                       }
+
                } else if ( rc == LDAP_RES_SEARCH_ENTRY ) {
-                       Entry           ent = {0};
-                       struct berval   bdn;
+                       Entry           ent = { 0 };
+                       struct berval   bdn = BER_BVNULL;
                        int             abort = 0;
 
                        do_retry = 0;
index fff12ab2159b27ec0bc361cb8424ab72bea74370..fe1e403a21cec4e0f88f6708afbc4f9926f567b8 100644 (file)
@@ -54,13 +54,13 @@ meta_back_search_start(
 )
 {
        metainfo_t      *mi = ( metainfo_t * )op->o_bd->be_private;
-       struct berval           realbase = op->o_req_dn;
-       int                     realscope = op->ors_scope;
-       ber_len_t               suffixlen = 0;
-       struct berval           mbase = BER_BVNULL; 
-       struct berval           mfilter = BER_BVNULL;
-       char                    **mapped_attrs = NULL;
-       int                     rc;
+       struct berval   realbase = op->o_req_dn;
+       int             realscope = op->ors_scope;
+       ber_len_t       suffixlen = 0;
+       struct berval   mbase = BER_BVNULL; 
+       struct berval   mfilter = BER_BVNULL;
+       char            **mapped_attrs = NULL;
+       int             rc;
 
        /* should we check return values? */
        if ( op->ors_deref != -1 ) {
@@ -228,18 +228,19 @@ done:;
 int
 meta_back_search( Operation *op, SlapReply *rs )
 {
-       metainfo_t              *mi = ( metainfo_t * )op->o_bd->be_private;
-       metaconn_t              *mc;
-       struct timeval          tv = { 0, 0 };
-       LDAPMessage             *res = NULL, *e;
-       int                     rc = 0, sres = LDAP_SUCCESS;
-       char                    *matched = NULL;
-       int                     i, last = 0, ncandidates = 0,
-                               initial_candidates = 0, candidate_match = 0;
-       dncookie                dc;
-       int                     is_ok = 0;
-       void                    *savepriv;
-       SlapReply               *candidates = meta_back_candidates_get( op );
+       metainfo_t      *mi = ( metainfo_t * )op->o_bd->be_private;
+       metaconn_t      *mc;
+       struct timeval  tv = { 0, 0 };
+       time_t          stoptime;
+       LDAPMessage     *res = NULL, *e;
+       int             rc = 0, sres = LDAP_SUCCESS;
+       char            *matched = NULL;
+       int             i, last = 0, ncandidates = 0,
+                       initial_candidates = 0, candidate_match = 0;
+       dncookie        dc;
+       int             is_ok = 0;
+       void            *savepriv;
+       SlapReply       *candidates = meta_back_candidates_get( op );
 
        /*
         * controls are set in ldap_back_dobind()
@@ -321,6 +322,11 @@ meta_back_search( Operation *op, SlapReply *rs )
         * but this is necessary for version matching, and for ACL processing.
         */
 
+       if ( op->ors_tlimit != SLAP_NO_LIMIT ) {
+               stoptime = op->o_time + op->ors_tlimit;
+               tv.tv_sec = 0;
+       }
+
        /*
         * In case there are no candidates, no cycle takes place...
         *
@@ -358,6 +364,19 @@ meta_back_search( Operation *op, SlapReply *rs )
                                /* FIXME: res should not need to be freed */
                                assert( res == NULL );
 
+                               /* check time limit */
+                               if ( op->ors_tlimit != SLAP_NO_LIMIT
+                                               && slap_get_time() > stoptime )
+                               {
+                                       doabandon = 1;
+                                       rc = rs->sr_err = LDAP_TIMELIMIT_EXCEEDED;
+                                       savepriv = op->o_private;
+                                       op->o_private = (void *)i;
+                                       send_ldap_result( op, rs );
+                                       op->o_private = savepriv;
+                                       goto finish;
+                               }
+
                                continue;
 
                        } else if ( rc == -1 ) {