fdshare_python.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. // $Id$
  15. #define PY_SSIZE_T_CLEAN
  16. #include <Python.h>
  17. #include <structmember.h>
  18. #include <config.h>
  19. #include <xfr/fd_share.h>
  20. static PyObject*
  21. fdshare_recv_fd(PyObject *self UNUSED_PARAM, PyObject *args) {
  22. int sock, fd;
  23. if (!PyArg_ParseTuple(args, "i", &sock)) {
  24. return (NULL);
  25. }
  26. fd = isc::xfr::recv_fd(sock);
  27. return (Py_BuildValue("i", fd));
  28. }
  29. static PyObject*
  30. fdshare_send_fd(PyObject *self UNUSED_PARAM, PyObject *args) {
  31. int sock, fd, result;
  32. if (!PyArg_ParseTuple(args, "ii", &sock, &fd)) {
  33. return (NULL);
  34. }
  35. result = isc::xfr::send_fd(sock, fd);
  36. return (Py_BuildValue("i", result));
  37. }
  38. static PyMethodDef fdshare_Methods[] = {
  39. {"send_fd", fdshare_send_fd, METH_VARARGS, ""},
  40. {"recv_fd", fdshare_recv_fd, METH_VARARGS, ""},
  41. {NULL, NULL, 0, NULL} /* Sentinel */
  42. };
  43. static PyModuleDef bind10_fdshare_python = {
  44. { PyObject_HEAD_INIT(NULL) NULL, 0, NULL},
  45. "bind10_fdshare",
  46. "Python bindings for fdshare",
  47. -1,
  48. fdshare_Methods,
  49. NULL,
  50. NULL,
  51. NULL,
  52. NULL
  53. };
  54. PyMODINIT_FUNC
  55. PyInit_libxfr_python(void) {
  56. PyObject *mod = PyModule_Create(&bind10_fdshare_python);
  57. if (mod == NULL) {
  58. return (NULL);
  59. }
  60. return (mod);
  61. }