kore

a fork of the worlds most advanced web framework
Log | Files | Refs | README | LICENSE

commit d60994abb59acc0753cc5c118c368e82eb2612c4
parent 9caa45a05024ef3593133bde6e08098b8963a704
Author: Erik Karlsson <erik.karlsson@tutus.se>
Date:   Thu, 14 Mar 2019 08:37:02 +0100

add python sendto recvfrom abstract socket support

Diffstat:
Msrc/python.c | 28++++++++++++++++++++++++++++
1 file changed, 28 insertions(+), 0 deletions(-)

diff --git a/src/python.c b/src/python.c @@ -2267,6 +2267,26 @@ pysocket_async_recv(struct pysocket_op *op) return (NULL); break; case AF_UNIX: + if (socklen < sizeof(sa_family_t)) { + if ((tuple = Py_BuildValue("(ON)", + Py_None, bytes)) == NULL) + return (NULL); + break; + } + + if (socklen > sizeof(struct sockaddr_un)) { + PyErr_SetString(PyExc_RuntimeError, + "Socklen longer than sockaddr_un"); + return (NULL); + } + +#if defined(__linux__) + if (op->sendaddr.sun.sun_path[0] == '\0') { + op->sendaddr.sun.sun_path[0] = '@'; + op->sendaddr.sun.sun_path[socklen - sizeof(sa_family_t)] = '\0'; + } +#endif + if ((tuple = Py_BuildValue("(sN)", op->sendaddr.sun.sun_path, bytes)) == NULL) return (NULL); @@ -2313,6 +2333,14 @@ pysocket_async_send(struct pysocket_op *op) break; case AF_UNIX: socklen = sizeof(op->sendaddr.sun); +#if defined(__linux__) + if (op->sendaddr.sun.sun_path[0] == '@') { + socklen = sizeof(sa_family_t) + + strlen(op->sendaddr.sun.sun_path); + op->sendaddr.sun.sun_path[0] = '\0'; + } +#endif + break; default: fatal("non AF_INET/AF_UNIX in %s", __func__);