If the connection is down, don't try another write.
authorVolker Lendecke <vl@samba.org>
Sun, 28 Jun 2009 13:29:38 +0000 (15:29 +0200)
committerVolker Lendecke <vl@samba.org>
Sun, 28 Jun 2009 13:51:02 +0000 (15:51 +0200)
source3/include/tldap.h
source3/lib/tldap.c

index 1d920f8adce0119e80d05cba4da373f7852eb151..cd502985698e2474025d9a70cd506da9bf4cf6af 100644 (file)
@@ -48,6 +48,7 @@ struct tldap_mod {
 bool tevent_req_is_ldap_error(struct tevent_req *req, int *perr);
 
 struct tldap_context *tldap_context_create(TALLOC_CTX *mem_ctx, int fd);
+bool tldap_connection_ok(struct tldap_context *ld);
 bool tldap_context_setattr(struct tldap_context *ld,
                           const char *name, const void *pptr);
 void *tldap_context_getattr(struct tldap_context *ld, const char *name);
index cbd9648007026e3e6fc15cfedd0817e07cbea0e2..451bc18d2e7eeb6593fda54565c03cc0002960ff 100644 (file)
@@ -55,6 +55,7 @@ struct tldap_context {
        int ld_sizelimit;
        int ld_timelimit;
        struct tstream_context *conn;
+       bool server_down;
        int msgid;
        struct tevent_queue *outgoing;
        struct tevent_req **pending;
@@ -153,6 +154,14 @@ struct tldap_context *tldap_context_create(TALLOC_CTX *mem_ctx, int fd)
        return ctx;
 }
 
+bool tldap_connection_ok(struct tldap_context *ld)
+{
+       if (ld == NULL) {
+               return false;
+       }
+       return !ld->server_down;
+}
+
 static struct tldap_ctx_attribute *tldap_context_findattr(
        struct tldap_context *ld, const char *name)
 {
@@ -395,6 +404,11 @@ static struct tevent_req *tldap_msg_send(TALLOC_CTX *mem_ctx,
        state->ev = ev;
        state->id = id;
 
+       if (state->ld->server_down) {
+               tevent_req_error(req, TLDAP_SERVER_DOWN);
+               return tevent_req_post(req, ev);
+       }
+
        tldap_push_controls(data, sctrls, num_sctrls);
 
        asn1_pop_tag(data);
@@ -507,12 +521,15 @@ static void tldap_msg_sent(struct tevent_req *subreq)
 {
        struct tevent_req *req = tevent_req_callback_data(
                subreq, struct tevent_req);
+       struct tldap_msg_state *state = tevent_req_data(
+               req, struct tldap_msg_state);
        ssize_t nwritten;
        int err;
 
        nwritten = tstream_writev_queue_recv(subreq, &err);
        TALLOC_FREE(subreq);
        if (nwritten == -1) {
+               state->ld->server_down = true;
                tevent_req_error(req, TLDAP_SERVER_DOWN);
                return;
        }