LCOV - code coverage report
Current view: top level - src/core/transport - transport.c (source / functions) Hit Total Coverage
Test: tmp.zDYK9MVh93 Lines: 43 55 78.2 %
Date: 2015-10-10 Functions: 10 11 90.9 %

          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/transport.h"
      35             : #include <grpc/support/alloc.h>
      36             : #include <grpc/support/log.h>
      37             : #include "src/core/transport/transport_impl.h"
      38             : 
      39        4013 : size_t grpc_transport_stream_size(grpc_transport *transport) {
      40        4013 :   return transport->vtable->sizeof_stream;
      41             : }
      42             : 
      43        4014 : void grpc_transport_destroy(grpc_exec_ctx *exec_ctx,
      44             :                             grpc_transport *transport) {
      45        4014 :   transport->vtable->destroy(exec_ctx, transport);
      46        4014 : }
      47             : 
      48     2702552 : int grpc_transport_init_stream(grpc_exec_ctx *exec_ctx,
      49             :                                grpc_transport *transport, grpc_stream *stream,
      50             :                                const void *server_data,
      51             :                                grpc_transport_stream_op *initial_op) {
      52     2702552 :   return transport->vtable->init_stream(exec_ctx, transport, stream,
      53             :                                         server_data, initial_op);
      54             : }
      55             : 
      56     8233982 : void grpc_transport_perform_stream_op(grpc_exec_ctx *exec_ctx,
      57             :                                       grpc_transport *transport,
      58             :                                       grpc_stream *stream,
      59             :                                       grpc_transport_stream_op *op) {
      60     8233982 :   transport->vtable->perform_stream_op(exec_ctx, transport, stream, op);
      61     8251968 : }
      62             : 
      63       11124 : void grpc_transport_perform_op(grpc_exec_ctx *exec_ctx,
      64             :                                grpc_transport *transport,
      65             :                                grpc_transport_op *op) {
      66       11124 :   transport->vtable->perform_op(exec_ctx, transport, op);
      67       11128 : }
      68             : 
      69     2702056 : void grpc_transport_destroy_stream(grpc_exec_ctx *exec_ctx,
      70             :                                    grpc_transport *transport,
      71             :                                    grpc_stream *stream) {
      72     2702056 :   transport->vtable->destroy_stream(exec_ctx, transport, stream);
      73     2704176 : }
      74             : 
      75        1094 : char *grpc_transport_get_peer(grpc_exec_ctx *exec_ctx,
      76             :                               grpc_transport *transport) {
      77        1094 :   return transport->vtable->get_peer(exec_ctx, transport);
      78             : }
      79             : 
      80           0 : void grpc_transport_stream_op_finish_with_failure(
      81             :     grpc_exec_ctx *exec_ctx, grpc_transport_stream_op *op) {
      82           0 :   grpc_exec_ctx_enqueue(exec_ctx, op->on_done_recv, 0);
      83           0 :   grpc_exec_ctx_enqueue(exec_ctx, op->on_done_send, 0);
      84           0 :   grpc_exec_ctx_enqueue(exec_ctx, op->on_consumed, 0);
      85           0 : }
      86             : 
      87           2 : void grpc_transport_stream_op_add_cancellation(grpc_transport_stream_op *op,
      88             :                                                grpc_status_code status) {
      89           2 :   GPR_ASSERT(status != GRPC_STATUS_OK);
      90           2 :   if (op->cancel_with_status == GRPC_STATUS_OK) {
      91           2 :     op->cancel_with_status = status;
      92             :   }
      93           2 :   if (op->close_with_status != GRPC_STATUS_OK) {
      94           0 :     op->close_with_status = GRPC_STATUS_OK;
      95           0 :     if (op->optional_close_message != NULL) {
      96           0 :       gpr_slice_unref(*op->optional_close_message);
      97           0 :       op->optional_close_message = NULL;
      98             :     }
      99             :   }
     100           2 : }
     101             : 
     102             : typedef struct {
     103             :   gpr_slice message;
     104             :   grpc_closure *then_call;
     105             :   grpc_closure closure;
     106             : } close_message_data;
     107             : 
     108           7 : static void free_message(grpc_exec_ctx *exec_ctx, void *p, int iomgr_success) {
     109           7 :   close_message_data *cmd = p;
     110           7 :   gpr_slice_unref(cmd->message);
     111           7 :   if (cmd->then_call != NULL) {
     112           0 :     cmd->then_call->cb(exec_ctx, cmd->then_call->cb_arg, iomgr_success);
     113             :   }
     114           7 :   gpr_free(cmd);
     115           7 : }
     116             : 
     117           7 : void grpc_transport_stream_op_add_close(grpc_transport_stream_op *op,
     118             :                                         grpc_status_code status,
     119             :                                         gpr_slice *optional_message) {
     120             :   close_message_data *cmd;
     121           7 :   GPR_ASSERT(status != GRPC_STATUS_OK);
     122          14 :   if (op->cancel_with_status != GRPC_STATUS_OK ||
     123           7 :       op->close_with_status != GRPC_STATUS_OK) {
     124           0 :     if (optional_message) {
     125           0 :       gpr_slice_unref(*optional_message);
     126             :     }
     127           7 :     return;
     128             :   }
     129           7 :   if (optional_message) {
     130           7 :     cmd = gpr_malloc(sizeof(*cmd));
     131           7 :     cmd->message = *optional_message;
     132           7 :     cmd->then_call = op->on_consumed;
     133           7 :     grpc_closure_init(&cmd->closure, free_message, cmd);
     134           7 :     op->on_consumed = &cmd->closure;
     135           7 :     op->optional_close_message = &cmd->message;
     136             :   }
     137           7 :   op->close_with_status = status;
     138             : }

Generated by: LCOV version 1.10