posix_mq 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/posix_mq.rb ADDED
@@ -0,0 +1,34 @@
1
+ # -*- encoding: binary -*-
2
+ class POSIX_MQ
3
+
4
+ # version of POSIX_MQ, currently 0.1.0
5
+ VERSION = '0.1.0'
6
+
7
+ # An analogous Struct to "struct mq_attr" in C.
8
+ # This may be used in arguments for POSIX_MQ.new and
9
+ # POSIX_MQ#attr=. POSIX_MQ#attr returns an instance
10
+ # of this class.
11
+ #
12
+ # See the mq_getattr(3) manpage for more information on the values.
13
+ Attr = Struct.new(:flags, :maxmsg, :msgsize, :curmsgs)
14
+
15
+ class << self
16
+
17
+ # Opens a POSIX message queue and performs operations on the
18
+ # given block, closing the message queue at exit.
19
+ # All all arguments are passed to POSIX_MQ.new.
20
+ def open(*args)
21
+ mq = new(*args)
22
+ block_given? or return mq
23
+ begin
24
+ yield mq
25
+ ensure
26
+ mq.close unless mq.closed?
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
34
+ require 'posix_mq_ext'
data/local.mk.sample ADDED
@@ -0,0 +1,70 @@
1
+ # this is a sample local.mk file, feel free to modify it for your needs
2
+ # GNUmakefile will source local.mk in the top-level source tree
3
+ # if it is present.
4
+ #
5
+ # This is depends on a bunch of GNU-isms from bash, touch.
6
+
7
+ RSYNC = rsync
8
+ DLEXT := so
9
+ gems :=
10
+
11
+ # Avoid loading rubygems to speed up tests because gmake is
12
+ # fork+exec heavy with Ruby.
13
+ prefix = $(HOME)
14
+ ifeq ($(r19),)
15
+ RUBY := $(prefix)/bin/ruby
16
+ gem_paths := $(addprefix $(prefix)/lib/ruby/gems/1.8/gems/,$(gems))
17
+ else
18
+ prefix := $(prefix)/ruby-1.9
19
+ export PATH := $(prefix)/bin:$(PATH)
20
+ RUBY := $(prefix)/bin/ruby --disable-gems
21
+ gem_paths := $(addprefix $(prefix)/lib/ruby/gems/1.9.1/gems/,$(gems))
22
+ endif
23
+
24
+ ifdef gem_paths
25
+ sp :=
26
+ sp +=
27
+ export RUBYLIB := $(subst $(sp),:,$(addsuffix /lib,$(gem_paths)))
28
+ endif
29
+
30
+ # pipefail is THE reason to use bash (v3+) or never revisions of ksh93
31
+ # SHELL := /bin/bash -e -o pipefail
32
+ SHELL := /bin/ksh93 -e -o pipefail
33
+
34
+ # trace execution of tests
35
+ # TRACER = strace -f -o $(t_pfx).strace -s 100000
36
+ TRACER = /usr/bin/time -v -o $(t_pfx).time
37
+
38
+ full-test: test-18 test-19
39
+ test-18:
40
+ $(MAKE) test 2>&1 | sed -e 's!^!1.8 !'
41
+ test-19:
42
+ $(MAKE) test r19=t 2>&1 | sed -e 's!^!1.9 !'
43
+
44
+ latest: NEWS
45
+ @awk 'BEGIN{RS="=== ";ORS=""}NR==2{sub(/\n$$/,"");print RS""$$0 }' $<
46
+
47
+ # publishes docs to http://bogomips.org/ruby_posix_mq/
48
+ publish_doc:
49
+ -git set-file-times
50
+ $(RM) -r doc ChangeLog NEWS
51
+ $(MAKE) doc LOG_VERSION=$(shell git tag -l | tail -1)
52
+ $(MAKE) -s latest > doc/LATEST
53
+ find doc/images doc/js -type f | \
54
+ TZ=UTC xargs touch -d '1970-01-01 00:00:00' doc/rdoc.css
55
+ $(MAKE) doc_gz
56
+ chmod 644 $$(find doc -type f)
57
+ $(RSYNC) -av doc/ dcvr:/srv/bogomips/ruby_posix_mq/
58
+ git ls-files | xargs touch
59
+
60
+ # Create gzip variants of the same timestamp as the original so nginx
61
+ # "gzip_static on" can serve the gzipped versions directly.
62
+ doc_gz: docs = $(shell find doc -type f ! -regex '^.*\.\(gif\|jpg\|png\|gz\)$$')
63
+ doc_gz:
64
+ touch doc/NEWS.atom.xml -d "$$(awk 'NR==1{print $$4,$$5,$$6}' NEWS)"
65
+ for i in $(docs); do \
66
+ gzip --rsyncable -9 < $$i > $$i.gz; touch -r $$i $$i.gz; done
67
+
68
+ # launches any of the following shells with RUBYLIB set
69
+ irb sh bash ksh:
70
+ $@
@@ -0,0 +1,187 @@
1
+ .TH posix-mq.rb 1 "Jan 1, 2010" "posix-mq.rb User Manual"
2
+ .SH NAME
3
+ .PP
4
+ posix-mq.rb - command-line interface for POSIX message queues
5
+ .SH SYNOPSIS
6
+ .PP
7
+ MQUEUE=/name posix-mq.rb COMMAND [\f[I]OPTIONS\f[]]
8
+ [\f[I]ARGUMENTS\f[]]
9
+ .SH DESCRIPTION
10
+ .PP
11
+ A command-line interface for manipulating POSIX message queues.
12
+ It is useful for testing and debugging applications using POSIX
13
+ message queues.
14
+ .SH COMMANDS
15
+ .PP
16
+ \f[I]create\f[] - create a new message queue
17
+ .PP
18
+ \f[I]attr\f[] - output attributes of the message queue
19
+ .PP
20
+ \f[I]send\f[] - insert a message into the queue from stdin or the
21
+ command-line
22
+ .PP
23
+ \f[I]receive\f[] - take a message from the queue and outputs it to
24
+ stdout
25
+ .PP
26
+ \f[I]wait\f[] - sleep until a message is available in the queue
27
+ .PP
28
+ \f[I]unlink\f[] - unlink the message queue
29
+ .SH CREATE USAGE
30
+ .PP
31
+ The \f[I]create\f[] command accepts the following options:
32
+ .TP
33
+ .B -x, --exclusive
34
+ This causes queue creation to fail if the queue exists.
35
+ .RS
36
+ .RE
37
+ .TP
38
+ .B -m, --mode MODE
39
+ The MODE to open the file under, the actual mode of the queue will
40
+ be AND-ed with the current umask (like open(2)).
41
+ .RS
42
+ .RE
43
+ .TP
44
+ .B -c, --maxmsg COUNT
45
+ The maximum messages in the queue.
46
+ The default and limit of this value is system-dependent.
47
+ This must be specified if --msgsize is also specified.
48
+ .RS
49
+ .RE
50
+ .TP
51
+ .B -s, --msgsize BYTES
52
+ The maximum size of an individual message.
53
+ The default and limit of this value is system-dependent.
54
+ This must be specified if --maxmsg is also specified.
55
+ .RS
56
+ .RE
57
+ .SH ATTR USAGE
58
+ .PP
59
+ The \f[I]attr\f[] command takes no special options nor command-line
60
+ arguments.
61
+ The output format of this command is suitable for \[lq]eval\[rq] in
62
+ shell scripts.
63
+ Sample output is below:
64
+ .PP
65
+ \f[CR]
66
+ \ \ \ \ flags=0
67
+ \ \ \ \ maxmsg=10
68
+ \ \ \ \ msgsize=8192
69
+ \ \ \ \ curmsgs=3
70
+ \f[]
71
+ .PP
72
+ See mq_getattr(3) for information on the meaning of the fields.
73
+ .SH SEND USAGE
74
+ .PP
75
+ The \f[I]send\f[] command will read a message from standard input
76
+ if no command-line arguments are given.
77
+ If command-line arguments are given, each argument is considered
78
+ its own message and will be inserted into the queue separately.
79
+ .PP
80
+ The following command-line arguments are accepted:
81
+ .TP
82
+ .B -n, --nonblock
83
+ Exit immediately with error if the message queue is full.
84
+ Normally posix-mq.rb(1) will block until the queue is writable or
85
+ interrupted.
86
+ This may not be used in conjunction with --timeout \&.
87
+ .RS
88
+ .RE
89
+ .TP
90
+ .B -t, --timeout SECONDS
91
+ Timeout and exit with error after SECONDS if the message queue is
92
+ full.
93
+ This may not be used in conjunction with --nonblock.
94
+ .RS
95
+ .RE
96
+ .TP
97
+ .B -p, --priority PRIORITY
98
+ Specify an integer PRIORITY, this value should be 0 through 31
99
+ (inclusive) for portability across POSIX-compliant systems.
100
+ The default priority is 0.
101
+ .RS
102
+ .RE
103
+ .SH RECEIVE USAGE
104
+ .PP
105
+ The \f[I]receive\f[] command will output message to standard
106
+ output.
107
+ It will read a message from standard input if no command-line
108
+ arguments are given.
109
+ If command-line arguments are given, each argument is considered
110
+ its own message and will be inserted into the queue separately.
111
+ .PP
112
+ The following command-line arguments are accepted:
113
+ .TP
114
+ .B -n, --nonblock
115
+ Exit immediately with error if the message queue is empty.
116
+ Normally posix-mq.rb(1) will block until the queue is readable or
117
+ interrupted.
118
+ This may not be used in conjunction with --timeout \&.
119
+ .RS
120
+ .RE
121
+ .TP
122
+ .B -t, --timeout SECONDS
123
+ Timeout and exit with error after SECONDS if the message queue is
124
+ empty.
125
+ This may not be used in conjunction with --nonblock.
126
+ .RS
127
+ .RE
128
+ .TP
129
+ .B -p, --priority
130
+ Output the priority of the received message to stderr in the
131
+ following format:
132
+ .RS
133
+ .RE
134
+ .PP
135
+ \f[CR]
136
+ \ \ \ \ priority=3
137
+
138
+ The\ priority\ is\ an\ unsigned\ integer.
139
+ \f[]
140
+ .SH WAIT USAGE
141
+ .PP
142
+ The \f[I]wait\f[] command will cause posix-mq.rb(1) to sleep until
143
+ a message is available in the queue.
144
+ Only one process may wait on an empty queue, posix-mq.rb(1) will
145
+ exit with an error if there is another waiting process.
146
+ .PP
147
+ It takes no arguments and accepts the following options:
148
+ .TP
149
+ .B -t, --timeout SECONDS
150
+ Timeout and exit with error after SECONDS if the message queue is
151
+ empty.
152
+ .RS
153
+ .RE
154
+ .SH UNLINK USAGE
155
+ .PP
156
+ The \f[I]unlink\f[] command prevents further opening and use of the
157
+ current queue.
158
+ Existing processes with the queue open may continue to operate on
159
+ the queue indefinitely.
160
+ If a new queue is created with the same name, the created queue is
161
+ a different queue from the unlinked queue.
162
+ See mq_unlink(3) for more information.
163
+ .SH GENERAL OPTIONS
164
+ .TP
165
+ .B -q
166
+ Do not show warning/error messages, suitable for scripting.
167
+ .RS
168
+ .RE
169
+ .TP
170
+ .B -h, --help
171
+ Show summary usage
172
+ .RS
173
+ .RE
174
+ .SH ENVIRONMENT
175
+ .PP
176
+ All commands rely on the MQUEUE environment variable.
177
+ The value of MQUEUE should always be prefixed with a slash
178
+ (\[lq]/\[rq]) for portability.
179
+ .SH DIAGNOSTICS
180
+ .PP
181
+ Exit status is normally 0.
182
+ Exit status is 2 if a timeout occurs, 1 for all other errors.
183
+ .SH SEE ALSO
184
+ .IP \[bu] 2
185
+ mq_overview(7) (http://kernel.org/doc/man-pages/online/pages/man7/mq_overview.7.html)
186
+ .SH AUTHOR
187
+ Ruby POSIX MQ hackers <ruby.posix.mq@librelist.com>
data/posix_mq.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # -*- encoding: binary -*-
2
+
3
+ ENV["VERSION"] or abort "VERSION= must be specified"
4
+ manifest = File.readlines('.manifest').map! { |x| x.chomp! }
5
+ test_files = manifest.grep(%r{\Atest/test_.*\.rb\z})
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = %q{posix_mq}
9
+ s.version = ENV["VERSION"]
10
+
11
+ s.authors = ["Ruby POSIX MQ hackers"]
12
+ s.date = Time.now.utc.strftime('%Y-%m-%d')
13
+ s.description = File.read("README").split(/\n\n/)[1]
14
+ s.email = %q{ruby.posix.mq@librelist.com}
15
+ s.executables = %w(posix-mq.rb)
16
+ s.extensions = %w(ext/posix_mq/extconf.rb)
17
+
18
+ s.extra_rdoc_files = File.readlines('.document').map! do |x|
19
+ x.chomp!
20
+ if File.directory?(x)
21
+ manifest.grep(%r{\A#{x}/})
22
+ elsif File.file?(x)
23
+ x
24
+ else
25
+ nil
26
+ end
27
+ end.flatten.compact
28
+
29
+ s.files = manifest
30
+ s.homepage = %q{http://bogomips.org/ruby_posix_mq/}
31
+ s.summary = %q{POSIX Message Queues for Ruby}
32
+ s.rdoc_options = [ "-Na", "-t", "posix_mq - #{s.summary}" ]
33
+ s.require_paths = %w(lib)
34
+ s.rubyforge_project = %q{qrp}
35
+
36
+ s.test_files = test_files
37
+
38
+ # s.licenses = %w(LGPLv3) # accessor not compatible with older RubyGems
39
+ end