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
d33fb6a2
Commit
d33fb6a2
authored
9 years ago
by
Pieter Hintjens
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1441 from jens-auer/rebase3
Rebase3
parents
b3f2acf7
e70b5efa
master
v4.3.2
v4.3.2-win
v4.3.1
v4.3.0
v4.2.5
v4.2.4
v4.2.3
v4.2.2
v4.2.1
v4.2.0
v4.2.0-rc1
No related merge requests found
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
130 additions
and
61 deletions
+130
-61
Makefile.am
Makefile.am
+1
-1
decoder.hpp
src/decoder.hpp
+9
-0
i_decoder.hpp
src/i_decoder.hpp
+3
-0
msg.cpp
src/msg.cpp
+0
-0
msg.hpp
src/msg.hpp
+55
-30
raw_decoder.hpp
src/raw_decoder.hpp
+1
-1
stream_engine.cpp
src/stream_engine.cpp
+3
-0
v2_decoder.cpp
src/v2_decoder.cpp
+45
-27
v2_decoder.hpp
src/v2_decoder.hpp
+13
-2
No files found.
Makefile.am
View file @
d33fb6a2
...
@@ -643,7 +643,7 @@ check_PROGRAMS = ${test_apps}
...
@@ -643,7 +643,7 @@ check_PROGRAMS = ${test_apps}
# Run the test cases
# Run the test cases
TESTS
=
$(test_apps)
TESTS
=
$(test_apps)
XFAIL_TESTS
=
tests/test_msg_ffn
XFAIL_TESTS
=
if
!ON_LINUX
if
!ON_LINUX
XFAIL_TESTS
+=
tests/test_abstract_ipc
XFAIL_TESTS
+=
tests/test_abstract_ipc
...
...
This diff is collapsed.
Click to expand it.
src/decoder.hpp
View file @
d33fb6a2
...
@@ -73,6 +73,10 @@ namespace zmq
...
@@ -73,6 +73,10 @@ namespace zmq
return
bufsize
;
return
bufsize
;
}
}
void
resize
(
size_t
new_size
)
{
bufsize
=
new_size
;
}
private
:
private
:
size_t
bufsize
;
size_t
bufsize
;
unsigned
char
*
buf
;
unsigned
char
*
buf
;
...
@@ -190,6 +194,11 @@ namespace zmq
...
@@ -190,6 +194,11 @@ namespace zmq
return
0
;
return
0
;
}
}
virtual
void
resize_buffer
(
size_t
new_size
)
{
allocator
->
resize
(
new_size
);
}
protected
:
protected
:
// Prototype of state machine action. Action should return false if
// Prototype of state machine action. Action should return false if
...
...
This diff is collapsed.
Click to expand it.
src/i_decoder.hpp
View file @
d33fb6a2
...
@@ -46,6 +46,7 @@ namespace zmq
...
@@ -46,6 +46,7 @@ namespace zmq
virtual
void
get_buffer
(
unsigned
char
**
data_
,
size_t
*
size_
)
=
0
;
virtual
void
get_buffer
(
unsigned
char
**
data_
,
size_t
*
size_
)
=
0
;
virtual
void
resize_buffer
(
size_t
)
=
0
;
// Decodes data pointed to by data_.
// Decodes data pointed to by data_.
// When a message is decoded, 1 is returned.
// When a message is decoded, 1 is returned.
// When the decoder needs more data, 0 is returnd.
// When the decoder needs more data, 0 is returnd.
...
@@ -54,6 +55,8 @@ namespace zmq
...
@@ -54,6 +55,8 @@ namespace zmq
size_t
&
processed
)
=
0
;
size_t
&
processed
)
=
0
;
virtual
msg_t
*
msg
()
=
0
;
virtual
msg_t
*
msg
()
=
0
;
};
};
}
}
...
...
This diff is collapsed.
Click to expand it.
src/msg.cpp
View file @
d33fb6a2
This diff is collapsed.
Click to expand it.
src/msg.hpp
View file @
d33fb6a2
...
@@ -54,6 +54,7 @@ namespace zmq
...
@@ -54,6 +54,7 @@ namespace zmq
class
msg_t
class
msg_t
{
{
public
:
public
:
// Message flags.
// Message flags.
enum
enum
{
{
...
@@ -65,12 +66,17 @@ namespace zmq
...
@@ -65,12 +66,17 @@ namespace zmq
};
};
bool
check
();
bool
check
();
int
init
(
void
*
data_
,
size_t
size_
,
msg_free_fn
*
ffn_
,
int
init
();
void
*
hint_
);
int
init
();
int
init
(
void
*
data
,
size_t
size_
,
msg_free_fn
*
ffn_
,
void
*
hint
,
zmq
::
atomic_counter_t
*
refcnt_
=
NULL
);
int
init_size
(
size_t
size_
);
int
init_size
(
size_t
size_
);
int
init_data
(
void
*
data_
,
size_t
size_
,
msg_free_fn
*
ffn_
,
int
init_data
(
void
*
data_
,
size_t
size_
,
msg_free_fn
*
ffn_
,
void
*
hint_
);
void
*
hint_
);
int
init_external_storage
(
void
*
data_
,
size_t
size_
,
zmq
::
atomic_counter_t
*
ctr
,
msg_free_fn
*
ffn_
,
void
*
hint_
);
int
init_delimiter
();
int
init_delimiter
();
int
close
();
int
close
();
int
move
(
msg_t
&
src_
);
int
move
(
msg_t
&
src_
);
...
@@ -88,9 +94,9 @@ namespace zmq
...
@@ -88,9 +94,9 @@ namespace zmq
bool
is_identity
()
const
;
bool
is_identity
()
const
;
bool
is_credential
()
const
;
bool
is_credential
()
const
;
bool
is_delimiter
()
const
;
bool
is_delimiter
()
const
;
bool
is_vsm
();
bool
is_vsm
()
const
;
bool
is_
l
msg
()
const
;
bool
is_
c
msg
()
const
;
bool
is_
cmsg
()
;
bool
is_
zcmsg
()
const
;
uint32_t
get_routing_id
();
uint32_t
get_routing_id
();
int
set_routing_id
(
uint32_t
routing_id_
);
int
set_routing_id
(
uint32_t
routing_id_
);
...
@@ -102,13 +108,30 @@ namespace zmq
...
@@ -102,13 +108,30 @@ namespace zmq
// references drops to 0, the message is closed and false is returned.
// references drops to 0, the message is closed and false is returned.
bool
rm_refs
(
int
refs_
);
bool
rm_refs
(
int
refs_
);
private
:
// Size in bytes of the largest message that is still copied around
// Size in bytes of the largest message that is still copied around
// rather than being reference-counted.
// rather than being reference-counted.
enum
{
msg_t_size
=
64
};
enum
{
msg_t_size
=
64
};
enum
{
max_vsm_size
=
msg_t_size
-
(
8
+
sizeof
(
metadata_t
*
)
+
3
+
sizeof
(
uint32_t
))
};
enum
{
max_vsm_size
=
msg_t_size
-
(
8
+
sizeof
(
metadata_t
*
)
+
3
+
sizeof
(
uint32_t
))
};
private
:
zmq
::
atomic_counter_t
*
refcnt
();
// Shared message buffer. Message data are either allocated in one
// continuous block along with this structure - thus avoiding one
// malloc/free pair or they are stored in used-supplied memory.
// In the latter case, ffn member stores pointer to the function to be
// used to deallocate the data. If the buffer is actually shared (there
// are at least 2 references to it) refcount member contains number of
// references.
struct
content_t
{
void
*
data
;
size_t
size
;
msg_free_fn
*
ffn
;
void
*
hint
;
zmq
::
atomic_counter_t
refcnt
;
};
// Different message types.
// Different message types.
enum
type_t
enum
type_t
{
{
...
@@ -121,10 +144,12 @@ namespace zmq
...
@@ -121,10 +144,12 @@ namespace zmq
type_delimiter
=
103
,
type_delimiter
=
103
,
// CMSG messages point to constant data
// CMSG messages point to constant data
type_cmsg
=
104
,
type_cmsg
=
104
,
type_max
=
104
};
atomic_counter_t
&
msg_counter
();
// zero-copy LMSG message for v2_decoder
type_zclmsg
=
105
,
type_max
=
105
};
// the file descriptor where this message originated, needs to be 64bit due to alignment
// the file descriptor where this message originated, needs to be 64bit due to alignment
int64_t
file_desc
;
int64_t
file_desc
;
...
@@ -149,36 +174,36 @@ namespace zmq
...
@@ -149,36 +174,36 @@ namespace zmq
unsigned
char
flags
;
unsigned
char
flags
;
uint32_t
routing_id
;
uint32_t
routing_id
;
}
vsm
;
}
vsm
;
struct
lmsg_t
{
struct
{
metadata_t
*
metadata
;
content_t
*
content
;
unsigned
char
unused
[
msg_t_size
-
(
8
+
sizeof
(
metadata_t
*
)
+
sizeof
(
content_t
*
)
+
2
+
sizeof
(
uint32_t
))];
unsigned
char
type
;
unsigned
char
flags
;
uint32_t
routing_id
;
}
lmsg
;
struct
{
metadata_t
*
metadata
;
metadata_t
*
metadata
;
// Shared message buffer. Message data are either allocated in one
// continuous block along with this structure - thus avoiding one
// malloc/free pair or they are stored in used-supplied memory.
// In the latter case, ffn member stores pointer to the function to be
// used to deallocate the data. If the buffer is actually shared (there
// are at least 2 references to it) refcount member contains number of
// references.
void
*
data
;
void
*
data
;
size_t
size
;
size_t
size
;
msg_free_fn
*
ffn
;
msg_free_fn
*
ffn
;
void
*
hint
;
void
*
hint
;
// create an aligned block for an atomic_counter_t object
zmq
::
atomic_counter_t
*
refcnt
;
union
aligned_atomic_counter_storage
{
zmq
::
atomic_counter_t
::
integer_t
maxAlign
;
unsigned
char
counter
[
sizeof
(
zmq
::
atomic_counter_t
)
];
}
refcnt
;
unsigned
char
unused
[
msg_t_size
-
(
8
+
sizeof
(
metadata_t
*
)
unsigned
char
unused
[
msg_t_size
-
(
8
+
sizeof
(
metadata_t
*
)
+
sizeof
(
void
*
)
+
sizeof
(
void
*
)
+
sizeof
(
size_t
)
+
sizeof
(
size_t
)
+
sizeof
(
msg_free_fn
*
)
+
sizeof
(
msg_free_fn
*
)
+
sizeof
(
void
*
)
+
sizeof
(
void
*
)
+
sizeof
(
aligned_atomic_counter_storage
)
+
sizeof
(
zmq
::
atomic_counter_t
*
)
+
2
+
2
+
sizeof
(
uint32_t
))];
+
sizeof
(
uint32_t
))];
unsigned
char
type
;
unsigned
char
type
;
unsigned
char
flags
;
unsigned
char
flags
;
uint32_t
routing_id
;
uint32_t
routing_id
;
}
lmsg
;
}
zc
lmsg
;
struct
{
struct
{
metadata_t
*
metadata
;
metadata_t
*
metadata
;
void
*
data
;
void
*
data
;
...
...
This diff is collapsed.
Click to expand it.
src/raw_decoder.hpp
View file @
d33fb6a2
...
@@ -56,7 +56,7 @@ namespace zmq
...
@@ -56,7 +56,7 @@ namespace zmq
virtual
msg_t
*
msg
()
{
return
&
in_progress
;
}
virtual
msg_t
*
msg
()
{
return
&
in_progress
;
}
virtual
void
resize_buffer
(
size_t
)
{}
private
:
private
:
...
...
This diff is collapsed.
Click to expand it.
src/stream_engine.cpp
View file @
d33fb6a2
...
@@ -295,6 +295,7 @@ void zmq::stream_engine_t::in_event ()
...
@@ -295,6 +295,7 @@ void zmq::stream_engine_t::in_event ()
decoder
->
get_buffer
(
&
inpos
,
&
bufsize
);
decoder
->
get_buffer
(
&
inpos
,
&
bufsize
);
const
int
rc
=
tcp_read
(
s
,
inpos
,
bufsize
);
const
int
rc
=
tcp_read
(
s
,
inpos
,
bufsize
);
if
(
rc
==
0
)
{
if
(
rc
==
0
)
{
error
(
connection_error
);
error
(
connection_error
);
return
;
return
;
...
@@ -307,6 +308,8 @@ void zmq::stream_engine_t::in_event ()
...
@@ -307,6 +308,8 @@ void zmq::stream_engine_t::in_event ()
// Adjust input size
// Adjust input size
insize
=
static_cast
<
size_t
>
(
rc
);
insize
=
static_cast
<
size_t
>
(
rc
);
// Adjust buffer size to received bytes
decoder
->
resize_buffer
(
insize
);
}
}
int
rc
=
0
;
int
rc
=
0
;
...
...
This diff is collapsed.
Click to expand it.
src/v2_decoder.cpp
View file @
d33fb6a2
...
@@ -29,6 +29,7 @@
...
@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <cmath>
#include "platform.hpp"
#include "platform.hpp"
#ifdef ZMQ_HAVE_WINDOWS
#ifdef ZMQ_HAVE_WINDOWS
...
@@ -43,14 +44,18 @@
...
@@ -43,14 +44,18 @@
zmq
::
shared_message_memory_allocator
::
shared_message_memory_allocator
(
size_t
bufsize_
)
:
zmq
::
shared_message_memory_allocator
::
shared_message_memory_allocator
(
size_t
bufsize_
)
:
buf
(
NULL
),
buf
(
NULL
),
bufsize
(
bufsize_
)
bufsize
(
0
),
max_size
(
bufsize_
),
msg_refcnt
(
NULL
)
{
{
}
}
zmq
::
shared_message_memory_allocator
::~
shared_message_memory_allocator
()
zmq
::
shared_message_memory_allocator
::~
shared_message_memory_allocator
()
{
{
if
(
buf
)
{
deallocate
();
deallocate
();
}
}
}
unsigned
char
*
zmq
::
shared_message_memory_allocator
::
allocate
()
unsigned
char
*
zmq
::
shared_message_memory_allocator
::
allocate
()
...
@@ -58,19 +63,38 @@ unsigned char* zmq::shared_message_memory_allocator::allocate()
...
@@ -58,19 +63,38 @@ unsigned char* zmq::shared_message_memory_allocator::allocate()
if
(
buf
)
if
(
buf
)
{
{
// release reference count to couple lifetime to messages
// release reference count to couple lifetime to messages
call_dec_ref
(
NULL
,
buf
);
zmq
::
atomic_counter_t
*
c
=
reinterpret_cast
<
zmq
::
atomic_counter_t
*>
(
buf
);
// if refcnt drops to 0, there are no message using the buffer
// because either all messages have been closed or only vsm-messages
// were created
if
(
c
->
sub
(
1
))
{
// buffer is still in use as message data. "Release" it and create a new one
// release pointer because we are going to create a new buffer
// release pointer because we are going to create a new buffer
release
();
release
();
}
}
}
// @todo aligmnet padding may be needed
// if buf != NULL it is not used by any message so we can re-use it for the next run
if
(
!
buf
)
if
(
!
buf
)
{
{
// allocate memory for reference counters together with reception buffer
buf
=
(
unsigned
char
*
)
malloc
(
bufsize
+
sizeof
(
zmq
::
atomic_counter_t
));
size_t
const
maxCounters
=
std
::
ceil
(
(
double
)
max_size
/
(
double
)
msg_t
::
max_vsm_size
);
size_t
const
allocationsize
=
max_size
+
sizeof
(
zmq
::
atomic_counter_t
)
+
maxCounters
*
sizeof
(
zmq
::
atomic_counter_t
);
buf
=
(
unsigned
char
*
)
malloc
(
allocationsize
);
alloc_assert
(
buf
);
alloc_assert
(
buf
);
new
(
buf
)
atomic_counter_t
(
1
);
new
(
buf
)
atomic_counter_t
(
1
);
}
}
else
{
// release reference count to couple lifetime to messages
zmq
::
atomic_counter_t
*
c
=
reinterpret_cast
<
zmq
::
atomic_counter_t
*>
(
buf
);
c
->
set
(
1
);
}
bufsize
=
max_size
;
msg_refcnt
=
reinterpret_cast
<
zmq
::
atomic_counter_t
*>
(
buf
+
sizeof
(
atomic_counter_t
)
+
max_size
);
return
buf
+
sizeof
(
zmq
::
atomic_counter_t
);
return
buf
+
sizeof
(
zmq
::
atomic_counter_t
);
}
}
...
@@ -78,19 +102,18 @@ void zmq::shared_message_memory_allocator::deallocate()
...
@@ -78,19 +102,18 @@ void zmq::shared_message_memory_allocator::deallocate()
{
{
free
(
buf
);
free
(
buf
);
buf
=
NULL
;
buf
=
NULL
;
bufsize
=
0
;
msg_refcnt
=
NULL
;
}
}
unsigned
char
*
zmq
::
shared_message_memory_allocator
::
release
()
unsigned
char
*
zmq
::
shared_message_memory_allocator
::
release
()
{
{
unsigned
char
*
b
=
buf
;
unsigned
char
*
b
=
buf
;
buf
=
NULL
;
buf
=
NULL
;
return
b
;
bufsize
=
0
;
}
msg_refcnt
=
NULL
;
void
zmq
::
shared_message_memory_allocator
::
reset
(
unsigned
char
*
b
)
return
b
;
{
deallocate
();
buf
=
b
;
}
}
void
zmq
::
shared_message_memory_allocator
::
inc_ref
()
void
zmq
::
shared_message_memory_allocator
::
inc_ref
()
...
@@ -100,31 +123,24 @@ void zmq::shared_message_memory_allocator::inc_ref()
...
@@ -100,31 +123,24 @@ void zmq::shared_message_memory_allocator::inc_ref()
void
zmq
::
shared_message_memory_allocator
::
call_dec_ref
(
void
*
,
void
*
hint
)
{
void
zmq
::
shared_message_memory_allocator
::
call_dec_ref
(
void
*
,
void
*
hint
)
{
zmq_assert
(
hint
);
zmq_assert
(
hint
);
zmq
::
atomic_counter_t
*
c
=
reinterpret_cast
<
zmq
::
atomic_counter_t
*>
(
hint
);
unsigned
char
*
buf
=
static_cast
<
unsigned
char
*>
(
hint
);
zmq
::
atomic_counter_t
*
c
=
reinterpret_cast
<
zmq
::
atomic_counter_t
*>
(
buf
);
if
(
!
c
->
sub
(
1
))
{
if
(
!
c
->
sub
(
1
))
{
c
->~
atomic_counter_t
();
c
->~
atomic_counter_t
();
free
(
hint
);
free
(
buf
);
buf
=
NULL
;
}
}
}
}
size_t
zmq
::
shared_message_memory_allocator
::
size
()
const
size_t
zmq
::
shared_message_memory_allocator
::
size
()
const
{
{
if
(
buf
)
{
return
bufsize
;
return
bufsize
;
}
else
{
return
0
;
}
}
}
unsigned
char
*
zmq
::
shared_message_memory_allocator
::
data
()
unsigned
char
*
zmq
::
shared_message_memory_allocator
::
data
()
{
{
zmq_assert
(
buf
);
return
buf
+
sizeof
(
zmq
::
atomic_counter_t
);
return
buf
+
sizeof
(
zmq
::
atomic_counter_t
);
}
}
...
@@ -199,6 +215,7 @@ int zmq::v2_decoder_t::size_ready(uint64_t msg_size, unsigned char const* read_p
...
@@ -199,6 +215,7 @@ int zmq::v2_decoder_t::size_ready(uint64_t msg_size, unsigned char const* read_p
// the current message can exceed the current buffer. We have to copy the buffer
// the current message can exceed the current buffer. We have to copy the buffer
// data into a new message and complete it in the next receive.
// data into a new message and complete it in the next receive.
if
(
unlikely
((
unsigned
char
*
)
read_pos
+
msg_size
>
(
data
()
+
size
())))
if
(
unlikely
((
unsigned
char
*
)
read_pos
+
msg_size
>
(
data
()
+
size
())))
{
{
// a new message has started, but the size would exceed the pre-allocated arena
// a new message has started, but the size would exceed the pre-allocated arena
...
@@ -209,12 +226,13 @@ int zmq::v2_decoder_t::size_ready(uint64_t msg_size, unsigned char const* read_p
...
@@ -209,12 +226,13 @@ int zmq::v2_decoder_t::size_ready(uint64_t msg_size, unsigned char const* read_p
{
{
// construct message using n bytes from the buffer as storage
// construct message using n bytes from the buffer as storage
// increase buffer ref count
// increase buffer ref count
rc
=
in_progress
.
init
(
(
unsigned
char
*
)
read_pos
,
// if the message will be a large message, pass a valid refcnt memory location as well
msg_size
,
shared_message_memory_allocator
::
call_dec_ref
,
rc
=
in_progress
.
init
(
(
unsigned
char
*
)
read_pos
,
msg_size
,
buffer
()
);
shared_message_memory_allocator
::
call_dec_ref
,
buffer
(),
create_refcnt
()
);
// For small messages, data has been copied and refcount does not have to be increased
// For small messages, data has been copied and refcount does not have to be increased
if
(
in_progress
.
is_
l
msg
())
if
(
in_progress
.
is_
zc
msg
())
{
{
inc_ref
();
inc_ref
();
}
}
...
...
This diff is collapsed.
Click to expand it.
src/v2_decoder.hpp
View file @
d33fb6a2
...
@@ -63,8 +63,6 @@ namespace zmq
...
@@ -63,8 +63,6 @@ namespace zmq
// the messages constructed on top of it.
// the messages constructed on top of it.
unsigned
char
*
release
();
unsigned
char
*
release
();
void
reset
(
unsigned
char
*
b
);
void
inc_ref
();
void
inc_ref
();
static
void
call_dec_ref
(
void
*
,
void
*
buffer
);
static
void
call_dec_ref
(
void
*
,
void
*
buffer
);
...
@@ -80,9 +78,22 @@ namespace zmq
...
@@ -80,9 +78,22 @@ namespace zmq
return
buf
;
return
buf
;
}
}
void
resize
(
size_t
new_size
)
{
bufsize
=
new_size
;
}
//
zmq
::
atomic_counter_t
*
create_refcnt
()
{
return
msg_refcnt
++
;
}
private
:
private
:
unsigned
char
*
buf
;
unsigned
char
*
buf
;
size_t
bufsize
;
size_t
bufsize
;
size_t
max_size
;
zmq
::
atomic_counter_t
*
msg_refcnt
;
};
};
// Decoder for ZMTP/2.x framing protocol. Converts data stream into messages.
// Decoder for ZMTP/2.x framing protocol. Converts data stream into messages.
...
...
This diff is collapsed.
Click to expand it.
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