Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
69d27b33
Commit
69d27b33
authored
Apr 30, 2014
by
Pieter Hintjens
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #992 from hurtonm/master
Define i_properties interface
parents
ddde62a6
19c62b93
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
82 additions
and
5 deletions
+82
-5
Makefile.am
src/Makefile.am
+1
-0
i_properties.hpp
src/i_properties.hpp
+45
-0
msg.cpp
src/msg.cpp
+27
-1
msg.hpp
src/msg.hpp
+3
-2
zmq.cpp
src/zmq.cpp
+6
-2
No files found.
src/Makefile.am
View file @
69d27b33
...
...
@@ -32,6 +32,7 @@ libzmq_la_SOURCES = \
i_decoder.hpp
\
i_engine.hpp
\
i_poll_events.hpp
\
i_properties.hpp
\
io_object.hpp
\
io_thread.hpp
\
ip.hpp
\
...
...
src/i_properties.hpp
0 → 100644
View file @
69d27b33
/*
Copyright (c) 2007-2014 Contributors as noted in the AUTHORS file
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
0MQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __ZMQ_I_PROPERTIES_HPP_INCLUDED__
#define __ZMQ_I_PROPERTIES_HPP_INCLUDED__
namespace
zmq
{
// Interface for accessing message properties.
// Implementers are supposed to use reference counting to
// manage object's lifetime.
struct
i_properties
{
virtual
~
i_properties
()
{}
// Returns pointer to property value or NULL if
// property not found.
virtual
const
char
*
get
(
const
char
*
property
)
const
=
0
;
virtual
void
add_ref
()
=
0
;
// Drop reference. Returns true iff the reference
// counter drops to zero.
virtual
bool
drop_ref
()
=
0
;
};
}
#endif
src/msg.cpp
View file @
69d27b33
...
...
@@ -26,6 +26,7 @@
#include "stdint.hpp"
#include "likely.hpp"
#include "i_properties.hpp"
#include "err.hpp"
// Check whether the sizes of public representation of the message (zmq_msg_t)
...
...
@@ -149,11 +150,14 @@ int zmq::msg_t::close ()
}
}
if
(
u
.
base
.
properties
!=
NULL
)
if
(
u
.
base
.
properties
->
drop_ref
())
delete
u
.
base
.
properties
;
// Make the message invalid.
u
.
base
.
type
=
0
;
return
0
;
}
int
zmq
::
msg_t
::
move
(
msg_t
&
src_
)
...
...
@@ -201,6 +205,9 @@ int zmq::msg_t::copy (msg_t &src_)
}
}
if
(
src_
.
u
.
base
.
properties
!=
NULL
)
src_
.
u
.
base
.
properties
->
add_ref
();
*
this
=
src_
;
return
0
;
...
...
@@ -268,6 +275,19 @@ void zmq::msg_t::set_fd (int64_t fd_)
file_desc
=
fd_
;
}
zmq
::
i_properties
*
zmq
::
msg_t
::
properties
()
const
{
return
u
.
base
.
properties
;
}
void
zmq
::
msg_t
::
set_properties
(
zmq
::
i_properties
*
properties_
)
{
assert
(
properties_
!=
NULL
);
assert
(
u
.
base
.
properties
==
NULL
);
properties_
->
add_ref
();
u
.
base
.
properties
=
properties_
;
}
bool
zmq
::
msg_t
::
is_identity
()
const
{
return
(
u
.
base
.
flags
&
identity
)
==
identity
;
...
...
@@ -297,6 +317,9 @@ void zmq::msg_t::add_refs (int refs_)
{
zmq_assert
(
refs_
>=
0
);
// Operation not supported for messages with properties.
zmq_assert
(
u
.
base
.
properties
==
NULL
);
// No copies required.
if
(
!
refs_
)
return
;
...
...
@@ -317,6 +340,9 @@ bool zmq::msg_t::rm_refs (int refs_)
{
zmq_assert
(
refs_
>=
0
);
// Operation not supported for messages with properties.
zmq_assert
(
u
.
base
.
properties
==
NULL
);
// No copies required.
if
(
!
refs_
)
return
true
;
...
...
src/msg.hpp
View file @
69d27b33
...
...
@@ -25,6 +25,7 @@
#include "config.hpp"
#include "atomic_counter.hpp"
#include "i_properties.hpp"
// Signature for free function to deallocate the message content.
// Note that it has to be declared as "C" so that it is the same as
...
...
@@ -70,6 +71,8 @@ namespace zmq
void
reset_flags
(
unsigned
char
flags_
);
int64_t
fd
();
void
set_fd
(
int64_t
fd_
);
i_properties
*
properties
()
const
;
void
set_properties
(
i_properties
*
properties_
);
bool
is_identity
()
const
;
bool
is_credential
()
const
;
bool
is_delimiter
()
const
;
...
...
@@ -86,8 +89,6 @@ namespace zmq
private
:
class
i_properties
;
// Size in bytes of the largest message that is still copied around
// rather than being reference-counted.
enum
{
msg_t_size
=
48
};
...
...
src/zmq.cpp
View file @
69d27b33
...
...
@@ -63,6 +63,7 @@ struct iovec {
#include "err.hpp"
#include "msg.hpp"
#include "fd.hpp"
#include "i_properties.hpp"
#if !defined ZMQ_HAVE_WINDOWS
#include <unistd.h>
...
...
@@ -646,8 +647,11 @@ int zmq_msg_set (zmq_msg_t *, int, int)
const
char
*
zmq_msg_gets
(
zmq_msg_t
*
msg_
,
const
char
*
property_
)
{
// All unknown properties return NULL
return
NULL
;
zmq
::
i_properties
*
properties
=
((
zmq
::
msg_t
*
)
msg_
)
->
properties
();
if
(
properties
)
return
properties
->
get
(
property_
);
else
return
NULL
;
}
// Polling.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment