Unverified Commit 7b9bc96c authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

http2: several cleanups

- separate easy handle from connections better
- added asserts on a number of places
- added sanity check of pipelines for debug builds

Closes #2751
parent 73af7bcd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ CURLcode Curl_async_resolved(struct connectdata *conn,
  if(result)
    /* We're not allowed to return failure with memory left allocated
       in the connectdata struct, free those here */
    Curl_disconnect(conn->data, conn, FALSE); /* close the connection */
    Curl_disconnect(conn->data, conn, TRUE); /* close the connection */

  return result;
}
+8 −5
Original line number Diff line number Diff line
@@ -158,18 +158,20 @@ CURLcode Curl_http_setup_conn(struct connectdata *conn)
  /* allocate the HTTP-specific struct for the Curl_easy, only to survive
     during this request */
  struct HTTP *http;
  DEBUGASSERT(conn->data->req.protop == NULL);
  struct Curl_easy *data = conn->data;
  DEBUGASSERT(data->req.protop == NULL);

  http = calloc(1, sizeof(struct HTTP));
  if(!http)
    return CURLE_OUT_OF_MEMORY;

  Curl_mime_initpart(&http->form, conn->data);
  conn->data->req.protop = http;
  data->req.protop = http;

  if(!CONN_INUSE(conn))
    /* if not alredy multi-using, setup connection details */
    Curl_http2_setup_conn(conn);
  Curl_http2_setup_req(conn->data);

  Curl_http2_setup_req(data);
  return CURLE_OK;
}

@@ -1913,6 +1915,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
  }

  http = data->req.protop;
  DEBUGASSERT(http);

  if(!data->state.this_is_a_follow) {
    /* Free to avoid leaking memory on multiple requests*/
+7 −2
Original line number Diff line number Diff line
@@ -154,6 +154,11 @@ static void http2_stream_free(struct HTTP *http)
  }
}

/*
 * Disconnects *a* connection used for HTTP/2. It might be an old one from the
 * connection cache and not the "main" one. Don't touch the easy handle!
 */

static CURLcode http2_disconnect(struct connectdata *conn,
                                 bool dead_connection)
{
@@ -164,8 +169,6 @@ static CURLcode http2_disconnect(struct connectdata *conn,

  nghttp2_session_del(c->h2);
  Curl_safefree(c->inbuf);
  http2_stream_free(conn->data->req.protop);
  conn->data->state.drain = 0;

  H2BUGF(infof(conn->data, "HTTP/2 DISCONNECT done\n"));

@@ -520,6 +523,7 @@ static int push_promise(struct Curl_easy *data,
    if(rv) {
      /* denied, kill off the new handle again */
      http2_stream_free(newhandle->req.protop);
      newhandle->req.protop = NULL;
      (void)Curl_close(newhandle);
      goto fail;
    }
@@ -535,6 +539,7 @@ static int push_promise(struct Curl_easy *data,
    if(rc) {
      infof(data, "failed to add handle to multi\n");
      http2_stream_free(newhandle->req.protop);
      newhandle->req.protop = NULL;
      Curl_close(newhandle);
      rv = 1;
      goto fail;
+2 −2
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
 * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution. The terms
@@ -65,7 +65,7 @@ void Curl_http2_cleanup_dependencies(struct Curl_easy *data);
#define Curl_http2_request_upgrade(x,y) CURLE_UNSUPPORTED_PROTOCOL
#define Curl_http2_setup(x) CURLE_UNSUPPORTED_PROTOCOL
#define Curl_http2_switched(x,y,z) CURLE_UNSUPPORTED_PROTOCOL
#define Curl_http2_setup_conn(x)
#define Curl_http2_setup_conn(x) Curl_nop_stmt
#define Curl_http2_setup_req(x)
#define Curl_http2_init_state(x)
#define Curl_http2_init_userset(x)
+3 −3
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 2013, Linus Nielsen Feltzing, <linus@haxx.se>
 * Copyright (C) 2013 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
 * Copyright (C) 2013 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution. The terms
@@ -110,8 +110,8 @@ CURLcode Curl_add_handle_to_pipeline(struct Curl_easy *handle,
  pipeline = &conn->send_pipe;

  result = addHandleToPipeline(handle, pipeline);

  if(pipeline == &conn->send_pipe && sendhead != conn->send_pipe.head) {
  if((conn->bundle->multiuse == BUNDLE_PIPELINING) &&
     (pipeline == &conn->send_pipe && sendhead != conn->send_pipe.head)) {
    /* this is a new one as head, expire it */
    Curl_pipeline_leave_write(conn); /* not in use yet */
    Curl_expire(conn->send_pipe.head->ptr, 0, EXPIRE_RUN_NOW);
Loading