From 9845750bf867ac99bea96512aa1c3a0812f08538 Mon Sep 17 00:00:00 2001 From: YoSTEALTH Date: Sun, 10 Mar 2024 08:27:09 -0600 Subject: [PATCH] lib.socket: added `bind`, `listen`, `SHUT_RD`, `SHUT_WR`, `SHUT_RDWR` & socket `SO_*` flags. Plus define test. --- src/liburing/__init__.py | 2 +- src/liburing/lib/socket.pxd | 61 +++++++++++++++++++++++++++++++ test/socket/socket_define_test.py | 45 +++++++++++++++++++++++ 3 files changed, 107 insertions(+), 1 deletion(-) diff --git a/src/liburing/__init__.py b/src/liburing/__init__.py index 9534c53..24495d3 100644 --- a/src/liburing/__init__.py +++ b/src/liburing/__init__.py @@ -1,7 +1,7 @@ from dynamic_import import importer -__version__ = '2024.3.8' +__version__ = '2024.3.10' importer(cache=True, exclude_dir='lib') # - `importer()` helps this project manage all import needs. It auto scans for diff --git a/src/liburing/lib/socket.pxd b/src/liburing/lib/socket.pxd index 39a5747..46dcaa8 100644 --- a/src/liburing/lib/socket.pxd +++ b/src/liburing/lib/socket.pxd @@ -44,6 +44,9 @@ cdef extern from '' nogil: sa_family_t sa_family char sa_data[14] # protocol-specific address + int __bind 'bind'(int sockfd, const __sockaddr *addr, socklen_t addrlen) + int __listen 'listen'(int sockfd, int backlog) + int __setsockopt 'setsockopt'(int sockfd, int level, int optname, @@ -134,3 +137,61 @@ cdef extern from '' nogil: # converting network to host order, uint16_t __ntohs 'ntohs'(uint16_t netshort) uint32_t __ntohl 'ntohl'(uint32_t netlong) + + +cdef extern from * nogil: # + enum: + __SHUT_RD 'SHUT_RD' + __SHUT_WR 'SHUT_WR' + __SHUT_RDWR 'SHUT_RDWR' + + enum: + __SOL_SOCKET 'SOL_SOCKET' + + __SO_DEBUG 'SO_DEBUG' + __SO_REUSEADDR 'SO_REUSEADDR' + __SO_TYPE 'SO_TYPE' + __SO_ERROR 'SO_ERROR' + __SO_DONTROUTE 'SO_DONTROUTE' + __SO_BROADCAST 'SO_BROADCAST' + __SO_SNDBUF 'SO_SNDBUF' + __SO_RCVBUF 'SO_RCVBUF' + __SO_SNDBUFFORCE 'SO_SNDBUFFORCE' + __SO_RCVBUFFORCE 'SO_RCVBUFFORCE' + __SO_KEEPALIVE 'SO_KEEPALIVE' + __SO_OOBINLINE 'SO_OOBINLINE' + __SO_NO_CHECK 'SO_NO_CHECK' + __SO_PRIORITY 'SO_PRIORITY' + __SO_LINGER 'SO_LINGER' + __SO_BSDCOMPAT 'SO_BSDCOMPAT' + __SO_REUSEPORT 'SO_REUSEPORT' + + __SO_PASSCRED 'SO_PASSCRED' + __SO_PEERCRED 'SO_PEERCRED' + __SO_RCVLOWAT 'SO_RCVLOWAT' + __SO_SNDLOWAT 'SO_SNDLOWAT' + + __SO_BINDTODEVICE 'SO_BINDTODEVICE' + + # Socket filtering + __SO_ATTACH_FILTER 'SO_ATTACH_FILTER' + __SO_DETACH_FILTER 'SO_DETACH_FILTER' + __SO_GET_FILTER 'SO_GET_FILTER' + __SO_PEERNAME 'SO_PEERNAME' + __SO_ACCEPTCONN 'SO_ACCEPTCONN' + __SO_PEERSEC 'SO_PEERSEC' + __SO_PASSSEC 'SO_PASSSEC' + __SO_MARK 'SO_MARK' + __SO_PROTOCOL 'SO_PROTOCOL' + __SO_DOMAIN 'SO_DOMAIN' + __SO_RXQ_OVFL 'SO_RXQ_OVFL' + __SO_WIFI_STATUS 'SO_WIFI_STATUS' + __SCM_WIFI_STATUS 'SCM_WIFI_STATUS' + __SO_PEEK_OFF 'SO_PEEK_OFF' + + # not tested + __SO_TIMESTAMP 'SO_TIMESTAMP' + __SO_TIMESTAMPNS 'SO_TIMESTAMPNS' + __SO_TIMESTAMPING 'SO_TIMESTAMPING' + __SO_RCVTIMEO 'SO_RCVTIMEO' + __SO_SNDTIMEO 'SO_SNDTIMEO' diff --git a/test/socket/socket_define_test.py b/test/socket/socket_define_test.py index 4172068..74ef3da 100644 --- a/test/socket/socket_define_test.py +++ b/test/socket/socket_define_test.py @@ -15,3 +15,48 @@ def test_define(): assert liburing.SOCK_PACKET == 10 assert liburing.SOCK_CLOEXEC == 0o2000000 assert liburing.SOCK_NONBLOCK == 0o4000 + + assert liburing.SHUT_RD == 0 + assert liburing.SHUT_WR == 1 + assert liburing.SHUT_RDWR == 2 + + # setsockopt & getsockopt + assert liburing.SOL_SOCKET == 1 + assert liburing.SO_DEBUG == 1 + assert liburing.SO_REUSEADDR == 2 + assert liburing.SO_TYPE == 3 + assert liburing.SO_ERROR == 4 + assert liburing.SO_DONTROUTE == 5 + assert liburing.SO_BROADCAST == 6 + assert liburing.SO_SNDBUF == 7 + assert liburing.SO_RCVBUF == 8 + assert liburing.SO_SNDBUFFORCE == 32 + assert liburing.SO_RCVBUFFORCE == 33 + assert liburing.SO_KEEPALIVE == 9 + assert liburing.SO_OOBINLINE == 10 + assert liburing.SO_NO_CHECK == 11 + assert liburing.SO_PRIORITY == 12 + assert liburing.SO_LINGER == 13 + assert liburing.SO_BSDCOMPAT == 14 + assert liburing.SO_REUSEPORT == 15 + assert liburing.SO_PASSCRED == 16 + assert liburing.SO_PEERCRED == 17 + assert liburing.SO_RCVLOWAT == 18 + assert liburing.SO_SNDLOWAT == 19 + assert liburing.SO_BINDTODEVICE == 25 + + # Socket filtering + assert liburing.SO_ATTACH_FILTER == 26 + assert liburing.SO_DETACH_FILTER == 27 + assert liburing.SO_GET_FILTER == liburing.SO_ATTACH_FILTER + assert liburing.SO_PEERNAME == 28 + assert liburing.SO_ACCEPTCONN == 30 + assert liburing.SO_PEERSEC == 31 + assert liburing.SO_PASSSEC == 34 + assert liburing.SO_MARK == 36 + assert liburing.SO_PROTOCOL == 38 + assert liburing.SO_DOMAIN == 39 + assert liburing.SO_RXQ_OVFL == 40 + assert liburing.SO_WIFI_STATUS == 41 + assert liburing.SCM_WIFI_STATUS == liburing.SO_WIFI_STATUS + assert liburing.SO_PEEK_OFF == 42