-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZmqToolsFullImpl_8hpp-source.html
More file actions
131 lines (121 loc) · 7.92 KB
/
ZmqToolsFullImpl_8hpp-source.html
File metadata and controls
131 lines (121 loc) · 7.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<html>
<head>
<meta name="keywords" content="0MQ, ZeroMQ, C++, multipart, message, library, open source, ZmqMessage" />
<meta name="description" content="ZmqMessage is free open source C++ library for sending and receiving ZeroMQ multipart messages"/>
<meta name="google-site-verification" content="0EvtpfjffSrc0fDV9ubKQVfq3IV55KY5d59hXHg9M34" />
<title>ZmqMessage: include/zmqmessage/ZmqToolsFullImpl.hpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<style>
/* must override a few items to get the style background color */
</style>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-25607292-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<table class="zm_headbar">
<tr>
<td>
<span><a href="index.html">Overview</a></span>
<span><a href="zm_tutorial.html">Tutorial</a></span>
<span><a href="namespaceZmqMessage.html">API reference</a></span>
<span><a href="examples.html">Examples</a></span>
<span><a href="zm_build.html">Build</a></span>
<span><a href="https://github.com/zmqmessage/zmqmessage/">Download</a></span>
</td>
<td align="right" class="zm_greynote">ZmqMessage 0.1 - 21 Oct 2011</td>
</tr></table>
<hr style="height: 3px;">
<!-- Generated by Doxygen 1.4.7 -->
<h1>include/zmqmessage/ZmqToolsFullImpl.hpp</h1><a href="ZmqToolsFullImpl_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001
<a name="l00013"></a>00013 <span class="preprocessor">#ifndef ZMQMESSAGE_ZMQTOOLSFULLIMPL_HPP_</span>
<a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define ZMQMESSAGE_ZMQTOOLSFULLIMPL_HPP_</span>
<a name="l00015"></a>00015 <span class="preprocessor"></span>
<a name="l00016"></a>00016 <span class="preprocessor">#include <string></span>
<a name="l00017"></a>00017
<a name="l00018"></a>00018 <span class="keyword">namespace</span>
<a name="l00019"></a>00019 <span class="keyword"></span>{
<a name="l00020"></a>00020 <span class="keywordtype">void</span>
<a name="l00021"></a><a class="code" href="ZmqToolsFullImpl_8hpp.html#38acd7f2c48b1b5ef88ca435a39832f4">00021</a> <a class="code" href="ZmqToolsFullImpl_8hpp.html#38acd7f2c48b1b5ef88ca435a39832f4">zmqmessage_free</a>(<span class="keywordtype">void</span> *data, <span class="keywordtype">void</span> *hint)
<a name="l00022"></a>00022 {
<a name="l00023"></a>00023 ::free(data);
<a name="l00024"></a>00024 }
<a name="l00025"></a>00025 }
<a name="l00026"></a>00026
<a name="l00027"></a>00027 <span class="keyword">namespace </span>ZmqMessage
<a name="l00028"></a>00028 {
<a name="l00029"></a>00029 time_t
<a name="l00030"></a><a class="code" href="namespaceZmqMessage.html#5424357e3c2f0e243cb6acf4390b0b9f">00030</a> <a class="code" href="namespaceZmqMessage.html#5424357e3c2f0e243cb6acf4390b0b9f">get_time</a>(zmq::message_t& message)
<a name="l00031"></a>00031 {
<a name="l00032"></a>00032 errno = 0;
<a name="l00033"></a>00033 std::string str;
<a name="l00034"></a>00034 <a class="code" href="namespaceZmqMessage.html#06c86c0cd57a00985048ef9b94b60729">get</a>(message, str);
<a name="l00035"></a>00035 time_t tm = strtol(str.data(), 0, 10);
<a name="l00036"></a>00036 <span class="keywordflow">if</span> (errno)
<a name="l00037"></a>00037 {
<a name="l00038"></a>00038 <span class="keywordflow">return</span> time_t();
<a name="l00039"></a>00039 }
<a name="l00040"></a>00040 <span class="keywordflow">return</span> tm;
<a name="l00041"></a>00041 }
<a name="l00042"></a>00042
<a name="l00043"></a>00043 <span class="keywordtype">void</span>
<a name="l00044"></a><a class="code" href="namespaceZmqMessage.html#8d9fb5d43437f57a05635350f1abe1d1">00044</a> <a class="code" href="namespaceZmqMessage.html#8d9fb5d43437f57a05635350f1abe1d1">init_msg</a>(<span class="keyword">const</span> <span class="keywordtype">void</span>* t, size_t sz, zmq::message_t& msg)
<a name="l00045"></a>00045 {
<a name="l00046"></a>00046 <span class="keywordflow">try</span>
<a name="l00047"></a>00047 {
<a name="l00048"></a>00048 <span class="keywordtype">void</span> *data = ::malloc(sz);
<a name="l00049"></a>00049 <span class="keywordflow">if</span> (!data)
<a name="l00050"></a>00050 {
<a name="l00051"></a>00051 <span class="keywordflow">throw</span> zmq::error_t();
<a name="l00052"></a>00052 }
<a name="l00053"></a>00053 ::memcpy(data, t, sz);
<a name="l00054"></a>00054 msg.rebuild(data, sz, &<a class="code" href="ZmqToolsFullImpl_8hpp.html#38acd7f2c48b1b5ef88ca435a39832f4">zmqmessage_free</a>, 0);
<a name="l00055"></a>00055 }
<a name="l00056"></a>00056 <span class="keywordflow">catch</span> (<span class="keyword">const</span> zmq::error_t& e)
<a name="l00057"></a>00057 {
<a name="l00058"></a>00058 <a class="code" href="namespaceZmqMessage.html#a2a1cf47a8dff94135d544cff9b07b90">throw_zmq_exception</a>(e);
<a name="l00059"></a>00059 }
<a name="l00060"></a>00060 }
<a name="l00061"></a>00061
<a name="l00062"></a>00062 <span class="keywordtype">bool</span>
<a name="l00063"></a><a class="code" href="namespaceZmqMessage.html#5a279539ebc2d608ad3dca51c9d041d1">00063</a> <a class="code" href="namespaceZmqMessage.html#5a279539ebc2d608ad3dca51c9d041d1">has_more</a>(zmq::socket_t& sock)
<a name="l00064"></a>00064 {
<a name="l00065"></a>00065 int64_t more = 0;
<a name="l00066"></a>00066 size_t more_size = <span class="keyword">sizeof</span>(more);
<a name="l00067"></a>00067 sock.getsockopt(ZMQ_RCVMORE, &more, &more_size);
<a name="l00068"></a>00068 <span class="keywordflow">return</span> (more != 0);
<a name="l00069"></a>00069 }
<a name="l00070"></a>00070
<a name="l00071"></a>00071 <span class="keywordtype">int</span>
<a name="l00072"></a><a class="code" href="namespaceZmqMessage.html#9b00f09bfd307effbb7f1b8af895ad13">00072</a> <a class="code" href="namespaceZmqMessage.html#9b00f09bfd307effbb7f1b8af895ad13">relay_raw</a>(zmq::socket_t& src, zmq::socket_t& dst, <span class="keywordtype">bool</span> check_first_part)
<a name="l00073"></a>00073 {
<a name="l00074"></a>00074 <span class="keywordtype">int</span> relayed = 0;
<a name="l00075"></a>00075 <span class="keywordflow">for</span> (
<a name="l00076"></a>00076 <span class="keywordtype">bool</span> more = check_first_part ? <a class="code" href="namespaceZmqMessage.html#5a279539ebc2d608ad3dca51c9d041d1">has_more</a>(src) : <span class="keyword">true</span>;
<a name="l00077"></a>00077 more; ++relayed)
<a name="l00078"></a>00078 {
<a name="l00079"></a>00079 zmq::message_t cur_part;
<a name="l00080"></a>00080 src.recv(&cur_part);
<a name="l00081"></a>00081 more = <a class="code" href="namespaceZmqMessage.html#5a279539ebc2d608ad3dca51c9d041d1">has_more</a>(src);
<a name="l00082"></a>00082 <span class="keywordtype">int</span> flag = more ? ZMQ_SNDMORE : 0;
<a name="l00083"></a>00083 <a class="code" href="namespaceZmqMessage.html#fca5cb180adf2275ae55c947595133cb">send_msg</a>(dst, cur_part, flag);
<a name="l00084"></a>00084 }
<a name="l00085"></a>00085 <span class="keywordflow">return</span> relayed;
<a name="l00086"></a>00086 }
<a name="l00087"></a>00087 }
<a name="l00088"></a>00088
<a name="l00089"></a>00089 <span class="preprocessor">#endif </span><span class="comment">/* ZMQMESSAGE_ZMQTOOLSFULLIMPL_HPP_ */</span>
</pre></div>
<hr style="height: 3px;">
<div class="zm_greynote">
ZmqMessage 0.1 — open source software, <a href="mailto:support@zmqmessage.org">support@zmqmessage.org</a>
</div>
</body>
</html>