pg 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1af2a36ecef18e9aefa719d6c5f4ed54e7269b598ea4e6c3e4e7794cdf596a32
4
- data.tar.gz: 64318d9ae8b95888748f0e64f0269a7412b112d3d13bfdba6ddabcc7d0aec61e
3
+ metadata.gz: 3339718d25beca7eef4d5961b44dddceb03bcaab93d0b5b27af1e56845345513
4
+ data.tar.gz: 95c026d833f3e45beb4bebf1089d8d2dfe398fffa4f7353e2b42daf572384c5c
5
5
  SHA512:
6
- metadata.gz: f3d7e7a6438f8fab628726c4e7e7f8b25b3f2681b7bd638eb2b2590f707d74d84ba933e2c1540398eba91355f0406a942ceb4752e22bab9a601fc8d668443c31
7
- data.tar.gz: 83fdd0650a23affc911b9871ea09a316e883fb993bac74a2e62bfaf54b466a2de6de98c2245c4b85ad29e8c09b13df35569553ddf01ac429ee2353ec5254185c
6
+ metadata.gz: c2bdb07724af0bda7f094b6060f3653cb98d4484e9de3e03856415dd7fb357c42a93205c477491d94d6d352f5d6a97cdb66c3f437da8376d666f276aa03c5753
7
+ data.tar.gz: 5765400174741c48119c146ec5b7e0111b3329fb6f08f5b6cd5abab4af6beb42a06c97876a48a872a92dab23aa80bf8fce2a1ca7c3f621927deb40df0b20813a
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,8 @@
1
+ == v1.1.3 [2018-09-06] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ - Revert opimization that was sometimes causing EBADF in rb_wait_for_single_fd().
4
+
5
+
1
6
  == v1.1.2 [2018-08-28] Michael Granger <ged@FaerieMUD.org>
2
7
 
3
8
  - Don't generate aliases for JOHAB encoding.
data/ext/pg.h CHANGED
@@ -101,9 +101,6 @@ typedef struct {
101
101
  /* Kind of PG::Coder object for casting COPY rows to ruby values */
102
102
  VALUE decoder_for_get_copy_data;
103
103
 
104
- /* The connection socket, used for rb_wait_for_single_fd() */
105
- int socket;
106
-
107
104
  /* enable/disable guessing size of PGresult's allocated memory */
108
105
  int guess_result_memsize;
109
106
  } t_pg_connection;
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * pg_connection.c - PG::Connection class extension
3
- * $Id: pg_connection.c,v be48d118eeed 2018/08/25 11:35:03 lars $
3
+ * $Id: pg_connection.c,v b49f54dc755b 2018/09/01 12:52:41 lars $
4
4
  *
5
5
  */
6
6
 
@@ -198,7 +198,6 @@ pgconn_s_allocate( VALUE klass )
198
198
  this->decoder_for_get_copy_data = Qnil;
199
199
  this->trace_stream = Qnil;
200
200
  this->external_encoding = Qnil;
201
- this->socket = -1;
202
201
  this->guess_result_memsize = 1;
203
202
 
204
203
  return self;
@@ -272,6 +271,7 @@ pgconn_init(int argc, VALUE *argv, VALUE self)
272
271
  this = pg_get_connection( self );
273
272
  conninfo = rb_funcall2( rb_cPGconn, rb_intern("parse_connect_args"), argc, argv );
274
273
  this->pgconn = gvl_PQconnectdb(StringValueCStr(conninfo));
274
+
275
275
  if(this->pgconn == NULL)
276
276
  rb_raise(rb_ePGerror, "PQconnectdb() unable to allocate structure");
277
277
 
@@ -281,10 +281,6 @@ pgconn_init(int argc, VALUE *argv, VALUE self)
281
281
  rb_exc_raise(error);
282
282
  }
283
283
 
284
- this->socket = PQsocket( this->pgconn );
285
- if ( this->socket < 0 )
286
- rb_raise(rb_eConnectionBad, "PQsocket() can't get socket descriptor");
287
-
288
284
  pgconn_set_default_encoding( self );
289
285
 
290
286
  if (rb_block_given_p()) {
@@ -335,10 +331,6 @@ pgconn_s_connect_start( int argc, VALUE *argv, VALUE klass )
335
331
  rb_exc_raise(error);
336
332
  }
337
333
 
338
- this->socket = PQsocket( this->pgconn );
339
- if ( this->socket < 0 )
340
- rb_raise(rb_eConnectionBad, "PQsocket() can't get socket descriptor");
341
-
342
334
  if ( rb_block_given_p() ) {
343
335
  return rb_ensure( rb_yield, rb_conn, pgconn_finish, rb_conn );
344
336
  }
