PHP 8.2.30
Preview: swoole_iouring.h Size: 3.10 KB
//opt/cloudlinux/alt-php83/root/usr/include/php/ext/swoole/include/swoole_iouring.h

/*
  +----------------------------------------------------------------------+
  | Swoole                                                               |
  +----------------------------------------------------------------------+
  | This source file is subject to version 2.0 of the Apache license,    |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | http://www.apache.org/licenses/LICENSE-2.0.html                      |
  | If you did not receive a copy of the Apache2.0 license and are unable|
  | to obtain it through the world-wide-web, please send a note to       |
  | license@swoole.com so we can mail you a copy immediately.            |
  +----------------------------------------------------------------------+
  | Author: NathanFreeman  <mariasocute@163.com>                         |
  +----------------------------------------------------------------------+
*/

#ifndef SWOOLE_SRC_SWOOLE_IOURING_H
#define SWOOLE_SRC_SWOOLE_IOURING_H

#include "swoole_coroutine.h"

#ifdef SW_USE_IOURING
#include <liburing.h>

#ifdef HAVE_IOURING_FUTEX
#ifndef FUTEX2_SIZE_U32
#define FUTEX2_SIZE_U32 0x02
#endif
#endif

using swoole::Coroutine;

enum swIouringFlag {
    SW_IOURING_DEFAULT = 0,
    SW_IOURING_SQPOLL = IORING_SETUP_SQPOLL,
};

namespace swoole {

struct IouringEvent;

class Iouring {
  private:
    uint64_t task_num = 0;
    uint64_t entries = 8192;
    struct io_uring ring;
    std::queue<IouringEvent *> waiting_tasks;
    network::Socket *ring_socket = nullptr;
    Reactor *reactor = nullptr;

    Iouring(Reactor *reactor_);
    bool ready();
    bool submit(IouringEvent *event);
    bool dispatch(IouringEvent *event);
    bool wakeup();

    struct io_uring_sqe *get_iouring_sqe() {
        struct io_uring_sqe *sqe = io_uring_get_sqe(&ring);
        // We need to reset the values of each sqe structure so that they can be used in a loop.
        if (sqe) {
            memset(sqe, 0, sizeof(struct io_uring_sqe));
        }
        return sqe;
    }

    static ssize_t execute(IouringEvent *event);

  public:
    ~Iouring();

    bool is_empty_waiting_tasks() {
        return waiting_tasks.size() == 0;
    }

    uint64_t get_task_num() {
        return task_num;
    }

    static int open(const char *pathname, int flags, int mode);
    static int close(int fd);
    static ssize_t read(int fd, void *buf, size_t size);
    static ssize_t write(int fd, const void *buf, size_t size);
    static ssize_t rename(const char *oldpath, const char *newpath);
    static int mkdir(const char *pathname, mode_t mode);
    static int unlink(const char *pathname);
#ifdef HAVE_IOURING_STATX
    static int fstat(int fd, struct stat *statbuf);
    static int stat(const char *path, struct stat *statbuf);
#endif
    static int rmdir(const char *pathname);
    static int fsync(int fd);
    static int fdatasync(int fd);
#ifdef HAVE_IOURING_FUTEX
    static int futex_wait(uint32_t *futex);
    static int futex_wakeup(uint32_t *futex);
#endif

    static int callback(Reactor *reactor, Event *event);
};
};  // namespace swoole
#endif
#endif

Directory Contents

Dirs: 0 × Files: 54

