Skip to content

Commit 36a7b1a

Browse files
authored
Merge pull request ged#614 from larskanis/cancon
Add support for new query cancel functions of PostgreSQL-17
2 parents 209f345 + 67733e4 commit 36a7b1a

File tree

12 files changed

+660
-134
lines changed

12 files changed

+660
-134
lines changed

ext/gvl_wrappers.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ PGresult *PQclosePortal(PGconn *conn, const char *portalName){return NULL;}
1212
int PQsendClosePrepared(PGconn *conn, const char *stmtName){return 0;}
1313
int PQsendClosePortal(PGconn *conn, const char *portalName){return 0;}
1414
int PQsendPipelineSync(PGconn *conn){return 0;}
15+
int PQcancelBlocking(PGcancelConn *cancelConn){return 0;}
16+
int PQcancelStart(PGcancelConn *cancelConn){return 0;}
17+
PostgresPollingStatusType PQcancelPoll(PGcancelConn *cancelConn){return PGRES_POLLING_FAILED;}
1518
#endif
1619
#ifndef HAVE_PQENTERPIPELINEMODE
1720
int PQpipelineSync(PGconn *conn){return 0;}

ext/gvl_wrappers.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
# include RUBY_EXTCONF_H
2222
#endif
2323

24+
#ifndef HAVE_PQSETCHUNKEDROWSMODE
25+
typedef struct pg_cancel_conn PGcancelConn;
26+
#endif
27+
2428
#define DEFINE_PARAM_LIST1(type, name) \
2529
name,
2630

@@ -217,6 +221,10 @@
217221

218222
#define FOR_EACH_PARAM_OF_PQisBusy(param)
219223

224+
#define FOR_EACH_PARAM_OF_PQcancelBlocking(param)
225+
#define FOR_EACH_PARAM_OF_PQcancelStart(param)
226+
#define FOR_EACH_PARAM_OF_PQcancelPoll(param)
227+
220228
#define FOR_EACH_PARAM_OF_PQencryptPasswordConn(param) \
221229
param(PGconn *, conn) \
222230
param(const char *, passwd) \
@@ -260,6 +268,9 @@
260268
function(PQsendPipelineSync, GVL_TYPE_NONVOID, int, PGconn *, conn) \
261269
function(PQsetClientEncoding, GVL_TYPE_NONVOID, int, const char *, encoding) \
262270
function(PQisBusy, GVL_TYPE_NONVOID, int, PGconn *, conn) \
271+
function(PQcancelBlocking, GVL_TYPE_NONVOID, int, PGcancelConn *, conn) \
272+
function(PQcancelStart, GVL_TYPE_NONVOID, int, PGcancelConn *, conn) \
273+
function(PQcancelPoll, GVL_TYPE_NONVOID, PostgresPollingStatusType, PGcancelConn *, conn) \
263274
function(PQencryptPasswordConn, GVL_TYPE_NONVOID, char *, const char *, algorithm) \
264275
function(PQcancel, GVL_TYPE_NONVOID, int, int, errbufsize);
265276

ext/pg.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,10 @@ Init_pg_ext(void)
404404
/* Checking if server is in standby mode. Available since PostgreSQL-14. */
405405
rb_define_const(rb_mPGconstants, "CONNECTION_CHECK_STANDBY", INT2FIX(CONNECTION_CHECK_STANDBY));
406406
#endif
407+
#if PG_MAJORVERSION_NUM >= 17
408+
/* Waiting for connection attempt to be started. Available since PostgreSQL-17. */
409+
rb_define_const(rb_mPGconstants, "CONNECTION_ALLOCATED", INT2FIX(CONNECTION_ALLOCATED));
410+
#endif
407411

408412
/****** PG::Connection CLASS CONSTANTS: Nonblocking connection polling status ******/
409413

@@ -689,4 +693,5 @@ Init_pg_ext(void)
689693
init_pg_copycoder();
690694
init_pg_recordcoder();
691695
init_pg_tuple();
696+
init_pg_cancon();
692697
}

ext/pg.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,8 @@ typedef struct {
116116
/* enable automatic flushing of send data at the end of send_query calls */
117117
unsigned int flush_data : 1;
118118

119-
#if defined(_WIN32)
120119
/* File descriptor to be used for rb_w32_unwrap_io_handle() */
121120
int ruby_sd;
122-
#endif
123121
} t_pg_connection;
124122

125123
typedef struct pg_coder t_pg_coder;
@@ -305,6 +303,7 @@ void init_pg_text_decoder _(( void ));
305303
void init_pg_binary_encoder _(( void ));
306304
void init_pg_binary_decoder _(( void ));
307305
void init_pg_tuple _(( void ));
306+
void init_pg_cancon _(( void ));
308307
VALUE lookup_error_class _(( const char * ));
309308
VALUE pg_bin_dec_bytea _(( t_pg_coder*, const char *, int, int, int, int ));
310309
VALUE pg_text_dec_string _(( t_pg_coder*, const char *, int, int, int, int ));
@@ -344,6 +343,13 @@ void pg_typemap_compact _(( void * ));
344343
PGconn *pg_get_pgconn _(( VALUE ));
345344
t_pg_connection *pg_get_connection _(( VALUE ));
346345
VALUE pgconn_block _(( int, VALUE *, VALUE ));
346+
#ifdef __GNUC__
347+
__attribute__((format(printf, 3, 4)))
348+
#endif
349+
NORETURN(void pg_raise_conn_error _(( VALUE klass, VALUE self, const char *format, ...)));
350+
VALUE pg_wrap_socket_io _(( int sd, VALUE self, VALUE *p_socket_io, int *p_ruby_sd ));
351+
void pg_unwrap_socket_io _(( VALUE self, VALUE *p_socket_io, int ruby_sd ));
352+
347353

348354
VALUE pg_new_result _(( PGresult *, VALUE ));
349355
VALUE pg_new_result_autoclear _(( PGresult *, VALUE ));

0 commit comments

Comments
 (0)