launch 1.0 → 2.0.0

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.
@@ -1,107 +0,0 @@
1
- require 'rubygems'
2
- require 'launch'
3
-
4
- ##
5
- # This is an echo server that runs using launchd on port 12345.
6
- #
7
- # To start, run:
8
- #
9
- # ruby echo.rb net.segment7.launch.echo.plist
10
- # launchctl load net.segment7.launch.echo.plist
11
- #
12
- # To use the echo server run:
13
- #
14
- # telnet localhost 12345
15
- #
16
- # To quit the echo server type ^] followed by ^D
17
- #
18
- # To stop run:
19
- #
20
- # launchctl unload net.segment7.launch.echo.plist
21
-
22
- class Echo
23
-
24
- include Launch
25
-
26
- def self.plist name
27
- file = File.expand_path __FILE__
28
- root = File.expand_path '../..', __FILE__
29
-
30
- plist = <<-PLIST
31
- <?xml version="1.0" encoding="UTF-8"?>
32
- <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
- <plist version="1.0">
34
- <dict>
35
- <key>Label</key>
36
- <string>#{name}</string>
37
- <key>ProgramArguments</key>
38
- <array>
39
- <string>#{Gem.ruby}</string>
40
- <string>-I#{root}/lib</string>
41
- <string>-I#{root}/ext</string>
42
- <string>#{file}</string>
43
- </array>
44
- <key>ServiceIPC</key>
45
- <true/>
46
- <key>Sockets</key>
47
- <dict>
48
- <key>EchoSocket</key>
49
- <dict>
50
- <key>SockServiceName</key>
51
- <string>12345</string>
52
- </dict>
53
- </dict>
54
- </dict>
55
- </plist>
56
- PLIST
57
-
58
- open name, 'w' do |io|
59
- io.write plist
60
- end
61
- end
62
-
63
- def initialize
64
- launch_checkin
65
- end
66
-
67
- ##
68
- # echo lines sent from +socket+
69
-
70
- def echo socket
71
- Thread.start do
72
- loop do
73
- socket.puts socket.gets
74
- end
75
- end
76
- end
77
-
78
- ##
79
- # Listens on +server+ for connections to echo on.
80
-
81
- def listen server
82
- Thread.start do
83
- loop do
84
- echo server.accept
85
- end
86
- end
87
- end
88
-
89
- ##
90
- # Starts listening on the sockets given by launchd and waits forever
91
-
92
- def run
93
- launch_sockets('EchoSocket', TCPServer).each do |server|
94
- listen server
95
- end
96
-
97
- sleep
98
- end
99
-
100
- end
101
-
102
- if ARGV.empty? then
103
- Echo.new.run
104
- else
105
- Echo.plist ARGV.first
106
- end
107
-
@@ -1,55 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'launch'
3
-
4
- class TestLaunch < MiniTest::Unit::TestCase
5
-
6
- include Launch
7
-
8
- def launch_message message
9
- @message = message
10
-
11
- return { 'response' => 'hash' }
12
- end
13
-
14
- def test_launch_checkin
15
- response = launch_checkin
16
-
17
- assert_equal Launch::Key::CHECKIN, @message
18
-
19
- expected = { 'response' => 'hash' }
20
-
21
- assert_equal expected, response
22
- assert_equal expected, @launch_checkin
23
- end
24
-
25
- def test_launch_sockets
26
- @launch_checkin = {
27
- Launch::JobKey::SOCKETS => {
28
- 'MySockets' => [STDIN.to_i, STDOUT.to_i]
29
- }
30
- }
31
-
32
- sockets = launch_sockets 'MySockets', IO
33
-
34
- assert_equal 2, sockets.length
35
-
36
- assert_instance_of IO, sockets.first
37
- assert_instance_of IO, sockets.last
38
-
39
- assert_equal [0, 1], sockets.map { |io| io.to_i }
40
- end
41
-
42
- def test_launch_sockets_none
43
- @launch_checkin = {
44
- Launch::JobKey::SOCKETS => {
45
- }
46
- }
47
-
48
- e = assert_raises Launch::Error do
49
- launch_sockets 'NoSockets', IO
50
- end
51
-
52
- assert_equal 'no sockets found for "NoSockets"', e.message
53
- end
54
-
55
- end
metadata.gz.sig DELETED
@@ -1,2 +0,0 @@
1
- }��K������g��1�OM��u+5��U#_�&���a�d�OO�f�A<yM��S��#�DE��~� �~&�wN$�H��[Ǽ�j?��E���5�s��ݍ�Ը3�q�+�����&��B"�j�������-{`��5�!���3�&~u��(���G�_8-����Yn��lF�>L�?';��*��
2
- �,F� ��:#@~�E�<�"�m8�a�b����q �vP�b/����v:�ZF��^E]��v�"#