2012-05-22 19:43:11 +02:00
|
|
|
#ifndef PHP_UV_H
|
|
|
|
|
|
|
|
#define PHP_UV_H
|
|
|
|
|
|
|
|
#define PHP_UV_EXTNAME "uv"
|
2012-07-01 15:36:40 +02:00
|
|
|
#define PHP_UV_EXTVER "0.0.1"
|
2012-05-22 19:43:11 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-06-19 01:10:25 +02:00
|
|
|
#ifdef PHP_WIN32
|
|
|
|
#include <Winsock2.h>
|
|
|
|
#include <Mswsock.h>
|
|
|
|
#include <psapi.h>
|
|
|
|
#include <Iphlpapi.h>
|
2012-06-20 05:08:44 +02:00
|
|
|
#endif
|
2012-06-19 01:10:25 +02:00
|
|
|
|
2012-07-14 15:57:18 +02:00
|
|
|
#ifndef PHP_UV_DTRACE
|
|
|
|
#define PHP_UV_DTRACE 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if PHP_UV_DTRACE >= 1
|
|
|
|
#include <dtrace.h>
|
|
|
|
#include <sys/sdt.h>
|
|
|
|
#include "phpuv_dtrace.h"
|
|
|
|
#define PHP_UV_PROBE(PROBE) PHPUV_TRACE_##PROBE();
|
|
|
|
#else
|
|
|
|
#define PHP_UV_PROBE(PROBE)
|
|
|
|
#endif
|
|
|
|
|
2012-05-22 19:43:11 +02:00
|
|
|
#include "php.h"
|
2012-05-23 06:35:28 +02:00
|
|
|
#include "uv.h"
|
2012-07-01 06:15:14 +02:00
|
|
|
#include "http_parser.h"
|
2012-05-22 19:43:11 +02:00
|
|
|
|
2012-07-14 20:56:29 +02:00
|
|
|
#include "php_network.h"
|
|
|
|
#include "php_streams.h"
|
|
|
|
|
2012-07-15 07:03:18 +02:00
|
|
|
#include "ext/sockets/php_sockets.h"
|
2012-07-14 20:56:29 +02:00
|
|
|
|
2012-05-22 19:43:11 +02:00
|
|
|
#include "zend_interfaces.h"
|
|
|
|
|
|
|
|
/* Define the entry point symbol
|
|
|
|
* Zend will use when loading this module
|
|
|
|
*/
|
|
|
|
extern zend_module_entry uv_module_entry;
|
2012-07-16 03:49:12 +02:00
|
|
|
#define phpext_uv_ptr &uv_module_entry
|
2012-05-22 19:43:11 +02:00
|
|
|
|
|
|
|
extern zend_class_entry *uv_class_entry;
|
|
|
|
|
2012-06-30 07:42:06 +02:00
|
|
|
enum php_uv_lock_type{
|
|
|
|
IS_UV_RWLOCK = 1,
|
2012-07-21 13:49:10 +02:00
|
|
|
IS_UV_RWLOCK_RD = 2,
|
|
|
|
IS_UV_RWLOCK_WR = 3,
|
|
|
|
IS_UV_MUTEX = 4,
|
|
|
|
IS_UV_SEMAPHORE = 5,
|
2012-06-30 07:42:06 +02:00
|
|
|
};
|
|
|
|
|
2012-05-29 18:47:30 +02:00
|
|
|
enum php_uv_resource_type{
|
2012-06-29 17:42:33 +02:00
|
|
|
IS_UV_TCP = 0,
|
|
|
|
IS_UV_UDP = 1,
|
|
|
|
IS_UV_PIPE = 2,
|
|
|
|
IS_UV_IDLE = 3,
|
|
|
|
IS_UV_TIMER = 4,
|
|
|
|
IS_UV_ASYNC = 5,
|
|
|
|
IS_UV_LOOP = 6,
|
|
|
|
IS_UV_HANDLE = 7,
|
|
|
|
IS_UV_STREAM = 8,
|
2012-05-29 18:47:30 +02:00
|
|
|
IS_UV_ADDRINFO = 9,
|
2012-06-29 17:42:33 +02:00
|
|
|
IS_UV_PROCESS = 10,
|
|
|
|
IS_UV_PREPARE = 11,
|
|
|
|
IS_UV_CHECK = 12,
|
|
|
|
IS_UV_WORK = 13,
|
|
|
|
IS_UV_FS = 14,
|
2012-06-23 07:18:38 +02:00
|
|
|
IS_UV_FS_EVENT = 15,
|
2012-06-29 17:42:33 +02:00
|
|
|
IS_UV_TTY = 16,
|
2012-07-08 18:27:02 +02:00
|
|
|
IS_UV_FS_POLL = 17,
|
2012-07-09 05:24:35 +02:00
|
|
|
IS_UV_POLL = 18,
|
2012-07-10 18:26:37 +02:00
|
|
|
IS_UV_MAX = 19
|
2012-05-29 18:47:30 +02:00
|
|
|
};
|
|
|
|
|
2012-07-11 06:07:57 +02:00
|
|
|
enum php_uv_callback_type{
|
|
|
|
PHP_UV_LISTEN_CB = 0,
|
|
|
|
PHP_UV_READ_CB = 1,
|
|
|
|
PHP_UV_READ2_CB = 2,
|
|
|
|
PHP_UV_WRITE_CB = 3,
|
|
|
|
PHP_UV_SHUTDOWN_CB = 4,
|
|
|
|
PHP_UV_CLOSE_CB = 5,
|
|
|
|
PHP_UV_TIMER_CB = 6,
|
|
|
|
PHP_UV_IDLE_CB = 7,
|
|
|
|
PHP_UV_CONNECT_CB = 8,
|
|
|
|
PHP_UV_GETADDR_CB = 9,
|
|
|
|
PHP_UV_RECV_CB = 10,
|
|
|
|
PHP_UV_SEND_CB = 11,
|
|
|
|
PHP_UV_PIPE_CONNECT_CB = 12,
|
|
|
|
PHP_UV_PROC_CLOSE_CB = 13,
|
|
|
|
PHP_UV_PREPARE_CB = 14,
|
|
|
|
PHP_UV_CHECK_CB = 15,
|
|
|
|
PHP_UV_ASYNC_CB = 16,
|
|
|
|
PHP_UV_WORK_CB = 17,
|
|
|
|
PHP_UV_AFTER_WORK_CB = 18,
|
|
|
|
PHP_UV_FS_CB = 19,
|
|
|
|
PHP_UV_FS_EVENT_CB = 20,
|
|
|
|
PHP_UV_FS_POLL_CB = 21,
|
|
|
|
PHP_UV_POLL_CB = 22,
|
|
|
|
PHP_UV_CB_MAX = 23
|
|
|
|
};
|
|
|
|
|
2012-07-10 18:26:37 +02:00
|
|
|
typedef struct {
|
|
|
|
zend_fcall_info fci;
|
|
|
|
zend_fcall_info_cache fcc;
|
|
|
|
} php_uv_cb_t;
|
|
|
|
|
2012-05-23 06:35:28 +02:00
|
|
|
typedef struct {
|
2012-05-27 08:36:03 +02:00
|
|
|
int in_free;
|
2012-06-14 17:18:05 +02:00
|
|
|
#ifdef ZTS
|
|
|
|
void ***thread_ctx;
|
|
|
|
#endif
|
2012-05-26 16:26:29 +02:00
|
|
|
int resource_id;
|
2012-05-29 18:47:30 +02:00
|
|
|
int type;
|
2012-07-09 05:24:35 +02:00
|
|
|
uv_os_sock_t sock;
|
2012-05-26 15:59:59 +02:00
|
|
|
union {
|
|
|
|
uv_tcp_t tcp;
|
|
|
|
uv_udp_t udp;
|
|
|
|
uv_pipe_t pipe;
|
|
|
|
uv_idle_t idle;
|
|
|
|
uv_timer_t timer;
|
|
|
|
uv_async_t async;
|
|
|
|
uv_loop_t loop;
|
|
|
|
uv_handle_t handle;
|
|
|
|
uv_stream_t stream;
|
2012-05-28 18:12:09 +02:00
|
|
|
uv_getaddrinfo_t addrinfo;
|
2012-06-17 15:50:18 +02:00
|
|
|
uv_prepare_t prepare;
|
2012-06-17 16:04:54 +02:00
|
|
|
uv_check_t check;
|
2012-06-14 15:24:19 +02:00
|
|
|
uv_process_t process;
|
2012-06-17 18:32:50 +02:00
|
|
|
uv_work_t work;
|
2012-06-20 05:40:39 +02:00
|
|
|
uv_fs_t fs;
|
2012-06-23 07:18:38 +02:00
|
|
|
uv_fs_event_t fs_event;
|
2012-06-23 08:05:14 +02:00
|
|
|
uv_tty_t tty;
|
2012-07-08 18:27:02 +02:00
|
|
|
uv_fs_poll_t fs_poll;
|
2012-07-09 05:24:35 +02:00
|
|
|
uv_poll_t poll;
|
2012-05-26 15:59:59 +02:00
|
|
|
} uv;
|
2012-06-22 05:51:16 +02:00
|
|
|
char *buffer;
|
2012-05-28 18:12:09 +02:00
|
|
|
zval *address;
|
2012-07-15 16:47:49 +02:00
|
|
|
zval *fs_fd;
|
2012-07-11 06:07:57 +02:00
|
|
|
php_uv_cb_t *callback[PHP_UV_CB_MAX];
|
2012-06-03 18:23:03 +02:00
|
|
|
} php_uv_t;
|
|
|
|
|
2012-05-28 18:12:09 +02:00
|
|
|
typedef struct {
|
|
|
|
int is_ipv4;
|
|
|
|
int resource_id;
|
|
|
|
union {
|
|
|
|
struct sockaddr_in ipv4;
|
|
|
|
struct sockaddr_in6 ipv6;
|
|
|
|
} addr;
|
|
|
|
} php_uv_sockaddr_t;
|
|
|
|
|
2012-06-30 07:10:58 +02:00
|
|
|
typedef struct {
|
|
|
|
int locked;
|
2012-06-30 07:42:06 +02:00
|
|
|
enum php_uv_lock_type type;
|
2012-06-30 07:10:58 +02:00
|
|
|
int resource_id;
|
|
|
|
union {
|
|
|
|
uv_rwlock_t rwlock;
|
|
|
|
uv_mutex_t mutex;
|
2012-07-08 17:18:26 +02:00
|
|
|
uv_sem_t semaphore;
|
2012-06-30 07:10:58 +02:00
|
|
|
} lock;
|
|
|
|
} php_uv_lock_t;
|
|
|
|
|
2012-07-22 14:54:19 +02:00
|
|
|
typedef struct {
|
|
|
|
int resource_id;
|
|
|
|
int fd;
|
|
|
|
zval *stream;
|
|
|
|
int flags;
|
|
|
|
} php_uv_stdio_t;
|
|
|
|
|
2012-06-30 07:10:58 +02:00
|
|
|
|
2012-07-01 06:15:14 +02:00
|
|
|
typedef struct {
|
|
|
|
struct http_parser parser;
|
|
|
|
struct http_parser_url handle;
|
|
|
|
struct http_parser_settings settings;
|
|
|
|
int is_response;
|
|
|
|
int was_header_value;
|
|
|
|
int finished;
|
|
|
|
zval *data;
|
|
|
|
zval *headers;
|
|
|
|
char *tmp;
|
|
|
|
} php_http_parser_context;
|
|
|
|
|
|
|
|
#define PHP_UV_HTTPPARSER_RESOURCE_NAME "uv_httpparser"
|
|
|
|
|
2012-05-23 06:35:28 +02:00
|
|
|
#define PHP_UV_RESOURCE_NAME "uv"
|
2012-05-28 18:12:09 +02:00
|
|
|
#define PHP_UV_SOCKADDR_RESOURCE_NAME "uv_sockaddr"
|
2012-05-28 15:18:36 +02:00
|
|
|
#define PHP_UV_LOOP_RESOURCE_NAME "uv_loop"
|
2012-06-03 18:23:03 +02:00
|
|
|
#define PHP_UV_ARES_RESOURCE_NAME "uv_ares"
|
2012-06-30 07:10:58 +02:00
|
|
|
#define PHP_UV_LOCK_RESOURCE_NAME "uv_lock"
|
2012-06-17 14:18:30 +02:00
|
|
|
#define PHP_UV_MUTEX_RESOURCE_NAME "uv_mutex"
|
2012-07-22 14:54:19 +02:00
|
|
|
#define PHP_UV_STDIO_RESOURCE_NAME "uv_stdio"
|
2012-05-23 06:35:28 +02:00
|
|
|
|
2012-06-25 17:30:45 +02:00
|
|
|
|
2012-06-25 18:34:25 +02:00
|
|
|
#if PHP_VERSION_ID>=50399
|
2012-06-25 17:30:45 +02:00
|
|
|
#define PHP_UV_LIST_INSERT(type, handle) zend_list_insert(type, handle TSRMLS_CC)
|
|
|
|
#else
|
|
|
|
#define PHP_UV_LIST_INSERT(type, handle) zend_list_insert(type, handle)
|
|
|
|
#endif
|
|
|
|
|
2012-06-23 13:27:30 +02:00
|
|
|
/* TODO: remove these macro when libuv provides uv_inet_ntop & uv_inet_pton */
|
|
|
|
#ifdef PHP_WIN32
|
2012-06-25 16:59:49 +02:00
|
|
|
# include "libuv/src/ares/inet_net_pton.h"
|
|
|
|
# include <Ws2tcpip.h>
|
2012-06-23 13:27:30 +02:00
|
|
|
# define uv_inet_pton ares_inet_pton
|
|
|
|
# define uv_inet_ntop ares_inet_ntop
|
|
|
|
#else
|
|
|
|
# include <arpa/inet.h>
|
|
|
|
# define uv_inet_pton inet_pton
|
|
|
|
# define uv_inet_ntop inet_ntop
|
|
|
|
#endif
|
|
|
|
|
2012-05-22 19:43:11 +02:00
|
|
|
#endif /* PHP_UV_H */
|