rbczmq 1.7.3 → 1.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.rdoc +4 -0
- data/Gemfile.lock +2 -2
- data/ext/rbczmq/socket.c +65 -18
- data/ext/rbczmq/socket.h +2 -0
- data/lib/zmq/version.rb +1 -1
- data/test/test_socket.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OWI3ZDU3NzMwMTQ5NzEwYTY1MzkwYzA3NmQzYmY2YjE5YzI0NmM5MQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTlhN2Q2NzM1NzYxZjNlMjEzOWM3ZTVkNmYyM2FiMmQzYzE2NzIyYQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzEzNjBiMTI2YmI3MGZkYjcyNjkzY2I1ODA2YWRhYzRjZGQ2ZTUzMzNkNzk4
|
10
|
+
MmQzNWIxMTExOTkwNWU4NzI3ZjZkNmVlOTVjY2U0MDE4MWQzMTYxNDhjMmU4
|
11
|
+
NjIyODg0ZGMxMjdjZWRmZjExOWMyZTA2OTAyNDY5ZTcyMmJkMDk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Mzg3MDk5M2E1MjIwOGU3Yjg2NjlkMWZlMGNmYjM2NDE2NWQ5MTM2N2RhM2Y1
|
14
|
+
NTJiMDNiMTUyNTk0ZGM2ODRmYjc0YTE0NTA1MmRhZGU2NDM3NzY2OTA0NDEx
|
15
|
+
MGYxNTk1OGE1N2VmYzJhODdjNGE4MTFjMzRhMjBlZmNhMWJlYjg=
|
data/CHANGELOG.rdoc
CHANGED
data/Gemfile.lock
CHANGED
data/ext/rbczmq/socket.c
CHANGED
@@ -346,6 +346,25 @@ static VALUE rb_czmq_socket_set_verbose(VALUE obj, VALUE level)
|
|
346
346
|
return Qnil;
|
347
347
|
}
|
348
348
|
|
349
|
+
/*
|
350
|
+
* :nodoc:
|
351
|
+
*
|
352
|
+
* Based on czmq `s_send_string` to send a C string. We need to be able to support
|
353
|
+
* strings that contain null bytes, so we cannot use zstr_send as it is intended for
|
354
|
+
* null terminated C strings.
|
355
|
+
*/
|
356
|
+
static int rb_czmq_nogvl_zstr_send_internal(struct nogvl_send_args *args, int flags)
|
357
|
+
{
|
358
|
+
errno = 0;
|
359
|
+
zmq_sock_wrapper *socket = args->socket;
|
360
|
+
|
361
|
+
zmq_msg_t message;
|
362
|
+
zmq_msg_init_size(&message, args->length);
|
363
|
+
memcpy(zmq_msg_data(&message), args->msg, args->length);
|
364
|
+
int rc = zmq_sendmsg(socket->socket, &message, flags);
|
365
|
+
return (rc == -1? -1: 0);
|
366
|
+
}
|
367
|
+
|
349
368
|
/*
|
350
369
|
* :nodoc:
|
351
370
|
* Sends a raw string while the GIL is released.
|
@@ -355,8 +374,8 @@ static VALUE rb_czmq_nogvl_zstr_send(void *ptr)
|
|
355
374
|
{
|
356
375
|
struct nogvl_send_args *args = ptr;
|
357
376
|
errno = 0;
|
358
|
-
|
359
|
-
return (VALUE)
|
377
|
+
int rc = rb_czmq_nogvl_zstr_send_internal(args, 0);
|
378
|
+
return (VALUE)rc;
|
360
379
|
}
|
361
380
|
|
362
381
|
/*
|
@@ -368,8 +387,8 @@ static VALUE rb_czmq_nogvl_zstr_sendm(void *ptr)
|
|
368
387
|
{
|
369
388
|
struct nogvl_send_args *args = ptr;
|
370
389
|
errno = 0;
|
371
|
-
|
372
|
-
return (VALUE)
|
390
|
+
int rc = rb_czmq_nogvl_zstr_send_internal(args, ZMQ_SNDMORE);
|
391
|
+
return (VALUE)rc;
|
373
392
|
}
|
374
393
|
|
375
394
|
/*
|
@@ -394,9 +413,11 @@ static VALUE rb_czmq_socket_send(VALUE obj, VALUE msg)
|
|
394
413
|
GetZmqSocket(obj);
|
395
414
|
ZmqAssertSocketNotPending(sock, "can only send on a bound or connected socket!");
|
396
415
|
ZmqSockGuardCrossThread(sock);
|
397
|
-
Check_Type(msg, T_STRING);
|
398
416
|
args.socket = sock;
|
399
|
-
|
417
|
+
StringValue(msg);
|
418
|
+
Check_Type(msg, T_STRING);
|
419
|
+
args.msg = RSTRING_PTR(msg);
|
420
|
+
args.length = RSTRING_LEN(msg);
|
400
421
|
rc = (int)rb_thread_blocking_region(rb_czmq_nogvl_zstr_send, (void *)&args, RUBY_UBF_IO, 0);
|
401
422
|
ZmqAssert(rc);
|
402
423
|
if (sock->verbose)
|
@@ -427,9 +448,11 @@ static VALUE rb_czmq_socket_sendm(VALUE obj, VALUE msg)
|
|
427
448
|
GetZmqSocket(obj);
|
428
449
|
ZmqAssertSocketNotPending(sock, "can only send on a bound or connected socket!");
|
429
450
|
ZmqSockGuardCrossThread(sock);
|
430
|
-
Check_Type(msg, T_STRING);
|
431
451
|
args.socket = sock;
|
432
|
-
|
452
|
+
StringValue(msg);
|
453
|
+
Check_Type(msg, T_STRING);
|
454
|
+
args.msg = RSTRING_PTR(msg);
|
455
|
+
args.length = RSTRING_LEN(msg);
|
433
456
|
rc = (int)rb_thread_blocking_region(rb_czmq_nogvl_zstr_sendm, (void *)&args, RUBY_UBF_IO, 0);
|
434
457
|
ZmqAssert(rc);
|
435
458
|
if (sock->verbose)
|
@@ -447,7 +470,13 @@ static VALUE rb_czmq_nogvl_recv(void *ptr)
|
|
447
470
|
struct nogvl_recv_args *args = ptr;
|
448
471
|
errno = 0;
|
449
472
|
zmq_sock_wrapper *socket = args->socket;
|
450
|
-
|
473
|
+
|
474
|
+
// implement similar to zstr_recv, except that the copy to the string is done
|
475
|
+
// after we return with the GIL so that the ruby string object can be created
|
476
|
+
// from the zmq message buffer in a single copy.
|
477
|
+
assert (socket->socket);
|
478
|
+
int rc = zmq_recvmsg(socket->socket, &args->message, 0);
|
479
|
+
return (VALUE)rc;
|
451
480
|
}
|
452
481
|
|
453
482
|
/*
|
@@ -474,13 +503,21 @@ static VALUE rb_czmq_socket_recv(VALUE obj)
|
|
474
503
|
ZmqAssertSocketNotPending(sock, "can only receive on a bound or connected socket!");
|
475
504
|
ZmqSockGuardCrossThread(sock);
|
476
505
|
args.socket = sock;
|
477
|
-
|
478
|
-
|
506
|
+
zmq_msg_init(&args.message);
|
507
|
+
|
508
|
+
int rc = (int)rb_thread_blocking_region(rb_czmq_nogvl_recv, (void *)&args, RUBY_UBF_IO, 0);
|
509
|
+
if (rc < 0) {
|
510
|
+
zmq_msg_close(&args.message);
|
511
|
+
return Qnil;
|
512
|
+
}
|
479
513
|
ZmqAssertSysError();
|
480
514
|
if (sock->verbose)
|
481
515
|
zclock_log ("I: %s socket %p: recv \"%s\"", zsocket_type_str(sock->socket), sock->socket, str);
|
482
|
-
|
483
|
-
|
516
|
+
|
517
|
+
result = rb_str_new(zmq_msg_data(&args.message), zmq_msg_size(&args.message));
|
518
|
+
zmq_msg_close(&args.message);
|
519
|
+
|
520
|
+
result = ZmqEncode(result);
|
484
521
|
return result;
|
485
522
|
}
|
486
523
|
|
@@ -501,19 +538,29 @@ static VALUE rb_czmq_socket_recv(VALUE obj)
|
|
501
538
|
static VALUE rb_czmq_socket_recv_nonblock(VALUE obj)
|
502
539
|
{
|
503
540
|
char *str = NULL;
|
541
|
+
struct nogvl_recv_args args;
|
504
542
|
errno = 0;
|
505
543
|
VALUE result = Qnil;
|
506
544
|
zmq_sock_wrapper *sock = NULL;
|
507
545
|
GetZmqSocket(obj);
|
508
546
|
ZmqAssertSocketNotPending(sock, "can only receive on a bound or connected socket!");
|
509
547
|
ZmqSockGuardCrossThread(sock);
|
510
|
-
|
511
|
-
|
548
|
+
|
549
|
+
zmq_msg_init(&args.message);
|
550
|
+
|
551
|
+
int rc = zmq_recvmsg(sock->socket, &args.message, ZMQ_DONTWAIT);
|
552
|
+
if (rc < 0) {
|
553
|
+
zmq_msg_close(&args.message);
|
554
|
+
return Qnil;
|
555
|
+
}
|
512
556
|
ZmqAssertSysError();
|
513
557
|
if (sock->verbose)
|
514
|
-
zclock_log ("I: %s socket %p:
|
515
|
-
|
516
|
-
|
558
|
+
zclock_log ("I: %s socket %p: recv \"%s\"", zsocket_type_str(sock->socket), sock->socket, str);
|
559
|
+
|
560
|
+
result = rb_str_new(zmq_msg_data(&args.message), zmq_msg_size(&args.message));
|
561
|
+
zmq_msg_close(&args.message);
|
562
|
+
|
563
|
+
result = ZmqEncode(result);
|
517
564
|
return result;
|
518
565
|
}
|
519
566
|
|
data/ext/rbczmq/socket.h
CHANGED
@@ -102,6 +102,7 @@ void rb_czmq_free_sock_gc(void *ptr);
|
|
102
102
|
struct nogvl_send_args {
|
103
103
|
zmq_sock_wrapper *socket;
|
104
104
|
const char *msg;
|
105
|
+
long length;
|
105
106
|
bool read;
|
106
107
|
};
|
107
108
|
|
@@ -120,6 +121,7 @@ struct nogvl_send_message_args {
|
|
120
121
|
|
121
122
|
struct nogvl_recv_args {
|
122
123
|
zmq_sock_wrapper *socket;
|
124
|
+
zmq_msg_t message;
|
123
125
|
};
|
124
126
|
|
125
127
|
struct nogvl_socket_poll_args {
|
data/lib/zmq/version.rb
CHANGED
data/test/test_socket.rb
CHANGED
@@ -275,6 +275,19 @@ class TestZmqSocket < ZmqTestCase
|
|
275
275
|
ensure
|
276
276
|
ctx.destroy
|
277
277
|
end
|
278
|
+
|
279
|
+
def test_send_receive_with_null_in_string
|
280
|
+
string = [1,0,1,2,3,4,5].pack('c*')
|
281
|
+
ctx = ZMQ::Context.new
|
282
|
+
rep = ctx.socket(:PAIR)
|
283
|
+
rep.bind("inproc://test.socket-send_receive")
|
284
|
+
req = ctx.socket(:PAIR)
|
285
|
+
req.connect("inproc://test.socket-send_receive")
|
286
|
+
assert req.send(string)
|
287
|
+
assert_equal string, rep.recv
|
288
|
+
ensure
|
289
|
+
ctx.destroy
|
290
|
+
end
|
278
291
|
|
279
292
|
def test_verbose
|
280
293
|
ctx = ZMQ::Context.new
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbczmq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lourens Naudé
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-11-
|
13
|
+
date: 2013-11-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake-compiler
|