Skip to content

Commit

Permalink
socket: created sockaddr and internal functions sockaddr_un,
Browse files Browse the repository at this point in the history
`sockaddr_in` & `sockaddr_in6`.

`sockadd` is still work in progress and it can be used to bind and
connect to socket.
  • Loading branch information
YoSTEALTH committed Mar 10, 2024
1 parent eb8feda commit a91bccb
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 128 deletions.
9 changes: 0 additions & 9 deletions src/liburing/_io_uring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ from .lib.io_uring cimport *
# fsync flags
IORING_FSYNC_DATASYNC = __IORING_FSYNC_DATASYNC

# sqe.flags
IOSQE_FIXED_FILE = __IOSQE_FIXED_FILE
IOSQE_IO_DRAIN = __IOSQE_IO_DRAIN
IOSQE_IO_LINK = __IOSQE_IO_LINK
IOSQE_IO_HARDLINK = __IOSQE_IO_HARDLINK
IOSQE_ASYNC = __IOSQE_ASYNC
IOSQE_BUFFER_SELECT = __IOSQE_BUFFER_SELECT
IOSQE_CQE_SKIP_SUCCESS = __IOSQE_CQE_SKIP_SUCCESS

IORING_URING_CMD_FIXED = __IORING_URING_CMD_FIXED

IORING_TIMEOUT_ABS = __IORING_TIMEOUT_ABS
Expand Down
17 changes: 12 additions & 5 deletions src/liburing/queue.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ from cpython.ref cimport Py_INCREF, Py_DECREF
from .error cimport trap_error, memory_error, index_error


LIBURING_UDATA_TIMEOUT = __LIBURING_UDATA_TIMEOUT


cdef class io_uring:
''' I/O URing
Expand Down Expand Up @@ -49,7 +46,6 @@ cdef class io_uring:
f'ring_fd={self.ptr.ring_fd!r}, features={self.ptr.features!r}, ' \
f'enter_ring_fd={self.ptr.enter_ring_fd!r}, int_flags={self.ptr.int_flags!r}) '


cdef class io_uring_sqe:
''' IO submission data structure (Submission Queue Entry)
Expand Down Expand Up @@ -132,7 +128,6 @@ cdef class io_uring_sqe:
def user_data(self, __u64 data):
__io_uring_sqe_set_data64(self.ptr, data)


