lwtarantool 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab63cfa8741750b2251ba60df2ac2a7fd993776f
4
- data.tar.gz: 8d7bfe89af4560f6e4669e6dbe75a6279a9a9d1d
3
+ metadata.gz: 840c16fb6c833ca1e15ac1bf0fa66ffe6cac3e8f
4
+ data.tar.gz: 179d4af7160d0c4d4313444da922832c93ef70c9
5
5
  SHA512:
6
- metadata.gz: 8a8573ef486d4bb5e45c8fe3f864a7b42448823de3d9bdec26538554c4b89649a4a74a3fc52946f43d6b92be930e599e1e900ced3f17b955f6d6a3dd16e93a23
7
- data.tar.gz: 6011994dee0bf850ab0c013d87a3d7c0a7bbbfbc6617de09b9b884a25cee6cd4cb3bbd7ecf4e5acae403763571d8cdc533bb7bc9fe8ab9b7ba5e3851a6778da0
6
+ metadata.gz: f194dcb042b4c5c2e3c27a1e70087f6fcf634802976575436e78042b0e637337d4079ad9cab298bc377c3604ef26084097dd5cbbf3b436319557742e2e9f49ed
7
+ data.tar.gz: 699ee21bcc77d952efa4bbbd4abe31c3268ef61c04ae2cd1f62030b6b56dc7a74843d121e25566e96bff38e98a2dd1de7c4a07b091b4e329ffcba5a269710328
@@ -68,26 +68,26 @@ static void
68
68
  lwt_conn_raise_error(lwt_conn_t *conn) {
69
69
  switch(tnt_error(conn->tnt)) {
70
70
  case TNT_EMEMORY:
71
- rb_raise(rb_eNoMemError, tnt_strerror(conn->tnt));
71
+ rb_raise(rb_eNoMemError, "%s", tnt_strerror(conn->tnt));
72
72
  break;
73
73
  case TNT_ERESOLVE:
74
- rb_raise(lwt_eResolvError, tnt_strerror(conn->tnt));
74
+ rb_raise(lwt_eResolvError, "%s", tnt_strerror(conn->tnt));
75
75
  break;
76
76
  case TNT_ETMOUT:
77
- rb_raise(lwt_eTimeoutError, tnt_strerror(conn->tnt));
77
+ rb_raise(lwt_eTimeoutError, "%s", tnt_strerror(conn->tnt));
78
78
  break;
79
79
  case TNT_ELOGIN:
80
- rb_raise(lwt_eLoginError, tnt_strerror(conn->tnt));
80
+ rb_raise(lwt_eLoginError, "%s", tnt_strerror(conn->tnt));
81
81
  break;
82
82
  case TNT_ESYSTEM:
83
- rb_raise(lwt_eSystemError, tnt_strerror(conn->tnt));
83
+ rb_raise(lwt_eSystemError, "%s", tnt_strerror(conn->tnt));
84
84
  break;
85
85
  case TNT_EBIG:
86
- rb_raise(lwt_eTooLargeRequestError, tnt_strerror(conn->tnt));
86
+ rb_raise(lwt_eTooLargeRequestError, "%s", tnt_strerror(conn->tnt));
87
87
  break;
88
88
  case TNT_EFAIL:
89
89
  default:
90
- rb_raise(lwt_eUnknownError, tnt_strerror(conn->tnt));
90
+ rb_raise(lwt_eUnknownError, "%s", tnt_strerror(conn->tnt));
91
91
  break;
92
92
  }
93
93
  }
@@ -114,6 +114,48 @@ lwt_conn_disconnect(VALUE self) {
114
114
  return Qtrue;
115
115
  }
116
116
 