@@ -2337,15 +2329,18 @@ pgconn_notifies(VALUE self)
2337
2329
  int rb_w32_wait_events( HANDLE *events, int num, DWORD timeout );
2338
2330
 
2339
2331
  static void *
2340
- wait_socket_readable( t_pg_connection *this, struct timeval *ptimeout, void *(*is_readable)(PGconn *) )
2332
+ wait_socket_readable( PGconn *conn, struct timeval *ptimeout, void *(*is_readable)(PGconn *) )
2341
2333
  {
2342
- PGconn *conn = this->pgconn;
2334
+ int sd = PQsocket( conn );
2343
2335
  void *retval;
2344
2336
  struct timeval aborttime={0,0}, currtime, waittime;
2345
2337
  DWORD timeout_milisec = INFINITE;
2346
2338
  DWORD wait_ret;
2347
2339
  WSAEVENT hEvent;
2348
2340
 
2341
+ if ( sd < 0 )
2342
+ rb_raise(rb_eConnectionBad, "PQsocket() can't get socket descriptor");
2343
+
2349
2344
  hEvent = WSACreateEvent();
2350
2345
 
2351
2346
  /* Check for connection errors (PQisBusy is true on connection errors) */
@@ -2360,7 +2355,7 @@ wait_socket_readable( t_pg_connection *this, struct timeval *ptimeout, void *(*i
2360
2355
  }
2361
2356
 
2362
2357
  while ( !(retval=is_readable(conn)) ) {
2363
- if ( WSAEventSelect(this->socket, hEvent, FD_READ|FD_CLOSE) == SOCKET_ERROR ) {
2358
+ if ( WSAEventSelect(sd, hEvent, FD_READ|FD_CLOSE) == SOCKET_ERROR ) {
2364
2359
  WSACloseEvent( hEvent );
2365
2360
  rb_raise( rb_eConnectionBad, "WSAEventSelect socket error: %d", WSAGetLastError() );
2366
2361
  }
@@ -2412,13 +2407,16 @@ wait_socket_readable( t_pg_connection *this, struct timeval *ptimeout, void *(*i
2412
2407
  /* non Win32 */
2413
2408
 
2414
2409
  static void *
2415
- wait_socket_readable( t_pg_connection *this, struct timeval *ptimeout, void *(*is_readable)(PGconn *))
2410
+ wait_socket_readable( PGconn *conn, struct timeval *ptimeout, void *(*is_readable)(PGconn *))
2416
2411
  {
2417
- PGconn *conn = this->pgconn;
2412
+ int sd = PQsocket( conn );
2418
2413
  int ret;
2419
2414
  void *retval;
2420
2415
  struct timeval aborttime={0,0}, currtime, waittime;
2421
2416
 
2417
+ if ( sd < 0 )
2418
+ rb_raise(rb_eConnectionBad, "PQsocket() can't get socket descriptor");
2419
+
2422
2420
  /* Check for connection errors (PQisBusy is true on connection errors) */
2423
2421
  if ( PQconsumeInput(conn) == 0 )
2424
2422
  rb_raise( rb_eConnectionBad, "PQconsumeInput() %s", PQerrorMessage(conn) );
@@ -2437,7 +2435,7 @@ wait_socket_readable( t_pg_connection *this, struct timeval *ptimeout, void *(*i
2437
2435
  /* Is the given timeout valid? */
2438
2436
  if( !ptimeout || (waittime.tv_sec >= 0 && waittime.tv_usec >= 0) ){
2439
2437
  /* Wait for the socket to become readable before checking again */
2440
- ret = rb_wait_for_single_fd( this->socket, RB_WAITFD_IN, ptimeout ? &waittime : NULL );
2438
+ ret = rb_wait_for_single_fd( sd, RB_WAITFD_IN, ptimeout ? &waittime : NULL );
2441
2439
  } else {
2442
2440
  ret = 0;
2443
2441
  }
@@ -2484,7 +2482,7 @@ notify_readable(PGconn *conn)
2484
2482
  static VALUE
2485
2483
  pgconn_wait_for_notify(int argc, VALUE *argv, VALUE self)
2486
2484
  {
2487
- t_pg_connection *this = pg_get_connection_safe( self );
2485
+ PGconn *conn = pg_get_pgconn( self );
2488
2486
  PGnotify *pnotification;
2489
2487
  struct timeval timeout;
2490
2488
  struct timeval *ptimeout = NULL;
@@ -2500,7 +2498,7 @@ pgconn_wait_for_notify(int argc, VALUE *argv, VALUE self)
2500
2498
  ptimeout = &timeout;
2501
2499
  }
2502
2500
 
2503
- pnotification = (PGnotify*) wait_socket_readable( this, ptimeout, notify_readable);
2501
+ pnotification = (PGnotify*) wait_socket_readable( conn, ptimeout, notify_readable);
2504
2502
 
2505
2503
  /* Return nil if the select timed out */
2506
2504
  if ( !pnotification ) return Qnil;
@@ -3078,7 +3076,7 @@ get_result_readable(PGconn *conn)
3078
3076
  */
3079
3077
  static VALUE
3080
3078
  pgconn_block( int argc, VALUE *argv, VALUE self ) {
3081
- t_pg_connection *this = pg_get_connection_safe( self );
3079
+ PGconn *conn = pg_get_pgconn( self );
3082
3080
 
3083
3081
  struct timeval timeout;
3084
3082
  struct timeval *ptimeout = NULL;
@@ -3093,7 +3091,7 @@ pgconn_block( int argc, VALUE *argv, VALUE self ) {
3093
3091
  ptimeout = &timeout;
3094
3092
  }
3095
3093
 
3096
- ret = wait_socket_readable( this, ptimeout, get_result_readable);
3094
+ ret = wait_socket_readable( conn, ptimeout, get_result_readable);
3097
3095
 
3098
3096
  if( !ret )
3099
3097
  return Qfalse;
data/lib/pg.rb CHANGED
@@ -35,10 +35,10 @@ end
35
35
  module PG
36
36
 
37
37
  # Library version
38
- VERSION = '1.1.2'
38
+ VERSION = '1.1.3'
39
39
 
40
40
  # VCS revision
41
- REVISION = %q$Revision: bbf57bf7e583 $
41
+ REVISION = %q$Revision: 6f611e78845a $
42
42
 
43
43
  class NotAllCopyDataRetrieved < PG::Error
44
44
  end
@@ -228,6 +228,22 @@ describe PG::Connection do
228
228
 
229
229
  res = @conn2.query("SELECT 4")
230
230
  end
231
+
232
+ it "can use conn.reset_start to restart the connection" do
233
+ ios = IO.pipe
234
+ conn = described_class.connect_start( @conninfo )
235
+ wait_for_polling_ok(conn)
236
+
237
+ # Close the two pipe file descriptors, so that the file descriptor of
238
+ # newly established connection is probably distinct from the previous one.
239
+ ios.each(&:close)
240
+ conn.reset_start
241
+ wait_for_polling_ok(conn)
242
+
243
+ # The new connection should work even when the file descriptor has changed.
244
+ expect( conn.exec("SELECT 1").values ).to eq([["1"]])
245
+ conn.close
246
+ end
231
247
  end
232
248
 
233
249
  it "raises proper error when sending fails" do
@@ -914,6 +930,20 @@ describe PG::Connection do
914
930
  expect { conn.finish }.to raise_error( PG::ConnectionBad, /connection is closed/i )
915
931
  end
916
932
 
933
+ it "can use conn.reset to restart the connection" do
934
+ ios = IO.pipe
935
+ conn = PG.connect( @conninfo )
936
+
937
+ # Close the two pipe file descriptors, so that the file descriptor of
938
+ # newly established connection is probably distinct from the previous one.
939
+ ios.each(&:close)
940
+ conn.reset
941
+
942
+ # The new connection should work even when the file descriptor has changed.
943
+ expect( conn.exec("SELECT 1").values ).to eq([["1"]])
944
+ conn.close
945
+ end
946
+
917
947
  it "closes the IO fetched from #socket_io when the connection is closed", :without_transaction, :socket_io do
918
948
  conn = PG.connect( @conninfo )
919
949
  io = conn.socket_io
@@ -939,7 +969,7 @@ describe PG::Connection do
939
969
  end
940
970
  serv.close
941
971
  expect{ conn.block }.to raise_error(PG::ConnectionBad, /server closed the connection unexpectedly/)
942
- expect{ conn.block }.to raise_error(PG::ConnectionBad, /connection not open/)
972
+ expect{ conn.block }.to raise_error(PG::ConnectionBad, /can't get socket descriptor/)
943
973
  end
944
974
 
945
975
  it "sets the fallback_application_name on new connections" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Granger
@@ -36,7 +36,7 @@ cert_chain:
36
36
  X0qdrKi+2aZZ0NGuFj9AItBsVmAvkBGIpX4TEKQp5haEbPpmaqO5nIIhV26PXmyT
37
37
  OMKv6pWsoS81vw5KAGBmfX8nht/Py90DQrbRvakATGI=
38
38
  -----END CERTIFICATE-----
39
- date: 2018-08-29 00:00:00.000000000 Z
39
+ date: 2018-09-07 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: hoe-mercurial
metadata.gz.sig CHANGED
Binary file