cdef class io_uring_cqe:
''' IO completion data structure (Completion Queue Entry)
Expand Down Expand Up @@ -424,3 +419,15 @@ cpdef inline io_uring_sqe io_uring_get_sqe(io_uring ring):
cdef io_uring_sqe sqe = io_uring_sqe(0)
sqe.ptr = __io_uring_get_sqe(ring.ptr)
return sqe


LIBURING_UDATA_TIMEOUT = __LIBURING_UDATA_TIMEOUT

# sqe.flags
IOSQE_FIXED_FILE = __IOSQE_FIXED_FILE
IOSQE_IO_DRAIN = __IOSQE_IO_DRAIN
IOSQE_IO_LINK = __IOSQE_IO_LINK
IOSQE_IO_HARDLINK = __IOSQE_IO_HARDLINK
IOSQE_ASYNC = __IOSQE_ASYNC
IOSQE_BUFFER_SELECT = __IOSQE_BUFFER_SELECT
IOSQE_CQE_SKIP_SUCCESS = __IOSQE_CQE_SKIP_SUCCESS
83 changes: 30 additions & 53 deletions src/liburing/socket.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@ from .lib.uring cimport *
from .queue cimport io_uring_sqe


cdef class io_uring_recvmsg_out:
cdef __io_uring_recvmsg_out * ptr

cdef class sockaddr_storage:
cdef __sockaddr_storage *ptr

cdef class sockaddr:
cdef __sockaddr *ptr
cdef:
void* ptr
socklen_t sizeof
readonly sa_family_t family

cdef class sockaddr_un:
cdef __sockaddr_un *ptr

cdef class sockaddr_in:
cdef __sockaddr_in *ptr
cdef __sockaddr_un* sockaddr_un(char* path) noexcept nogil
cdef __sockaddr_in* sockaddr_in(char* addr, in_port_t port) noexcept nogil
cdef __sockaddr_in6* sockaddr_in6(char *addr, in_port_t port, uint32_t scope_id) noexcept nogil

cdef class sockaddr_in6:
cdef __sockaddr_in6 *ptr

cdef class msghdr:
cdef __msghdr *ptr
Expand All @@ -27,6 +21,27 @@ cdef class cmsghdr:
cdef __cmsghdr *ptr


cdef class io_uring_recvmsg_out:
cdef __io_uring_recvmsg_out * ptr


cpdef void io_uring_prep_socket(io_uring_sqe sqe,
int domain,
int type,
int protocol=?,
unsigned int flags=?) noexcept nogil
cpdef void io_uring_prep_socket_direct(io_uring_sqe sqe,
int domain,
int type,
int protocol=?,
unsigned int file_index=?,
unsigned int flags=?) noexcept nogil
cpdef void io_uring_prep_socket_direct_alloc(io_uring_sqe sqe,
int domain,
int type,
int protocol=?,
unsigned int flags=?) noexcept nogil

cpdef void io_uring_prep_recvmsg(io_uring_sqe sqe,
int fd,
msghdr msg=?,
Expand Down Expand Up @@ -58,7 +73,7 @@ cpdef void io_uring_prep_multishot_accept_direct(io_uring_sqe sqe,
int flags=?) noexcept nogil
cpdef void io_uring_prep_connect(io_uring_sqe sqe,
int fd,
sockaddr addr) noexcept nogil
sockaddr addr) noexcept
cpdef void io_uring_prep_send(io_uring_sqe sqe,
int sockfd,
const unsigned char[:] buf,
Expand Down Expand Up @@ -114,49 +129,11 @@ cpdef unsigned int io_uring_recvmsg_payload_length(io_uring_recvmsg_out o,
int buf_len,
msghdr msgh) noexcept nogil
cpdef void io_uring_prep_shutdown(io_uring_sqe sqe, int fd, int how) noexcept nogil
cpdef void io_uring_prep_socket(io_uring_sqe sqe,
int domain,
int type,
int protocol,
unsigned int flags=?) noexcept nogil
cpdef void io_uring_prep_socket_direct(io_uring_sqe sqe,
int domain,
int type,
int protocol,
unsigned int file_index=?,
unsigned int flags=?) noexcept nogil
cpdef void io_uring_prep_socket_direct_alloc(io_uring_sqe sqe,
int domain,
int type,
int protocol,
unsigned int flags=?) noexcept nogil

cpdef void io_uring_prep_cmd_sock(io_uring_sqe sqe,
int cmd_op,
int fd,
int level,
int optname,
unsigned char[:] optval,
int optlen) noexcept nogil


cpdef enum: # TODO: need to name this.
AF_UNIX = __AF_UNIX
AF_INET = __AF_INET
AF_INET6 = __AF_INET6

SOCK_STREAM = __SOCK_STREAM
SOCK_DGRAM = __SOCK_DGRAM
SOCK_RAW = __SOCK_RAW
SOCK_RDM = __SOCK_RDM
SOCK_SEQPACKET = __SOCK_SEQPACKET
SOCK_DCCP = __SOCK_DCCP
SOCK_PACKET = __SOCK_PACKET
SOCK_CLOEXEC = __SOCK_CLOEXEC
SOCK_NONBLOCK = __SOCK_NONBLOCK

# used by `io_uring_prep_cmd_sock(cmd_op)`
cpdef enum io_uring_socket_op:
SOCKET_URING_OP_SIOCINQ = __SOCKET_URING_OP_SIOCINQ
SOCKET_URING_OP_SIOCOUTQ = __SOCKET_URING_OP_SIOCOUTQ
SOCKET_URING_OP_GETSOCKOPT = __SOCKET_URING_OP_GETSOCKOPT
SOCKET_URING_OP_SETSOCKOPT = __SOCKET_URING_OP_SETSOCKOPT
Loading

0 comments on commit a91bccb

Please sign in to comment.