CURL: the cleanup has to be done before.
[citadel.git] / citadel / event_client.c
index fdd66d7ae6c17a1d47d066e5121c87b587c5cee3..78876b50271296bb19196de5033537dd70113412 100644 (file)
@@ -101,7 +101,8 @@ void SetEVState(AsyncIO *IO, eIOState State)
 {
 
        CitContext* CCC = IO->CitContext;
-       memcpy(CCC->lastcmdname, IOStates[State].Key, IOStates[State].len + 1);
+       if (CCC != NULL)
+               memcpy(CCC->lastcmdname, IOStates[State].Key, IOStates[State].len + 1);
 
 }
 
@@ -294,6 +295,17 @@ eNextState QueueEventContext(AsyncIO *IO, IO_CallBack CB)
        return eSendReply;
 }
 
+eNextState EventQueueDBOperation(AsyncIO *IO, IO_CallBack CB)
+{
+       StopClientWatchers(IO, 0);
+       return QueueDBOperation(IO, CB);
+}
+eNextState DBQueueEventContext(AsyncIO *IO, IO_CallBack CB)
+{
+       StopDBWatchers(IO);
+       return QueueEventContext(IO, CB);
+}
+
 extern eNextState evcurl_handle_start(AsyncIO *IO);
 
 eNextState QueueCurlContext(AsyncIO *IO)
@@ -333,6 +345,13 @@ eNextState QueueCurlContext(AsyncIO *IO)
        return eSendReply;
 }
 
+eNextState CurlQueueDBOperation(AsyncIO *IO, IO_CallBack CB)
+{
+       StopCurlWatchers(IO);
+       return QueueDBOperation(IO, CB);
+}
+
+
 void DestructCAres(AsyncIO *IO);
 void FreeAsyncIOContents(AsyncIO *IO)
 {
@@ -384,6 +403,9 @@ void StopCurlWatchers(AsyncIO *IO)
        ev_io_stop(event_base, &IO->send_event);
        ev_io_stop(event_base, &IO->recv_event);
 
+       curl_easy_cleanup(IO->HttpReq.chnd);
+       IO->HttpReq.chnd = NULL;
+
        if (IO->SendBuf.fd != 0) {
                close(IO->SendBuf.fd);
        }