在yar_transport.h中,定义了yar_transport_t结构体,先不考虑并行处理的接口,以socket传输协议为例子学习,代码简化一些如下:
typedef struct _yar_transport_interface {
void *data;
int (*open)(struct _yar_transport_interface *self, char *address, uint len, long options, char **msg TSRMLS_DC);
int (*send)(struct _yar_transport_interface *self, struct _yar_request *request, char **msg TSRMLS_DC);
struct _yar_response * (*exec)(struct _yar_transport_interface *self, struct _yar_request *request TSRMLS_DC);
int (*setopt)(struct _yar_transport_interface *self, long type, void *value, void *addition TSRMLS_DC);
int (*calldata)(struct _yar_transport_interface *self, yar_call_data_t *calldata TSRMLS_DC);
void (*close)(struct _yar_transport_interface *self TSRMLS_DC);
} yar_transport_interface_t;
typedef struct _yar_transport {
const char *name;
struct _yar_transport_interface * (*init)(TSRMLS_D);
void (*destroy)(yar_transport_interface_t *self TSRMLS_DC);
yar_transport_multi_t *multi;
} yar_transport_t;
然后在transports/socket.c中定义了yar_transport_socket
yar_transport_t yar_transport_socket = {
"sock",
php_yar_socket_init,
php_yar_socket_destroy,
};
整理了整体的执行流程如下图
