pigato 0.1.0 → 0.1.1

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: 0c027e75179b49f887920e909e6fa4d3d2998336
4
- data.tar.gz: 059d621ee85c2956532537886eb6aa58fe198c14
3
+ metadata.gz: 59fe6ec27b63289331f1bcc8dfe5bd56a273861e
4
+ data.tar.gz: d196156fb32ed9b50337a1e6b7d2af5d2aaaa5f2
5
5
  SHA512:
6
- metadata.gz: 9020e44ea14d0019ea231ab0e9e8135235764b07f57aa3af13144cc8ea10aa45f9b9d4a417258cc1060855cc868ef641231af0bb4181d0200a17043fa06d4eda
7
- data.tar.gz: 7874b6aa9f9c1aa280f48e7de899570abe370992d784c8c889c914b4e0ceb8804aef26a5998713944671c3a8ebd95497dc2845ef9b6f51d50d78e4270c85bd47
6
+ metadata.gz: c9c083863c48629c7b74f878af92f9b81d5a5aba14f9c585293a53cad91208baec1db9cc6d9064f20c05db2465ff9d2af0d67dea2e4e5c57eaba03238aceb3c0
7
+ data.tar.gz: 7a6065cba43176980abb835ee529e4199e82e38ea89628cf995c29587aaab01c10b9fa3385dd7b689d7e828df96730e7fe62da2c49389a9cc3ad5ca7a7c65d42
data/examples/client.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "rubygems"
4
- require "pigato"
4
+ require "#{File.dirname(__FILE__)}/../lib/pigato.rb"
5
5
 
6
6
  client = PigatoClient.new('tcp://localhost:55555')
7
7
  requests = 10
data/lib/pigato/client.rb CHANGED
@@ -1,71 +1,64 @@
1
- module Pigato
2
- class Client
3
- include MDP
1
+ require "json"
2
+ require "ffi-rzmq"
4
3
 
5
- attr_accessor :timeout
4
+ class PigatoClient
6
5
 
7
- def initialize broker
8
- @broker = broker
9
- @context = ZMQ::Context.new(1)
10
- @client = nil
11
- @poller = ZMQ::Poller.new
12
- @timeout = 2500
6
+ def initialize broker
7
+ @broker = broker
8
+ @context = ZMQ::Context.new(1)
9
+ @client = nil
10
+ @poller = ZMQ::Poller.new
13
11
 
14
- reconnect_to_broker
15
- end
16
-
17
- def send service, request, timeout = 2500
18
- request = [request.to_json]
12
+ reconnect_to_broker
13
+ end
19
14
 
20
- rid = 'RID' + (rand() * 1000000).to_s
21
- # Prefix request with protocol frames
22
- # Frame 0: empty (REQ emulation)
23
- # Frame 1: "MDPCxy" (six bytes, MDP/Client x.y)
24
- # Frame 2: Service name (printable string)
25
- request = [MDP::C_CLIENT, MDP::W_REQUEST, service, rid].concat(request)
26
- @client.send_strings request
15
+ def send service, request, timeout = 2500
16
+ request = [request.to_json]
27
17
 
28
- res = Array.new
29
- res << rid
18
+ rid = 'RID' + (rand() * 1000000).to_s
19
+ request = [Pigato::C_CLIENT, Pigato::W_REQUEST, service, rid].concat(request)
20
+ @client.send_strings request
30
21
 
31
- data = Array.new
32
- while 1 do
33
- chunk = _recv(timeout)
34
- data << chunk[4]
35
- break if chunk[0] == MDP::W_REPLY
36
- end
22
+ res = Array.new
23
+ res << rid
37
24
 
38
- res << data
39
- res
25
+ data = Array.new
26
+ while 1 do
27
+ chunk = _recv(timeout)
28
+ data << chunk[4]
29
+ break if chunk[0] == Pigato::W_REPLY
40
30
  end
41
31
 
42
- def _recv timeout
43
- items = @poller.poll(timeout)
44
- if items
45
- messages = []
46
- @client.recv_strings messages
32
+ res << data
33
+ res
34
+ end
47
35
 
48
- # header
49
- if messages.shift != MDP::C_CLIENT
50
- raise RuntimeError, "Not a valid MDP message"
51
- end
36
+ def _recv timeout
37
+ items = @poller.poll(timeout)
38
+ if items
39
+ messages = []
40
+ @client.recv_strings messages
52
41
 
53
- return messages
42
+ # header
43
+ if messages.shift != Pigato::C_CLIENT
44
+ raise RuntimeError, "Not a valid Pigato message"
54
45
  end
55
46
 
56
- nil
47
+ return messages
57
48
  end
58
49
 
59
- def reconnect_to_broker
60
- if @client
61
- @poller.deregister @client, ZMQ::DEALER
62
- end
50
+ nil
51
+ end
63
52
 
64
- @client = @context.socket ZMQ::DEALER
65
- @client.setsockopt ZMQ::LINGER, 0
66
- @client.setsockopt ZMQ::IDENTITY, "C" + (rand() * 10).to_s
67
- @client.connect @broker
68
- @poller.register @client, ZMQ::POLLIN
53
+ def reconnect_to_broker
54
+ if @client
55
+ @poller.deregister @client, ZMQ::DEALER
69
56
  end
57
+
58
+ @client = @context.socket ZMQ::DEALER
59
+ @client.setsockopt ZMQ::LINGER, 0
60
+ @client.setsockopt ZMQ::IDENTITY, "C" + (rand() * 10).to_s
61
+ @client.connect @broker
62
+ @poller.register @client, ZMQ::POLLIN
70
63
  end
71
64
  end
data/lib/pigato/proto.rb CHANGED
@@ -1,17 +1,10 @@
1
- module PIGATO
2
- module PROTO
3
- # This is the version of MDP/Client we implement
4
- C_CLIENT = "C"
5
-
6
- # This is the version of MDP/Worker we implement
7
- W_WORKER = "W"
8
-
9
- # MDP/Server commands, as strings
10
- W_READY = "1"
11
- W_REQUEST = "2"
12
- W_REPLY = "3"
13
- W_HEARTBEAT = "4"
14
- W_DISCONNECT = "5"
15
- W_REPLY_PARTIAL = "6"
16
- end
1
+ module Pigato
2
+ C_CLIENT = "C"
3
+ W_WORKER = "W"
4
+ W_READY = "1"
5
+ W_REQUEST = "2"
6
+ W_REPLY = "3"
7
+ W_HEARTBEAT = "4"
8
+ W_DISCONNECT = "5"
9
+ W_REPLY_PARTIAL = "6"
17
10
  end
@@ -1,3 +1,3 @@
1
1
  module Pigato
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/pigato.rb CHANGED
@@ -1,7 +1,3 @@
1
- require "json"
2
- require "ffi-rzmq"
3
- require "pigato/version"
4
- require "pigato/proto.rb"
5
-
6
- module Pigato
7
- end
1
+ require_relative "pigato/version.rb"
2
+ require_relative "pigato/proto.rb"
3
+ require_relative "pigato/client.rb"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pigato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paolo Ardoino