LCOV - code coverage report
Current view: top level - src/core/iomgr - endpoint_pair_posix.c (source / functions) Hit Total Coverage
Test: tmp.zDYK9MVh93 Lines: 16 16 100.0 %
Date: 2015-10-10 Functions: 2 2 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 <grpc/support/port_platform.h>
      35             : 
      36             : #ifdef GPR_POSIX_SOCKET
      37             : 
      38             : #include "src/core/iomgr/endpoint_pair.h"
      39             : 
      40             : #include <errno.h>
      41             : #include <fcntl.h>
      42             : #include <string.h>
      43             : #include <sys/types.h>
      44             : #include <sys/socket.h>
      45             : 
      46             : #include "src/core/iomgr/tcp_posix.h"
      47             : #include "src/core/support/string.h"
      48             : #include <grpc/support/alloc.h>
      49             : #include <grpc/support/log.h>
      50             : #include <grpc/support/string_util.h>
      51             : 
      52         655 : static void create_sockets(int sv[2]) {
      53             :   int flags;
      54         655 :   GPR_ASSERT(socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == 0);
      55         655 :   flags = fcntl(sv[0], F_GETFL, 0);
      56         655 :   GPR_ASSERT(fcntl(sv[0], F_SETFL, flags | O_NONBLOCK) == 0);
      57         655 :   flags = fcntl(sv[1], F_GETFL, 0);
      58         655 :   GPR_ASSERT(fcntl(sv[1], F_SETFL, flags | O_NONBLOCK) == 0);
      59         655 : }
      60             : 
      61         655 : grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(const char *name,
      62             :                                                    size_t read_slice_size) {
      63             :   int sv[2];
      64             :   grpc_endpoint_pair p;
      65             :   char *final_name;
      66         655 :   create_sockets(sv);
      67             : 
      68         655 :   gpr_asprintf(&final_name, "%s:client", name);
      69         655 :   p.client = grpc_tcp_create(grpc_fd_create(sv[1], final_name), read_slice_size,
      70             :                              "socketpair-server");
      71         655 :   gpr_free(final_name);
      72         655 :   gpr_asprintf(&final_name, "%s:server", name);
      73         655 :   p.server = grpc_tcp_create(grpc_fd_create(sv[0], final_name), read_slice_size,
      74             :                              "socketpair-client");
      75         655 :   gpr_free(final_name);
      76         655 :   return p;
      77             : }
      78             : 
      79             : #endif

Generated by: LCOV version 1.10