LCOV - code coverage report
Current view: top level - util/io - fdshare_python.cc (source / functions) Hit Total Coverage
Test: report.info Lines: 20 25 80.0 %
Date: 2012-05-15 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 38 18.4 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
       2                 :            : //
       3                 :            : // Permission to use, copy, modify, and/or distribute this software for any
       4                 :            : // purpose with or without fee is hereby granted, provided that the above
       5                 :            : // copyright notice and this permission notice appear in all copies.
       6                 :            : //
       7                 :            : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
       8                 :            : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
       9                 :            : // AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
      10                 :            : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
      11                 :            : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
      12                 :            : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
      13                 :            : // PERFORMANCE OF THIS SOFTWARE.
      14                 :            : 
      15                 :            : #define PY_SSIZE_T_CLEAN
      16                 :            : #include <Python.h>
      17                 :            : #include <structmember.h>
      18                 :            : 
      19                 :            : #include <config.h>
      20                 :            : 
      21                 :            : #include "fd_share.h"
      22                 :            : 
      23                 :            : 
      24                 :            : static PyObject*
      25                 :          1 : fdshare_recv_fd(PyObject*, PyObject* args) {
      26                 :            :     int sock, fd;
      27         [ +  - ]:          1 :     if (!PyArg_ParseTuple(args, "i", &sock)) {
      28                 :            :         return (NULL);
      29                 :            :     }
      30                 :          1 :     fd = isc::util::io::recv_fd(sock);
      31                 :          1 :     return (Py_BuildValue("i", fd));
      32                 :            : }
      33                 :            : 
      34                 :            : static PyObject*
      35                 :          1 : fdshare_send_fd(PyObject*, PyObject* args) {
      36                 :            :     int sock, fd, result;
      37         [ +  - ]:          1 :     if (!PyArg_ParseTuple(args, "ii", &sock, &fd)) {
      38                 :            :         return (NULL);
      39                 :            :     }
      40                 :          1 :     result = isc::util::io::send_fd(sock, fd);
      41                 :          1 :     return (Py_BuildValue("i", result));
      42                 :            : }
      43                 :            : 
      44                 :            : static PyMethodDef fdshare_Methods[] = {
      45                 :            :     {"send_fd",  fdshare_send_fd, METH_VARARGS, ""},
      46                 :            :     {"recv_fd",  fdshare_recv_fd, METH_VARARGS, ""},
      47                 :            :     {NULL, NULL, 0, NULL}        /* Sentinel */
      48                 :            : };
      49                 :            : 
      50                 :            : 
      51                 :            : static PyModuleDef bind10_fdshare_python = {
      52                 :            :     { PyObject_HEAD_INIT(NULL) NULL, 0, NULL},
      53                 :            :     "bind10_fdshare",
      54                 :            :     "Python bindings for fdshare",
      55                 :            :     -1,
      56                 :            :     fdshare_Methods,
      57                 :            :     NULL,
      58                 :            :     NULL,
      59                 :            :     NULL,
      60                 :            :     NULL
      61                 :            : };
      62                 :            : 
      63                 :            : PyMODINIT_FUNC
      64                 :          5 : PyInit_libutil_io_python(void) {
      65                 :          5 :     PyObject *mod = PyModule_Create(&bind10_fdshare_python);
      66         [ +  - ]:          5 :     if (mod == NULL) {
      67                 :            :         return (NULL);
      68                 :            :     }
      69                 :            : 
      70                 :            :     PyObject* FD_SYSTEM_ERROR = Py_BuildValue("i",
      71                 :          5 :                                               isc::util::io::FD_SYSTEM_ERROR);
      72         [ -  + ]:          5 :     if (FD_SYSTEM_ERROR == NULL) {
      73 [ #  # ][ #  # ]:          0 :         Py_XDECREF(mod);
      74                 :            :         return (NULL);
      75                 :            :     }
      76                 :          5 :     int ret = PyModule_AddObject(mod, "FD_SYSTEM_ERROR", FD_SYSTEM_ERROR);
      77         [ -  + ]:          5 :     if (ret == -1) {
      78 [ #  # ][ #  # ]:          0 :         Py_XDECREF(FD_SYSTEM_ERROR);
      79 [ #  # ][ #  # ]:          0 :         Py_XDECREF(mod);
      80                 :            :         return (NULL);
      81                 :            :     }
      82                 :            : 
      83                 :            :     PyObject* FD_OTHER_ERROR = Py_BuildValue("i",
      84                 :          5 :                                              isc::util::io::FD_OTHER_ERROR);
      85         [ -  + ]:          5 :     if (FD_OTHER_ERROR == NULL) {
      86 [ #  # ][ #  # ]:          0 :         Py_XDECREF(mod);
      87                 :            :         return (NULL);
      88                 :            :     }
      89                 :          5 :     ret = PyModule_AddObject(mod, "FD_OTHER_ERROR", FD_OTHER_ERROR);
      90         [ -  + ]:          5 :     if (-1 == ret) {
      91 [ #  # ][ #  # ]:          0 :         Py_XDECREF(FD_OTHER_ERROR);
      92 [ #  # ][ #  # ]:          5 :         Py_XDECREF(mod);
      93                 :            :         return (NULL);
      94                 :            :     }
      95                 :            : 
      96                 :            :     return (mod);
      97                 :            : }
      98                 :            : 

Generated by: LCOV version 1.9