trilogy 2.6.0 → 2.6.1

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: a56e3472569e26552e3c8d7a674b70d9f5e15a546187f75e806f4d56ff5f15b2
4
- data.tar.gz: a2c29dc1fcf378be7a26088661401d9d4e7d4253c6823f8e7e84414662947cb1
3
+ metadata.gz: d015527cefe1e66b73b4db1d31b98e3db6ab616edb1fb2da947054a55818f338
4
+ data.tar.gz: 315bdd0e7dabf0f37ed69f5cd0884a702a7502443b1e26e5b01bec90b122e11d
5
5
  SHA512:
6
- metadata.gz: 0f3348ccdf12ae3cef0c34f95e09829528a0bdb09b466774a1a8369fdeae6f4d1fb59df96b1d17e5361aea4656968b5e2149ffbf9fe8337b17d45f0903408122
7
- data.tar.gz: 33711de128dd47aeff4ab618d0c3b6032e966b1b52b7dad6352e1588f5d13e54df2d4709c97c006ec63d1fa603a1f190abd58784cea835d26be6c1f56da5b46c
6
+ metadata.gz: b6e50321b8493b6ea8137d534e0fa8eedc5b7388093fee5e910dbe8c6bd81c0e0dc9c8d9c448895096fb8bd0244a0ee65b19b5f580c3b9137c76c9af221f0ab2
7
+ data.tar.gz: 7d8b81caf8faaadc4ef548ffddab7a73f9b8d4d6ede5a0f9078c6ea65cd195f83bdcacdf5a3d7b71d76503161a689d8ac66b058a4c605a915f9a9dcf4aa56cdd
data/README.md CHANGED
@@ -27,7 +27,6 @@ $ gem install trilogy
27
27
  ``` ruby
28
28
  client = Trilogy.new(host: "127.0.0.1", port: 3306, username: "root", read_timeout: 2)
29
29
  if client.ping
30
- client.query_options[:database_timezone] = :utc
31
30
  client.change_db "mydb"
32
31
 
33
32
  result = client.query("SELECT id, created_at FROM users LIMIT 10")
@@ -63,7 +62,7 @@ bundle exec rake build
63
62
 
64
63
  The official Ruby bindings are inside of the canonical trilogy repository itself.
65
64
 
66
- 1. Fork it ( https://github.com/github/trilogy/fork )
65
+ 1. Fork it ( https://github.com/trilogy-libraries/trilogy/fork )
67
66
  2. Create your feature branch (`git checkout -b my-new-feature`)
68
67
  3. Commit your changes (`git commit -am 'Add some feature'`)
69
68
  4. Push to the branch (`git push origin my-new-feature`)
@@ -43,9 +43,7 @@ static void mark_trilogy(void *ptr)
43
43
  static void free_trilogy(void *ptr)
44
44
  {
45
45
  struct trilogy_ctx *ctx = ptr;
46
- if (ctx->conn.socket != NULL) {
47
- trilogy_free(&ctx->conn);
48
- }
46
+ trilogy_free(&ctx->conn);
49
47
  xfree(ptr);
50
48
  }
51
49
 
@@ -309,6 +307,7 @@ static int try_connect(struct trilogy_ctx *ctx, trilogy_handshake_t *handshake,
309
307
  int rc = args.rc;
310
308
 
311
309
  if (rc != TRILOGY_OK) {
310
+ trilogy_sock_close(sock);
312
311
  return rc;
313
312
  }
314
313
 
@@ -316,8 +315,10 @@ static int try_connect(struct trilogy_ctx *ctx, trilogy_handshake_t *handshake,
316
315
  escape the GVL on each wait operation without going through call_without_gvl */
317
316
  sock->wait_cb = _cb_ruby_wait;
318
317
  rc = trilogy_connect_send_socket(&ctx->conn, sock);
319
- if (rc < 0)
318
+ if (rc < 0) {
319
+ trilogy_sock_close(sock);
320
320
  return rc;
321
+ }
321
322
 
322
323
  while (1) {
323
324
  rc = trilogy_connect_recv(&ctx->conn, handshake);
@@ -425,7 +426,7 @@ static void authenticate(struct trilogy_ctx *ctx, trilogy_handshake_t *handshake
425
426
  }
426
427
  }
427
428
 
428
- static VALUE rb_trilogy_initialize(VALUE self, VALUE encoding, VALUE charset, VALUE opts)
429
+ static VALUE rb_trilogy_connect(VALUE self, VALUE encoding, VALUE charset, VALUE opts)
429
430
  {
430
431
  struct trilogy_ctx *ctx = get_ctx(self);
431
432
  trilogy_sockopt_t connopt = {0};
@@ -436,7 +437,6 @@ static VALUE rb_trilogy_initialize(VALUE self, VALUE encoding, VALUE charset, VA
436
437
  connopt.encoding = NUM2INT(charset);
437
438
 
438
439
  Check_Type(opts, T_HASH);
439
- rb_ivar_set(self, id_connection_options, opts);
440
440
 
441
441
  if ((val = rb_hash_lookup(opts, ID2SYM(id_ssl_mode))) != Qnil) {
442
442
  Check_Type(val, T_FIXNUM);
@@ -578,9 +578,6 @@ static VALUE rb_trilogy_initialize(VALUE self, VALUE encoding, VALUE charset, VA
578
578
  }
579
579
 
580
580
  int rc = try_connect(ctx, &handshake, &connopt);
581
- if (rc == TRILOGY_TIMEOUT) {
582
- rb_raise(Trilogy_TimeoutError, "trilogy_connect_recv");
583
- }
584
581
  if (rc != TRILOGY_OK) {
585
582
  if (connopt.path) {
586
583
  handle_trilogy_error(ctx, rc, "trilogy_connect - unable to connect to %s", connopt.path);
@@ -1104,7 +1101,7 @@ RUBY_FUNC_EXPORTED void Init_cext()
1104
1101
  VALUE Trilogy = rb_const_get(rb_cObject, rb_intern("Trilogy"));
1105
1102
  rb_define_alloc_func(Trilogy, allocate_trilogy);
1106
1103
 
1107
- rb_define_private_method(Trilogy, "_initialize", rb_trilogy_initialize, 3);
1104
+ rb_define_private_method(Trilogy, "_connect", rb_trilogy_connect, 3);
1108
1105
  rb_define_method(Trilogy, "change_db", rb_trilogy_change_db, 1);
1109
1106
  rb_define_alias(Trilogy, "select_db", "change_db");
1110
1107
  rb_define_method(Trilogy, "query", rb_trilogy_query, 1);
@@ -2,8 +2,12 @@ require "mkmf"
2
2
 
3
3
  # concatenate trilogy library sources to allow the compiler to optimise across
4
4
  # source files
5
+
6
+ trilogy_src_dir = File.realpath("src", __dir__)
5
7
  File.binwrite("trilogy.c",
6
- Dir["#{__dir__}/src/**/*.c"].map { |src| File.binread(src) }.join)
8
+ Dir["#{trilogy_src_dir}/**/*.c"].map { |src|
9
+ %{#line 1 "#{src}"\n} + File.binread(src)
10
+ }.join)
7
11
 
8
12
  $objs = %w[trilogy.o cast.o cext.o]
9
13
  $CFLAGS << " -I #{__dir__}/inc -std=gnu99 -fvisibility=hidden"
@@ -57,4 +57,9 @@ int trilogy_buffer_putc(trilogy_buffer_t *buffer, uint8_t c)
57
57
  return TRILOGY_OK;
58
58
  }
59
59
 
60
- void trilogy_buffer_free(trilogy_buffer_t *buffer) { free(buffer->buff); }
60
+ void trilogy_buffer_free(trilogy_buffer_t *buffer)
61
+ {
62
+ free(buffer->buff);
63
+ buffer->buff = NULL;
64
+ buffer->len = buffer->cap = 0;
65
+ }
@@ -100,8 +100,15 @@ static int _cb_raw_close(trilogy_sock_t *_sock)
100
100
  if (sock->fd != -1) {
101
101
  rc = close(sock->fd);
102
102
  }
103
+
103
104
  if (sock->addr) {
104
- freeaddrinfo(sock->addr);
105
+ if (sock->base.opts.hostname == NULL && sock->base.opts.path != NULL) {
106
+ /* We created these with calloc so must free them instead of calling freeaddrinfo */
107
+ free(sock->addr->ai_addr);
108
+ free(sock->addr);
109
+ } else {
110
+ freeaddrinfo(sock->addr);
111
+ }
105
112
  }
106
113
 
107
114
  free(sock->base.opts.hostname);
@@ -189,6 +196,7 @@ static int raw_connect_internal(struct trilogy_sock *sock, const struct addrinfo
189
196
  {
190
197
  int sockerr;
191
198
  socklen_t sockerr_len = sizeof(sockerr);
199
+ int rc = TRILOGY_SYSERR;
192
200
 
193
201
  sock->fd = socket(ai->ai_family, SOCK_STREAM, ai->ai_protocol);
194
202
  if (sock->fd < 0) {
@@ -244,8 +252,8 @@ static int raw_connect_internal(struct trilogy_sock *sock, const struct addrinfo
244
252
  }
245
253
  }
246
254
 
247
- if (trilogy_sock_wait_write((trilogy_sock_t *)sock) < 0) {
248
- goto fail;
255
+ if ((rc = trilogy_sock_wait_write((trilogy_sock_t *)sock)) < 0) {
256
+ goto failrc;
249
257
  }
250
258
 
251
259
  if (getsockopt(sock->fd, SOL_SOCKET, SO_ERROR, &sockerr, &sockerr_len) < 0) {
@@ -263,9 +271,11 @@ static int raw_connect_internal(struct trilogy_sock *sock, const struct addrinfo
263
271
  return TRILOGY_OK;
264
272
 
265
273
  fail:
274
+ rc = TRILOGY_SYSERR;
275
+ failrc:
266
276
  close(sock->fd);
267
277
  sock->fd = -1;
268
- return TRILOGY_SYSERR;
278
+ return rc;
269
279
  }
270
280
 
271
281
  static int _cb_raw_connect(trilogy_sock_t *_sock)
@@ -377,6 +387,9 @@ static ssize_t ssl_io_return(struct trilogy_sock *sock, ssize_t ret)
377
387
  int rc = SSL_get_error(sock->ssl, (int)ret);
378
388
  if (rc == SSL_ERROR_WANT_WRITE || rc == SSL_ERROR_WANT_READ) {
379
389
  return (ssize_t)TRILOGY_AGAIN;
390
+ } else if (rc == SSL_ERROR_ZERO_RETURN) {
391
+ // Server has closed the connection for writing by sending the close_notify alert
392
+ return (ssize_t)TRILOGY_CLOSED_CONNECTION;
380
393
  } else if (rc == SSL_ERROR_SYSCALL && !ERR_peek_error()) {
381
394
  if (errno == 0) {
382
395
  // On OpenSSL <= 1.1.1, SSL_ERROR_SYSCALL with an errno value
data/lib/trilogy/error.rb CHANGED
@@ -117,7 +117,7 @@ class Trilogy
117
117
  include ConnectionError
118
118
  end
119
119
 
120
- # Occurrs when a socket read or write returns EOF or when an operation is
120
+ # Occurs when a socket read or write returns EOF or when an operation is
121
121
  # attempted on a socket which previously encountered an error.
122
122
  class EOFError < BaseConnectionError
123
123
  end
@@ -1,3 +1,3 @@
1
1
  class Trilogy
2
- VERSION = "2.6.0"
2
+ VERSION = "2.6.1"
3
3
  end
data/lib/trilogy.rb CHANGED
@@ -12,8 +12,10 @@ class Trilogy
12
12
  mysql_encoding = options[:encoding] || "utf8mb4"
13
13
  encoding = Trilogy::Encoding.find(mysql_encoding)
14
14
  charset = Trilogy::Encoding.charset(mysql_encoding)
15
+ @connection_options = options
16
+ @connected_host = nil
15
17
 
16
- _initialize(encoding, charset, options)
18
+ _connect(encoding, charset, options)
17
19
  end
18
20
 
19
21
  def connection_options
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trilogy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0
4
+ version: 2.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-18 00:00:00.000000000 Z
11
+ date: 2024-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler