LCOV - code coverage report
Current view: top level - core/transport/chttp2 - incoming_metadata.c (source / functions) Hit Total Coverage
Test: tmp.CaZ6RjdVn2 Lines: 36 36 100.0 %
Date: 2015-12-10 22:15:08 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  * Copyright 2015, Google Inc.
       4             :  * All rights reserved.
       5             :  *
       6             :  * Redistribution and use in source and binary forms, with or without
       7             :  * modification, are permitted provided that the following conditions are
       8             :  * met:
       9             :  *
      10             :  *     * Redistributions of source code must retain the above copyright
      11             :  * notice, this list of conditions and the following disclaimer.
      12             :  *     * Redistributions in binary form must reproduce the above
      13             :  * copyright notice, this list of conditions and the following disclaimer
      14             :  * in the documentation and/or other materials provided with the
      15             :  * distribution.
      16             :  *     * Neither the name of Google Inc. nor the names of its
      17             :  * contributors may be used to endorse or promote products derived from
      18             :  * this software without specific prior written permission.
      19             :  *
      20             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
      21             :  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      22             :  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
      23             :  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
      24             :  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      25             :  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
      26             :  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      27             :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      28             :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      29             :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
      30             :  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      31             :  *
      32             :  */
      33             : 
      34             : #include "src/core/transport/chttp2/incoming_metadata.h"
      35             : 
      36             : #include <string.h>
      37             : 
      38             : #include "src/core/transport/chttp2/internal.h"
      39             : 
      40             : #include <grpc/support/alloc.h>
      41             : #include <grpc/support/log.h>
      42             : 
      43    17741362 : void grpc_chttp2_incoming_metadata_buffer_init(
      44             :     grpc_chttp2_incoming_metadata_buffer *buffer) {
      45    17741362 :   buffer->deadline = gpr_inf_future(GPR_CLOCK_REALTIME);
      46    17755713 : }
      47             : 
      48    17726438 : void grpc_chttp2_incoming_metadata_buffer_destroy(
      49             :     grpc_chttp2_incoming_metadata_buffer *buffer) {
      50             :   size_t i;
      51    17726438 :   if (!buffer->published) {
      52     8876135 :     for (i = 0; i < buffer->count; i++) {
      53         205 :       GRPC_MDELEM_UNREF(buffer->elems[i].md);
      54             :     }
      55             :   }
      56    17726438 :   gpr_free(buffer->elems);
      57    17738418 : }
      58             : 
      59    32814183 : void grpc_chttp2_incoming_metadata_buffer_add(
      60             :     grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem *elem) {
      61    32814183 :   GPR_ASSERT(!buffer->published);
      62    32814183 :   if (buffer->capacity == buffer->count) {
      63     8880377 :     buffer->capacity = GPR_MAX(8, 2 * buffer->capacity);
      64     8883409 :     buffer->elems =
      65     8880377 :         gpr_realloc(buffer->elems, sizeof(*buffer->elems) * buffer->capacity);
      66             :   }
      67    32817215 :   buffer->elems[buffer->count++].md = elem;
      68    32817215 : }
      69             : 
      70     1047992 : void grpc_chttp2_incoming_metadata_buffer_set_deadline(
      71             :     grpc_chttp2_incoming_metadata_buffer *buffer, gpr_timespec deadline) {
      72     1047992 :   GPR_ASSERT(!buffer->published);
      73     1047992 :   buffer->deadline = deadline;
      74     1047992 : }
      75             : 
      76     8878123 : void grpc_chttp2_incoming_metadata_buffer_publish(
      77             :     grpc_chttp2_incoming_metadata_buffer *buffer, grpc_metadata_batch *batch) {
      78     8878123 :   GPR_ASSERT(!buffer->published);
      79     8878123 :   buffer->published = 1;
      80     8878123 :   if (buffer->count > 0) {
      81             :     size_t i;
      82    32877423 :     for (i = 1; i < buffer->count; i++) {
      83    26169813 :       buffer->elems[i].prev = &buffer->elems[i - 1];
      84             :     }
      85    32872085 :     for (i = 0; i < buffer->count - 1; i++) {
      86    26164212 :       buffer->elems[i].next = &buffer->elems[i + 1];
      87             :     }
      88     6707873 :     buffer->elems[0].prev = NULL;
      89     6707873 :     buffer->elems[buffer->count - 1].next = NULL;
      90     6707873 :     batch->list.head = &buffer->elems[0];
      91     6707873 :     batch->list.tail = &buffer->elems[buffer->count - 1];
      92             :   } else {
      93     2170250 :     batch->list.head = batch->list.tail = NULL;
      94             :   }
      95     8878123 :   batch->deadline = buffer->deadline;
      96     8878123 : }

Generated by: LCOV version 1.11