Name Size Perms Modified Actions
24.83 KB lrw-r--r-- 2025-03-12 14:14:46
Edit Download
3.43 KB lrw-r--r-- 2025-03-12 14:14:46
Edit Download
2.28 KB lrw-r--r-- 2025-03-12 14:14:46
Edit Download
3.61 KB lrw-r--r-- 2025-03-12 14:14:46
Edit Download
3.72 KB lrw-r--r-- 2025-03-12 14:14:46
Edit Download
1.29 KB lrw-r--r-- 2025-03-12 14:14:46
Edit Download
2.23 KB lrw-r--r-- 2025-03-12 14:14:46
Edit Download
2.34 KB lrw-r--r-- 2025-03-12 14:14:47
Edit Download
8.65 KB lrw-r--r-- 2025-03-12 14:14:47
Edit Download
8.88 KB lrw-r--r-- 2025-03-12 14:14:47
Edit Download
9.97 KB lrw-r--r-- 2025-03-12 14:14:47
Edit Download
4.18 KB lrw-r--r-- 2025-03-12 14:14:47
Edit Download
2.75 KB lrw-r--r-- 2025-03-12 14:14:47
Edit Download
5.83 KB lrw-r--r-- 2025-03-12 14:14:47
Edit Download
18.78 KB lrw-r--r-- 2025-03-12 14:14:47
Edit Download
3.87 KB lrw-r--r-- 2025-03-12 14:14:47
Edit Download
2.08 KB lrw-r--r-- 2025-03-12 14:14:47
Edit Download
2.41 KB lrw-r--r-- 2025-03-12 14:14:47
Edit Download
6.11 KB lrw-r--r-- 2025-03-12 14:14:47
Edit Download
4.43 KB lrw-r--r-- 2025-03-12 14:14:47
Edit Download
3.84 KB lrw-r--r-- 2025-03-12 14:14:47
Edit Download
9.69 KB lrw-r--r-- 2025-03-12 14:14:47
Edit Download
1.79 KB lrw-r--r-- 2025-03-12 14:14:47
Edit Download
6.99 KB lrw-r--r-- 2025-03-12 14:14:47
Edit Download
8.38 KB lrw-r--r-- 2025-03-12 14:14:48
Edit Download
3.10 KB lrw-r--r-- 2025-03-12 14:14:48
Edit Download
3.39 KB lrw-r--r-- 2025-03-12 14:14:48
Edit Download
15.34 KB lrw-r--r-- 2025-03-12 14:14:48
Edit Download
3.17 KB lrw-r--r-- 2025-03-12 14:14:49
Edit Download
2.75 KB lrw-r--r-- 2025-03-12 14:14:49
Edit Download
6.02 KB lrw-r--r-- 2025-03-12 14:14:49
Edit Download
1.44 KB lrw-r--r-- 2025-03-12 14:14:50
Edit Download
2.18 KB lrw-r--r-- 2025-03-12 14:14:50
Edit Download
1.92 KB lrw-r--r-- 2025-03-12 14:14:50
Edit Download
2.64 KB lrw-r--r-- 2025-03-12 14:14:50
Edit Download
9.94 KB lrw-r--r-- 2025-03-12 14:14:50
Edit Download
5.17 KB lrw-r--r-- 2025-03-12 14:14:50
Edit Download
2.87 KB lrw-r--r-- 2025-03-12 14:14:50
Edit Download
11.25 KB lrw-r--r-- 2025-03-12 14:14:50
Edit Download
2.09 KB lrw-r--r-- 2025-03-12 14:14:50
Edit Download
43.94 KB lrw-r--r-- 2025-03-12 14:14:50
Edit Download
1.72 KB lrw-r--r-- 2025-03-12 14:14:50
Edit Download
19.04 KB lrw-r--r-- 2025-03-12 14:14:50
Edit Download
2.23 KB lrw-r--r-- 2025-03-12 14:14:50
Edit Download
4.94 KB lrw-r--r-- 2025-03-12 14:14:50
Edit Download
4.70 KB lrw-r--r-- 2025-03-12 14:14:50
Edit Download
8.87 KB lrw-r--r-- 2025-03-12 14:14:50
Edit Download
7.35 KB lrw-r--r-- 2025-03-12 14:14:51
Edit Download
2.23 KB lrw-r--r-- 2025-03-12 14:14:51
Edit Download
4.13 KB lrw-r--r-- 2025-03-12 14:14:51
Edit Download
6.61 KB lrw-r--r-- 2025-03-12 14:14:51
Edit Download
2.21 KB lrw-r--r-- 2025-03-12 14:14:51
Edit Download
4.53 KB lrw-r--r-- 2025-03-12 14:14:51
Edit Download
2.48 KB lrw-r--r-- 2025-03-12 14:14:51
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).