ma_pvio.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #ifndef _ma_pvio_h_
  2. #define _ma_pvio_h_
  3. #define cio_defined
  4. #ifdef HAVE_TLS
  5. #include <ma_tls.h>
  6. #else
  7. #define MARIADB_TLS void
  8. #endif
  9. #define PVIO_SET_ERROR if (pvio->set_error) \
  10. pvio->set_error
  11. #define PVIO_READ_AHEAD_CACHE_SIZE 16384
  12. #define PVIO_READ_AHEAD_CACHE_MIN_SIZE 2048
  13. #define PVIO_EINTR_TRIES 2
  14. struct st_ma_pvio_methods;
  15. typedef struct st_ma_pvio_methods PVIO_METHODS;
  16. #define IS_PVIO_ASYNC(a) \
  17. ((a)->mysql && (a)->mysql->options.extension && (a)->mysql->options.extension->async_context)
  18. #define IS_PVIO_ASYNC_ACTIVE(a) \
  19. (IS_PVIO_ASYNC(a)&& (a)->mysql->options.extension->async_context->active)
  20. #define IS_MYSQL_ASYNC(a) \
  21. ((a)->options.extension && (a)->options.extension->async_context)
  22. #define IS_MYSQL_ASYNC_ACTIVE(a) \
  23. (IS_MYSQL_ASYNC(a)&& (a)->options.extension->async_context->active)
  24. enum enum_pvio_timeout {
  25. PVIO_CONNECT_TIMEOUT= 0,
  26. PVIO_READ_TIMEOUT,
  27. PVIO_WRITE_TIMEOUT
  28. };
  29. enum enum_pvio_io_event
  30. {
  31. VIO_IO_EVENT_READ,
  32. VIO_IO_EVENT_WRITE,
  33. VIO_IO_EVENT_CONNECT
  34. };
  35. enum enum_pvio_type {
  36. PVIO_TYPE_UNIXSOCKET= 0,
  37. PVIO_TYPE_SOCKET,
  38. PVIO_TYPE_NAMEDPIPE,
  39. PVIO_TYPE_SHAREDMEM,
  40. };
  41. enum enum_pvio_operation {
  42. PVIO_READ= 0,
  43. PVIO_WRITE=1
  44. };
  45. #define SHM_DEFAULT_NAME "MYSQL"
  46. struct st_pvio_callback;
  47. typedef struct st_pvio_callback {
  48. void (*callback)(MYSQL *mysql, uchar *buffer, size_t size);
  49. struct st_pvio_callback *next;
  50. } PVIO_CALLBACK;
  51. struct st_ma_pvio {
  52. void *data;
  53. /* read ahead cache */
  54. uchar *cache;
  55. uchar *cache_pos;
  56. size_t cache_size;
  57. enum enum_pvio_type type;
  58. int timeout[3];
  59. int ssl_type; /* todo: change to enum (ssl plugins) */
  60. MARIADB_TLS *ctls;
  61. MYSQL *mysql;
  62. PVIO_METHODS *methods;
  63. void (*set_error)(MYSQL *mysql, unsigned int error_nr, const char *sqlstate, const char *format, ...);
  64. void (*callback)(MARIADB_PVIO *pvio, my_bool is_read, const uchar *buffer, size_t length);
  65. };
  66. typedef struct st_ma_pvio_cinfo
  67. {
  68. const char *host;
  69. const char *unix_socket;
  70. int port;
  71. enum enum_pvio_type type;
  72. MYSQL *mysql;
  73. } MA_PVIO_CINFO;
  74. struct st_ma_pvio_methods
  75. {
  76. my_bool (*set_timeout)(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout);
  77. int (*get_timeout)(MARIADB_PVIO *pvio, enum enum_pvio_timeout type);
  78. ssize_t (*read)(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
  79. ssize_t (*async_read)(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
  80. ssize_t (*write)(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
  81. ssize_t (*async_write)(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
  82. int (*wait_io_or_timeout)(MARIADB_PVIO *pvio, my_bool is_read, int timeout);
  83. my_bool (*blocking)(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value);
  84. my_bool (*connect)(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo);
  85. my_bool (*close)(MARIADB_PVIO *pvio);
  86. int (*fast_send)(MARIADB_PVIO *pvio);
  87. int (*keepalive)(MARIADB_PVIO *pvio);
  88. my_bool (*get_handle)(MARIADB_PVIO *pvio, void *handle);
  89. my_bool (*is_blocking)(MARIADB_PVIO *pvio);
  90. my_bool (*is_alive)(MARIADB_PVIO *pvio);
  91. my_bool (*has_data)(MARIADB_PVIO *pvio, ssize_t *data_len);
  92. int(*shutdown)(MARIADB_PVIO *pvio);
  93. };
  94. /* Function prototypes */
  95. MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo);
  96. void ma_pvio_close(MARIADB_PVIO *pvio);
  97. ssize_t ma_pvio_cache_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
  98. ssize_t ma_pvio_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
  99. ssize_t ma_pvio_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
  100. int ma_pvio_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type);
  101. my_bool ma_pvio_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout);
  102. int ma_pvio_fast_send(MARIADB_PVIO *pvio);
  103. int ma_pvio_keepalive(MARIADB_PVIO *pvio);
  104. my_socket ma_pvio_get_socket(MARIADB_PVIO *pvio);
  105. my_bool ma_pvio_is_blocking(MARIADB_PVIO *pvio);
  106. my_bool ma_pvio_blocking(MARIADB_PVIO *pvio, my_bool block, my_bool *previous_mode);
  107. my_bool ma_pvio_is_blocking(MARIADB_PVIO *pvio);
  108. int ma_pvio_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout);
  109. my_bool ma_pvio_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo);
  110. my_bool ma_pvio_is_alive(MARIADB_PVIO *pvio);
  111. my_bool ma_pvio_get_handle(MARIADB_PVIO *pvio, void *handle);
  112. my_bool ma_pvio_has_data(MARIADB_PVIO *pvio, ssize_t *length);
  113. #endif /* _ma_pvio_h_ */