117
+ void
118
+ _lwt_conn_set_num_option(VALUE args, const char *option, lwt_conn_t *conn, enum tnt_opt_type tnt_opt) {
119
+ VALUE val;
120
+
121
+ val = rb_hash_aref(args, ID2SYM(rb_intern(option)));
122
+
123
+ if (TYPE(val) == T_NIL)
124
+ return;
125
+
126
+ if (TYPE(val) != T_FIXNUM)
127
+ rb_raise(rb_eArgError, "%s must be an Integer", option);
128
+
129
+ if (tnt_set(conn->tnt, tnt_opt, rb_fix2uint(val)) != 0)
130
+ rb_raise(rb_eArgError, "invalid %s value", option);
131
+ }
132
+
133
+ void
134
+ _lwt_conn_set_timeval_option(VALUE args, const char *option, lwt_conn_t *conn, enum tnt_opt_type tnt_opt) {
135
+ VALUE val;
136
+ double timeout_sec, timeout_usec;
137
+ struct timeval tnt_opt_val;
138
+
139
+ val = rb_hash_aref(args, ID2SYM(rb_intern(option)));
140
+
141
+ if (TYPE(val) == T_NIL)
142
+ return;
143
+
144
+ if (TYPE(val) != T_FIXNUM && TYPE(val) != T_FLOAT)
145
+ rb_raise(rb_eArgError, "%s must be an Integer", option);
146
+
147
+ timeout_usec = modf(rb_num2dbl(val), &timeout_sec);
148
+
149
+ if (timeout_sec < 0)
150
+ rb_raise(rb_eArgError, "%s < 0", option);
151
+
152
+ tnt_opt_val.tv_sec = (unsigned long) timeout_sec;
153
+ tnt_opt_val.tv_usec = (unsigned long) (timeout_usec * 1000000);
154
+
155
+ if (tnt_set(conn->tnt, tnt_opt, &tnt_opt_val) != 0)
156
+ rb_raise(rb_eArgError, "invalid %s value", option);
157
+ }
158
+
117
159
  /**
118
160
  * Document-class: LWTarantool::Connection
119
161
  *
@@ -123,6 +165,8 @@ lwt_conn_disconnect(VALUE self) {
123
165
  * @option args [String] :url The tarantool address
124
166
  * @option args [Integer] :recv_buf_size Receive buffer size (unknown effect)
125
167
  * @option args [Integer] :send_buf_size Send buffer size (maximum request size)
168
+ * @option args [Integer] :connect_timeout Timeout for establish tcp connection to Tarantool
169
+ * @option args [Integer] :open_timeout The same as connect_timeout
126
170
  *
127
171
  * @example
128
172
  * LWTarantool::Connection.new(url: 'tcp://127.0.0.1:3301')
@@ -148,25 +192,14 @@ lwt_conn_initialize(VALUE self, VALUE args) {
148
192
  if (TYPE(args) != T_HASH)
149
193
  rb_raise(rb_eArgError, "args must be a Hash");
150
194
 
151
- // handle recv_buf_size option
152
- val = rb_hash_aref(args, ID2SYM(rb_intern( "recv_buf_size")));
153
- if (TYPE(val) != T_NIL) {
154
- if (TYPE(val) != T_FIXNUM)
155
- rb_raise(rb_eArgError, "recv_buf_size must be an Integer");
156
-
157
- if (tnt_set(conn->tnt, TNT_OPT_RECV_BUF, rb_fix2uint(val)) != 0)
158
- rb_raise(rb_eArgError, "invalid recv_buf_size value");
159
- }
195
+ _lwt_conn_set_num_option(args, "recv_buf_size", conn, TNT_OPT_RECV_BUF);
196
+ _lwt_conn_set_num_option(args, "send_buf_size", conn, TNT_OPT_SEND_BUF);
197
+ _lwt_conn_set_timeval_option(args, "connect_timeout", conn, TNT_OPT_TMOUT_CONNECT);
198
+ _lwt_conn_set_timeval_option(args, "open_timeout", conn, TNT_OPT_TMOUT_CONNECT);
160
199
 
161
- // handle send_buf_size option
162
- val = rb_hash_aref(args, ID2SYM(rb_intern( "send_buf_size")));
163
- if (TYPE(val) != T_NIL) {
164
- if (TYPE(val) != T_FIXNUM)
165
- rb_raise(rb_eArgError, "send_buf_size must be an Integer");
166
-
167
- if (tnt_set(conn->tnt, TNT_OPT_SEND_BUF, rb_fix2uint(val)) != 0)
168
- rb_raise(rb_eArgError, "invalid send_buf_size value");
169
- }
200
+ // TODO: How should we process a partial read/write before timeout?
201
+ //_lwt_conn_set_timeval_option(args, "receive_timeout", conn, TNT_OPT_TMOUT_RECV);
202
+ //_lwt_conn_set_timeval_option(args, "send_timeout", conn, TNT_OPT_TMOUT_SEND);
170
203
 
171
204
  // handle url option
172
205
  val = rb_hash_aref(args, ID2SYM(rb_intern( "url")));
@@ -244,17 +277,26 @@ lwt_conn_read(VALUE self) {
244
277
  int rc = conn->tnt->read_reply(conn->tnt, reply);
245
278
  //printf("sync: %d, code: %d, err: %d, errno: %d, strerr: %s\n", rc, reply->sync, reply->code, tnt_error(conn->tnt), tnt_errno(conn->tnt), tnt_strerror(conn->tnt));
246
279
 
247
- if (rc == 1)
280
+ if (rc == 1) {
281
+ tnt_reply_free(reply);
248
282
  return Qnil;
283
+ }
249
284
 
250
- if (rc == -1)
285
+ if (rc == -1) {
286
+ tnt_reply_free(reply);
251
287
  lwt_conn_raise_error(conn);
288
+ }
252
289
 
253
- if (rc != 0)
290
+ if (rc != 0) {
291
+ tnt_reply_free(reply);
254
292
  rb_raise( lwt_eUnknownError, "read_reply() return code %d", rc);
293
+ }
255
294
 
256
- if (st_delete(conn->requests, &reply->sync, &req) != 1)
257
- rb_raise(lwt_eSyncError, "Bad sync id %lu in tarantool reply", reply->sync);
295
+ if (st_delete(conn->requests, &reply->sync, &req) != 1) {
296
+ int sync = reply->sync;
297
+ tnt_reply_free(reply);
298
+ rb_raise(lwt_eSyncError, "Bad sync id %lu in tarantool reply", sync);
299
+ }
258
300
 
259
301
  lwt_request_add_reply( req, reply);
260
302
 
@@ -3,6 +3,18 @@
3
3
 
4
4
  static VALUE rClass;
5
5
 
6
+ static void
7
+ lwt_request_dealloc(lwt_request_t *req) {
8
+ if (req == NULL)
9
+ return;
10
+
11
+ if (req->reply == NULL)
12
+ return;
13
+
14
+ tnt_reply_free(req->reply);
15
+ }
16
+
17
+
6
18
  VALUE
7
19
  lwt_request_create( VALUE conn, uint64_t id) {
8
20
  VALUE self;
@@ -11,7 +23,7 @@ lwt_request_create( VALUE conn, uint64_t id) {
11
23
  req = ZALLOC(lwt_request_t);
12
24
  req->id = id;
13
25
 
14
- self = Data_Wrap_Struct( rClass, NULL, NULL, req);
26
+ self = Data_Wrap_Struct( rClass, NULL, lwt_request_dealloc, req);
15
27
  rb_iv_set(self, "@conn", conn);
16
28
 
17
29
  //printf("Create request %p, reply: %p\n", req, req->reply);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lwtarantool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Golovko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-20 00:00:00.000000000 Z
11
+ date: 2019-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack