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
4e616f30
Commit
4e616f30
authored
May 18, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: C-style casts used
Solution: replace by C++-style casts
parent
d002eb55
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
52 changed files
with
322 additions
and
254 deletions
+322
-254
blob.hpp
src/blob.hpp
+4
-4
clock.cpp
src/clock.cpp
+1
-1
ctx.cpp
src/ctx.cpp
+7
-4
curve_client.cpp
src/curve_client.cpp
+4
-3
curve_client_tools.hpp
src/curve_client_tools.hpp
+4
-4
curve_server.cpp
src/curve_server.cpp
+3
-3
dish.cpp
src/dish.cpp
+4
-3
dist.cpp
src/dist.cpp
+1
-1
encoder.hpp
src/encoder.hpp
+2
-2
err.cpp
src/err.cpp
+2
-2
generic_mtrie_impl.hpp
src/generic_mtrie_impl.hpp
+1
-1
io_thread.cpp
src/io_thread.cpp
+1
-1
ip.cpp
src/ip.cpp
+30
-20
ip_resolver.cpp
src/ip_resolver.cpp
+5
-5
mechanism.cpp
src/mechanism.cpp
+5
-4
mechanism_base.cpp
src/mechanism_base.cpp
+2
-1
msg.cpp
src/msg.cpp
+4
-3
options.cpp
src/options.cpp
+15
-11
own.cpp
src/own.cpp
+1
-1
pipe.cpp
src/pipe.cpp
+1
-1
plain_server.cpp
src/plain_server.cpp
+1
-1
poller_base.cpp
src/poller_base.cpp
+1
-1
radio.cpp
src/radio.cpp
+3
-3
random.cpp
src/random.cpp
+4
-4
raw_decoder.cpp
src/raw_decoder.cpp
+1
-1
reaper.cpp
src/reaper.cpp
+1
-1
req.cpp
src/req.cpp
+2
-1
router.cpp
src/router.cpp
+4
-3
select.cpp
src/select.cpp
+7
-6
signaler.cpp
src/signaler.cpp
+8
-4
socket_base.cpp
src/socket_base.cpp
+15
-14
socket_poller.cpp
src/socket_poller.cpp
+11
-8
socks.cpp
src/socks.cpp
+2
-2
socks_connecter.cpp
src/socks_connecter.cpp
+5
-4
stream.cpp
src/stream.cpp
+4
-2
stream_engine.cpp
src/stream_engine.cpp
+12
-10
sub.cpp
src/sub.cpp
+1
-1
tcp.cpp
src/tcp.cpp
+16
-11
tcp_address.cpp
src/tcp_address.cpp
+15
-12
tcp_connecter.cpp
src/tcp_connecter.cpp
+6
-5
tcp_listener.cpp
src/tcp_listener.cpp
+8
-7
timers.cpp
src/timers.cpp
+1
-1
trie.cpp
src/trie.cpp
+11
-8
udp_engine.cpp
src/udp_engine.cpp
+34
-27
v1_decoder.cpp
src/v1_decoder.cpp
+4
-2
v1_encoder.cpp
src/v1_encoder.cpp
+1
-1
v2_decoder.cpp
src/v2_decoder.cpp
+1
-1
wire.hpp
src/wire.hpp
+28
-21
xpub.cpp
src/xpub.cpp
+5
-4
xsub.cpp
src/xsub.cpp
+5
-5
zmq.cpp
src/zmq.cpp
+0
-0
zmq_utils.cpp
src/zmq_utils.cpp
+8
-8
No files found.
src/blob.hpp
View file @
4e616f30
...
...
@@ -75,7 +75,7 @@ struct blob_t
// Creates a blob_t of a given size, with uninitialized content.
explicit
blob_t
(
const
size_t
size
)
:
data_
(
(
unsigned
char
*
)
malloc
(
size
)),
data_
(
static_cast
<
unsigned
char
*>
(
malloc
(
size
)
)),
size_
(
size
),
owned_
(
true
)
{
...
...
@@ -85,7 +85,7 @@ struct blob_t
// Creates a blob_t of a given size, an initializes content by copying
// from another buffer.
blob_t
(
const
unsigned
char
*
const
data
,
const
size_t
size
)
:
data_
(
(
unsigned
char
*
)
malloc
(
size
)),
data_
(
static_cast
<
unsigned
char
*>
(
malloc
(
size
)
)),
size_
(
size
),
owned_
(
true
)
{
...
...
@@ -124,7 +124,7 @@ struct blob_t
void
set_deep_copy
(
blob_t
const
&
other
)
{
clear
();
data_
=
(
unsigned
char
*
)
malloc
(
other
.
size_
);
data_
=
static_cast
<
unsigned
char
*>
(
malloc
(
other
.
size_
)
);
size_
=
other
.
size_
;
owned_
=
true
;
memcpy
(
data_
,
other
.
data_
,
size_
);
...
...
@@ -134,7 +134,7 @@ struct blob_t
void
set
(
const
unsigned
char
*
const
data
,
const
size_t
size
)
{
clear
();
data_
=
(
unsigned
char
*
)
malloc
(
size
);
data_
=
static_cast
<
unsigned
char
*>
(
malloc
(
size
)
);
size_
=
size
;
owned_
=
true
;
memcpy
(
data_
,
data
,
size_
);
...
...
src/clock.cpp
View file @
4e616f30
...
...
@@ -156,7 +156,7 @@ uint64_t zmq::clock_t::now_us ()
// Convert the tick number into the number of seconds
// since the system was started.
double
ticks_div
=
ticksPerSecond
.
QuadPart
/
1000000.0
;
return
(
uint64_t
)
(
tick
.
QuadPart
/
ticks_div
);
return
static_cast
<
uint64_t
>
(
tick
.
QuadPart
/
ticks_div
);
#elif defined HAVE_CLOCK_GETTIME \
&& (defined CLOCK_MONOTONIC || defined ZMQ_HAVE_VXWORKS)
...
...
src/ctx.cpp
View file @
4e616f30
...
...
@@ -290,7 +290,8 @@ bool zmq::ctx_t::start ()
int
ios
=
io_thread_count
;
opt_sync
.
unlock
();
slot_count
=
mazmq
+
ios
+
2
;
slots
=
(
i_mailbox
**
)
malloc
(
sizeof
(
i_mailbox
*
)
*
slot_count
);
slots
=
static_cast
<
i_mailbox
**>
(
malloc
(
sizeof
(
i_mailbox
*
)
*
slot_count
));
if
(
!
slots
)
{
errno
=
ENOMEM
;
goto
fail
;
...
...
@@ -311,7 +312,8 @@ bool zmq::ctx_t::start ()
reaper
->
start
();
// Create I/O thread objects and launch them.
for
(
int32_t
i
=
(
int32_t
)
slot_count
-
1
;
i
>=
(
int32_t
)
2
;
i
--
)
{
for
(
int32_t
i
=
static_cast
<
int32_t
>
(
slot_count
)
-
1
;
i
>=
static_cast
<
int32_t
>
(
2
);
i
--
)
{
slots
[
i
]
=
NULL
;
}
...
...
@@ -331,7 +333,8 @@ bool zmq::ctx_t::start ()
}
// In the unused part of the slot array, create a list of empty slots.
for
(
int32_t
i
=
(
int32_t
)
slot_count
-
1
;
i
>=
(
int32_t
)
ios
+
2
;
i
--
)
{
for
(
int32_t
i
=
static_cast
<
int32_t
>
(
slot_count
)
-
1
;
i
>=
static_cast
<
int32_t
>
(
ios
)
+
2
;
i
--
)
{
empty_slots
.
push_back
(
i
);
}
...
...
@@ -377,7 +380,7 @@ zmq::socket_base_t *zmq::ctx_t::create_socket (int type_)
empty_slots
.
pop_back
();
// Generate new unique socket ID.
int
sid
=
(
(
int
)
max_socket_id
.
add
(
1
))
+
1
;
int
sid
=
(
static_cast
<
int
>
(
max_socket_id
.
add
(
1
)
))
+
1
;
// Create the socket and register its mailbox.
socket_base_t
*
s
=
socket_base_t
::
create
(
type_
,
this
,
slot
,
sid
);
...
...
src/curve_client.cpp
View file @
4e616f30
...
...
@@ -176,7 +176,7 @@ int zmq::curve_client_t::produce_initiate (msg_t *msg_)
{
const
size_t
metadata_length
=
basic_properties_len
();
unsigned
char
*
metadata_plaintext
=
(
unsigned
char
*
)
malloc
(
metadata_length
);
static_cast
<
unsigned
char
*>
(
malloc
(
metadata_length
)
);
alloc_assert
(
metadata_plaintext
);
add_basic_properties
(
metadata_plaintext
,
metadata_length
);
...
...
@@ -217,10 +217,11 @@ int zmq::curve_client_t::process_ready (const uint8_t *msg_data,
const
size_t
clen
=
(
msg_size
-
14
)
+
crypto_box_BOXZEROBYTES
;
uint8_t
ready_nonce
[
crypto_box_NONCEBYTES
];
uint8_t
*
ready_plaintext
=
(
uint8_t
*
)
malloc
(
crypto_box_ZEROBYTES
+
clen
);
uint8_t
*
ready_plaintext
=
static_cast
<
uint8_t
*>
(
malloc
(
crypto_box_ZEROBYTES
+
clen
));
alloc_assert
(
ready_plaintext
);
uint8_t
*
ready_box
=
(
uint8_t
*
)
malloc
(
crypto_box_BOXZEROBYTES
+
16
+
clen
);
static_cast
<
uint8_t
*>
(
malloc
(
crypto_box_BOXZEROBYTES
+
16
+
clen
)
);
alloc_assert
(
ready_box
);
memset
(
ready_box
,
0
,
crypto_box_BOXZEROBYTES
);
...
...
src/curve_client_tools.hpp
View file @
4e616f30
...
...
@@ -164,11 +164,11 @@ struct curve_client_tools_t
return
-
1
;
uint8_t
initiate_nonce
[
crypto_box_NONCEBYTES
];
uint8_t
*
initiate_box
=
(
uint8_t
*
)
malloc
(
crypto_box_BOXZEROBYTES
+
144
+
metadata_length
);
uint8_t
*
initiate_box
=
static_cast
<
uint8_t
*>
(
malloc
(
crypto_box_BOXZEROBYTES
+
144
+
metadata_length
)
);
alloc_assert
(
initiate_box
);
uint8_t
*
initiate_plaintext
=
(
uint8_t
*
)
malloc
(
crypto_box_ZEROBYTES
+
128
+
metadata_length
);
uint8_t
*
initiate_plaintext
=
static_cast
<
uint8_t
*>
(
malloc
(
crypto_box_ZEROBYTES
+
128
+
metadata_length
)
);
alloc_assert
(
initiate_plaintext
);
// Create Box [C + vouch + metadata](C'->S')
...
...
src/curve_server.cpp
View file @
4e616f30
...
...
@@ -430,7 +430,7 @@ int zmq::curve_server_t::produce_ready (msg_t *msg_)
uint8_t
ready_nonce
[
crypto_box_NONCEBYTES
];
uint8_t
*
ready_plaintext
=
(
uint8_t
*
)
malloc
(
crypto_box_ZEROBYTES
+
metadata_length
);
static_cast
<
uint8_t
*>
(
malloc
(
crypto_box_ZEROBYTES
+
metadata_length
)
);
alloc_assert
(
ready_plaintext
);
// Create Box [metadata](S'->C')
...
...
@@ -443,8 +443,8 @@ int zmq::curve_server_t::produce_ready (msg_t *msg_)
memcpy
(
ready_nonce
,
"CurveZMQREADY---"
,
16
);
put_uint64
(
ready_nonce
+
16
,
cn_nonce
);
uint8_t
*
ready_box
=
(
uint8_t
*
)
malloc
(
crypto_box_BOXZEROBYTES
+
16
+
metadata_length
);
uint8_t
*
ready_box
=
static_cast
<
uint8_t
*>
(
malloc
(
crypto_box_BOXZEROBYTES
+
16
+
metadata_length
)
);
alloc_assert
(
ready_box
);
int
rc
=
crypto_box_afternm
(
ready_box
,
ready_plaintext
,
mlen
,
ready_nonce
,
...
...
src/dish.cpp
View file @
4e616f30
...
...
@@ -295,7 +295,8 @@ int zmq::dish_session_t::push_msg (msg_t *msg_)
goto
has_group
;
// Set the message group
rc
=
msg_
->
set_group
((
char
*
)
group_msg
.
data
(),
group_msg
.
size
());
rc
=
msg_
->
set_group
(
static_cast
<
char
*>
(
group_msg
.
data
()),
group_msg
.
size
());
errno_assert
(
rc
==
0
);
// We set the group, so we don't need the group_msg anymore
...
...
@@ -328,7 +329,7 @@ int zmq::dish_session_t::pull_msg (msg_t *msg_)
if
(
!
msg_
->
is_join
()
&&
!
msg_
->
is_leave
())
return
rc
;
else
{
int
group_length
=
(
int
)
strlen
(
msg_
->
group
(
));
int
group_length
=
static_cast
<
int
>
(
strlen
(
msg_
->
group
()
));
msg_t
command
;
int
offset
;
...
...
@@ -346,7 +347,7 @@ int zmq::dish_session_t::pull_msg (msg_t *msg_)
}
command
.
set_flags
(
msg_t
::
command
);
char
*
command_data
=
(
char
*
)
command
.
data
(
);
char
*
command_data
=
static_cast
<
char
*>
(
command
.
data
()
);
// Copy the group
memcpy
(
command_data
+
offset
,
msg_
->
group
(),
group_length
);
...
...
src/dist.cpp
View file @
4e616f30
...
...
@@ -179,7 +179,7 @@ void zmq::dist_t::distribute (msg_t *msg_)
// Add matching-1 references to the message. We already hold one reference,
// that's why -1.
msg_
->
add_refs
(
(
int
)
matching
-
1
);
msg_
->
add_refs
(
static_cast
<
int
>
(
matching
)
-
1
);
// Push copy of the message to each matching pipe.
int
failed
=
0
;
...
...
src/encoder.hpp
View file @
4e616f30
...
...
@@ -60,7 +60,7 @@ template <typename T> class encoder_base_t : public i_encoder
next
(
NULL
),
new_msg_flag
(
false
),
bufsize
(
bufsize_
),
buf
(
(
unsigned
char
*
)
malloc
(
bufsize_
)),
buf
(
static_cast
<
unsigned
char
*>
(
malloc
(
bufsize_
)
)),
in_progress
(
NULL
)
{
alloc_assert
(
buf
);
...
...
@@ -146,7 +146,7 @@ template <typename T> class encoder_base_t : public i_encoder
step_t
next_
,
bool
new_msg_flag_
)
{
write_pos
=
(
unsigned
char
*
)
write_pos_
;
write_pos
=
static_cast
<
unsigned
char
*>
(
write_pos_
)
;
to_write
=
to_write_
;
next
=
next_
;
new_msg_flag
=
new_msg_flag_
;
...
...
src/err.cpp
View file @
4e616f30
...
...
@@ -219,8 +219,8 @@ void zmq::win_error (char *buffer_, size_t buffer_size_)
#else
DWORD
rc
=
FormatMessageA
(
FORMAT_MESSAGE_FROM_SYSTEM
|
FORMAT_MESSAGE_IGNORE_INSERTS
,
NULL
,
errcode
,
MAKELANGID
(
LANG_NEUTRAL
,
SUBLANG_DEFAULT
),
buffer_
,
(
DWORD
)
buffer_size_
,
NULL
);
MAKELANGID
(
LANG_NEUTRAL
,
SUBLANG_DEFAULT
),
buffer_
,
static_cast
<
DWORD
>
(
buffer_size_
),
NULL
);
#endif
zmq_assert
(
rc
);
}
...
...
src/generic_mtrie_impl.hpp
View file @
4e616f30
...
...
@@ -191,7 +191,7 @@ void zmq::generic_mtrie_t<T>::rm_helper (value_t *pipe_,
// Adjust the buffer.
if
(
buffsize_
>=
maxbuffsize_
)
{
maxbuffsize_
=
buffsize_
+
256
;
*
buff_
=
(
unsigned
char
*
)
realloc
(
*
buff_
,
maxbuffsize_
);
*
buff_
=
static_cast
<
unsigned
char
*>
(
realloc
(
*
buff_
,
maxbuffsize_
)
);
alloc_assert
(
*
buff_
);
}
...
...
src/io_thread.cpp
View file @
4e616f30
...
...
@@ -38,7 +38,7 @@
zmq
::
io_thread_t
::
io_thread_t
(
ctx_t
*
ctx_
,
uint32_t
tid_
)
:
object_t
(
ctx_
,
tid_
),
mailbox_handle
(
(
poller_t
::
handle_t
)
NULL
)
mailbox_handle
(
static_cast
<
poller_t
::
handle_t
>
(
NULL
)
)
{
poller
=
new
(
std
::
nothrow
)
poller_t
(
*
ctx_
);
alloc_assert
(
poller
);
...
...
src/ip.cpp
View file @
4e616f30
...
...
@@ -135,8 +135,8 @@ void zmq::enable_ipv4_mapping (fd_t s_)
#else
int
flag
=
0
;
#endif
int
rc
=
setsockopt
(
s_
,
IPPROTO_IPV6
,
IPV6_V6ONLY
,
(
char
*
)
&
flag
,
sizeof
(
flag
));
int
rc
=
setsockopt
(
s_
,
IPPROTO_IPV6
,
IPV6_V6ONLY
,
reinterpret_cast
<
char
*>
(
&
flag
)
,
sizeof
(
flag
));
#ifdef ZMQ_HAVE_WINDOWS
wsa_assert
(
rc
!=
SOCKET_ERROR
);
#else
...
...
@@ -156,7 +156,8 @@ int zmq::get_peer_ip_address (fd_t sockfd_, std::string &ip_addr_)
#else
socklen_t
addrlen
=
sizeof
ss
;
#endif
rc
=
getpeername
(
sockfd_
,
(
struct
sockaddr
*
)
&
ss
,
&
addrlen
);
rc
=
getpeername
(
sockfd_
,
reinterpret_cast
<
struct
sockaddr
*>
(
&
ss
),
&
addrlen
);
#ifdef ZMQ_HAVE_WINDOWS
if
(
rc
==
SOCKET_ERROR
)
{
const
int
last_error
=
WSAGetLastError
();
...
...
@@ -173,8 +174,8 @@ int zmq::get_peer_ip_address (fd_t sockfd_, std::string &ip_addr_)
#endif
char
host
[
NI_MAXHOST
];
rc
=
getnameinfo
(
(
struct
sockaddr
*
)
&
ss
,
addrlen
,
host
,
sizeof
host
,
NULL
,
0
,
NI_NUMERICHOST
);
rc
=
getnameinfo
(
reinterpret_cast
<
struct
sockaddr
*>
(
&
ss
),
addrlen
,
host
,
sizeof
host
,
NULL
,
0
,
NI_NUMERICHOST
);
if
(
rc
!=
0
)
return
0
;
...
...
@@ -187,7 +188,7 @@ int zmq::get_peer_ip_address (fd_t sockfd_, std::string &ip_addr_)
}
u
;
u
.
sa_stor
=
ss
;
return
(
int
)
u
.
sa
.
sa_family
;
return
static_cast
<
int
>
(
u
.
sa
.
sa_family
)
;
}
void
zmq
::
set_ip_type_of_service
(
fd_t
s_
,
int
iptos
)
...
...
@@ -311,8 +312,9 @@ void zmq::shutdown_network ()
static
void
tune_socket
(
const
SOCKET
socket
)
{
BOOL
tcp_nodelay
=
1
;
int
rc
=
setsockopt
(
socket
,
IPPROTO_TCP
,
TCP_NODELAY
,
(
char
*
)
&
tcp_nodelay
,
sizeof
tcp_nodelay
);
int
rc
=
setsockopt
(
socket
,
IPPROTO_TCP
,
TCP_NODELAY
,
reinterpret_cast
<
char
*>
(
&
tcp_nodelay
),
sizeof
tcp_nodelay
);
wsa_assert
(
rc
!=
SOCKET_ERROR
);
zmq
::
tcp_tune_loopback_fast_path
(
socket
);
...
...
@@ -415,7 +417,8 @@ int zmq::make_fdpair (fd_t *r_, fd_t *w_)
// Set SO_REUSEADDR and TCP_NODELAY on listening socket.
BOOL
so_reuseaddr
=
1
;
int
rc
=
setsockopt
(
listener
,
SOL_SOCKET
,
SO_REUSEADDR
,
(
char
*
)
&
so_reuseaddr
,
sizeof
so_reuseaddr
);
reinterpret_cast
<
char
*>
(
&
so_reuseaddr
),
sizeof
so_reuseaddr
);
wsa_assert
(
rc
!=
SOCKET_ERROR
);
tune_socket
(
listener
);
...
...
@@ -441,12 +444,14 @@ int zmq::make_fdpair (fd_t *r_, fd_t *w_)
}
// Bind listening socket to signaler port.
rc
=
bind
(
listener
,
(
const
struct
sockaddr
*
)
&
addr
,
sizeof
addr
);
rc
=
bind
(
listener
,
reinterpret_cast
<
const
struct
sockaddr
*>
(
&
addr
),
sizeof
addr
);
if
(
rc
!=
SOCKET_ERROR
&&
signaler_port
==
0
)
{
// Retrieve ephemeral port number
int
addrlen
=
sizeof
addr
;
rc
=
getsockname
(
listener
,
(
struct
sockaddr
*
)
&
addr
,
&
addrlen
);
rc
=
getsockname
(
listener
,
reinterpret_cast
<
struct
sockaddr
*>
(
&
addr
),
&
addrlen
);
}
// Listen for incoming connections.
...
...
@@ -455,7 +460,8 @@ int zmq::make_fdpair (fd_t *r_, fd_t *w_)
// Connect writer to the listener.
if
(
rc
!=
SOCKET_ERROR
)
rc
=
connect
(
*
w_
,
(
struct
sockaddr
*
)
&
addr
,
sizeof
addr
);
rc
=
connect
(
*
w_
,
reinterpret_cast
<
struct
sockaddr
*>
(
&
addr
),
sizeof
addr
);
// Accept connection from writer.
if
(
rc
!=
SOCKET_ERROR
)
...
...
@@ -466,22 +472,26 @@ int zmq::make_fdpair (fd_t *r_, fd_t *w_)
if
(
*
r_
!=
INVALID_SOCKET
)
{
size_t
dummy_size
=
1024
*
1024
;
// 1M to overload default receive buffer
unsigned
char
*
dummy
=
(
unsigned
char
*
)
malloc
(
dummy_size
);
unsigned
char
*
dummy
=
static_cast
<
unsigned
char
*>
(
malloc
(
dummy_size
));
wsa_assert
(
dummy
);
int
still_to_send
=
(
int
)
dummy_size
;
int
still_to_recv
=
(
int
)
dummy_size
;
int
still_to_send
=
static_cast
<
int
>
(
dummy_size
)
;
int
still_to_recv
=
static_cast
<
int
>
(
dummy_size
)
;
while
(
still_to_send
||
still_to_recv
)
{
int
nbytes
;
if
(
still_to_send
>
0
)
{
nbytes
=
::
send
(
*
w_
,
(
char
*
)
(
dummy
+
dummy_size
-
still_to_send
),
still_to_send
,
0
);
nbytes
=
::
send
(
*
w_
,
reinterpret_cast
<
char
*>
(
dummy
+
dummy_size
-
still_to_send
),
still_to_send
,
0
);
wsa_assert
(
nbytes
!=
SOCKET_ERROR
);
still_to_send
-=
nbytes
;
}
nbytes
=
::
recv
(
*
r_
,
(
char
*
)
(
dummy
+
dummy_size
-
still_to_recv
),
still_to_recv
,
0
);
nbytes
=
::
recv
(
*
r_
,
reinterpret_cast
<
char
*>
(
dummy
+
dummy_size
-
still_to_recv
),
still_to_recv
,
0
);
wsa_assert
(
nbytes
!=
SOCKET_ERROR
);
still_to_recv
-=
nbytes
;
}
...
...
src/ip_resolver.cpp
View file @
4e616f30
...
...
@@ -208,7 +208,7 @@ int zmq::ip_resolver_t::resolve (ip_addr_t *ip_addr_, const char *name_)
port
=
0
;
}
else
{
// Parse the port number (0 is not a valid port).
port
=
(
uint16_t
)
atoi
(
port_str
.
c_str
(
));
port
=
static_cast
<
uint16_t
>
(
atoi
(
port_str
.
c_str
()
));
if
(
port
==
0
)
{
errno
=
EINVAL
;
return
-
1
;
...
...
@@ -239,7 +239,7 @@ int zmq::ip_resolver_t::resolve (ip_addr_t *ip_addr_, const char *name_)
if
(
isalpha
(
if_str
.
at
(
0
)))
{
zone_id
=
do_if_nametoindex
(
if_str
.
c_str
());
}
else
{
zone_id
=
(
uint32_t
)
atoi
(
if_str
.
c_str
(
));
zone_id
=
static_cast
<
uint32_t
>
(
atoi
(
if_str
.
c_str
()
));
}
if
(
zone_id
==
0
)
{
...
...
@@ -557,7 +557,7 @@ int zmq::ip_resolver_t::get_interface_name (unsigned long index,
#ifdef ZMQ_HAVE_WINDOWS_UWP
char
*
buffer
=
(
char
*
)
malloc
(
1024
);
#else
char
*
buffer
=
(
char
*
)
malloc
(
IF_MAX_STRING_SIZE
);
char
*
buffer
=
static_cast
<
char
*>
(
malloc
(
IF_MAX_STRING_SIZE
)
);
#endif
alloc_assert
(
buffer
);
...
...
@@ -582,7 +582,7 @@ int zmq::ip_resolver_t::wchar_to_utf8 (const WCHAR *src, char **dest) const
int
buffer_len
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
src
,
-
1
,
NULL
,
0
,
NULL
,
0
);
char
*
buffer
=
(
char
*
)
malloc
(
buffer_len
);
char
*
buffer
=
static_cast
<
char
*>
(
malloc
(
buffer_len
)
);
alloc_assert
(
buffer
);
rc
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
src
,
-
1
,
buffer
,
buffer_len
,
NULL
,
0
);
...
...
@@ -608,7 +608,7 @@ int zmq::ip_resolver_t::resolve_nic_name (ip_addr_t *ip_addr_, const char *nic_)
unsigned
long
out_buf_len
=
sizeof
(
IP_ADAPTER_ADDRESSES
);
do
{
addresses
=
(
IP_ADAPTER_ADDRESSES
*
)
malloc
(
out_buf_len
);
addresses
=
static_cast
<
IP_ADAPTER_ADDRESSES
*>
(
malloc
(
out_buf_len
)
);
alloc_assert
(
addresses
);
rc
=
...
...
src/mechanism.cpp
View file @
4e616f30
...
...
@@ -209,14 +209,14 @@ void zmq::mechanism_t::make_command_with_basic_properties (
const
int
rc
=
msg_
->
init_size
(
command_size
);
errno_assert
(
rc
==
0
);
unsigned
char
*
ptr
=
(
unsigned
char
*
)
msg_
->
data
(
);
unsigned
char
*
ptr
=
static_cast
<
unsigned
char
*>
(
msg_
->
data
()
);
// Add prefix
memcpy
(
ptr
,
prefix_
,
prefix_len_
);
ptr
+=
prefix_len_
;
add_basic_properties
(
ptr
,
command_size
-
(
ptr
-
(
unsigned
char
*
)
msg_
->
data
(
)));
add_basic_properties
(
ptr
,
command_size
-
(
ptr
-
static_cast
<
unsigned
char
*>
(
msg_
->
data
()
)));
}
int
zmq
::
mechanism_t
::
parse_metadata
(
const
unsigned
char
*
ptr_
,
...
...
@@ -251,7 +251,8 @@ int zmq::mechanism_t::parse_metadata (const unsigned char *ptr_,
if
(
name
==
ZMTP_PROPERTY_IDENTITY
&&
options
.
recv_routing_id
)
set_peer_routing_id
(
value
,
value_length
);
else
if
(
name
==
ZMTP_PROPERTY_SOCKET_TYPE
)
{
if
(
!
check_socket_type
((
const
char
*
)
value
,
value_length
))
{
if
(
!
check_socket_type
(
reinterpret_cast
<
const
char
*>
(
value
),
value_length
))
{
errno
=
EINVAL
;
return
-
1
;
}
...
...
src/mechanism_base.cpp
View file @
4e616f30
...
...
@@ -41,7 +41,8 @@ zmq::mechanism_base_t::mechanism_base_t (session_base_t *const session_,
int
zmq
::
mechanism_base_t
::
check_basic_command_structure
(
msg_t
*
msg_
)
{
if
(
msg_
->
size
()
<=
1
||
msg_
->
size
()
<=
((
uint8_t
*
)
msg_
->
data
())[
0
])
{
if
(
msg_
->
size
()
<=
1
||
msg_
->
size
()
<=
(
static_cast
<
uint8_t
*>
(
msg_
->
data
()))[
0
])
{
session
->
get_socket
()
->
event_handshake_failed_protocol
(
session
->
get_endpoint
(),
ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_UNSPECIFIED
);
...
...
src/msg.cpp
View file @
4e616f30
...
...
@@ -88,7 +88,7 @@ int zmq::msg_t::init_size (size_t size_)
u
.
vsm
.
metadata
=
NULL
;
u
.
vsm
.
type
=
type_vsm
;
u
.
vsm
.
flags
=
0
;
u
.
vsm
.
size
=
(
unsigned
char
)
size_
;
u
.
vsm
.
size
=
static_cast
<
unsigned
char
>
(
size_
)
;
u
.
vsm
.
group
[
0
]
=
'\0'
;
u
.
vsm
.
routing_id
=
0
;
}
else
{
...
...
@@ -99,7 +99,8 @@ int zmq::msg_t::init_size (size_t size_)
u
.
lmsg
.
routing_id
=
0
;
u
.
lmsg
.
content
=
NULL
;
if
(
sizeof
(
content_t
)
+
size_
>
size_
)
u
.
lmsg
.
content
=
(
content_t
*
)
malloc
(
sizeof
(
content_t
)
+
size_
);
u
.
lmsg
.
content
=
static_cast
<
content_t
*>
(
malloc
(
sizeof
(
content_t
)
+
size_
));
if
(
unlikely
(
!
u
.
lmsg
.
content
))
{
errno
=
ENOMEM
;
return
-
1
;
...
...
@@ -163,7 +164,7 @@ int zmq::msg_t::init_data (void *data_,
u
.
lmsg
.
flags
=
0
;
u
.
lmsg
.
group
[
0
]
=
'\0'
;
u
.
lmsg
.
routing_id
=
0
;
u
.
lmsg
.
content
=
(
content_t
*
)
malloc
(
sizeof
(
content_t
));
u
.
lmsg
.
content
=
static_cast
<
content_t
*>
(
malloc
(
sizeof
(
content_t
)
));
if
(
!
u
.
lmsg
.
content
)
{
errno
=
ENOMEM
;
return
-
1
;
...
...
src/options.cpp
View file @
4e616f30
...
...
@@ -75,7 +75,8 @@ int zmq::do_getsockopt (void *const optval_,
}
memcpy
(
optval_
,
value_
,
value_len_
);
// TODO why is the remaining memory null-ed?
memset
((
char
*
)
optval_
+
value_len_
,
0
,
*
optvallen_
-
value_len_
);
memset
(
static_cast
<
char
*>
(
optval_
)
+
value_len_
,
0
,
*
optvallen_
-
value_len_
);
*
optvallen_
=
value_len_
;
return
0
;
}
...
...
@@ -89,7 +90,8 @@ static int do_getsockopt_curve_key (void *const optval_,
memcpy
(
optval_
,
curve_key_
,
CURVE_KEYSIZE
);
return
0
;
}
else
if
(
*
optvallen_
==
CURVE_KEYSIZE_Z85
+
1
)
{
zmq_z85_encode
((
char
*
)
optval_
,
curve_key_
,
CURVE_KEYSIZE
);
zmq_z85_encode
(
static_cast
<
char
*>
(
optval_
),
curve_key_
,
CURVE_KEYSIZE
);
return
0
;
}
return
sockopt_invalid
();
...
...
@@ -148,7 +150,7 @@ do_setsockopt_string_allow_empty_strict (const void *const optval_,
out_value_
->
clear
();
return
0
;
}
else
if
(
optval_
!=
NULL
&&
optvallen_
>
0
&&
optvallen_
<=
max_len_
)
{
out_value_
->
assign
(
(
const
char
*
)
optval_
,
optvallen_
);
out_value_
->
assign
(
static_cast
<
const
char
*>
(
optval_
)
,
optvallen_
);
return
0
;
}
return
sockopt_invalid
();
...
...
@@ -163,7 +165,7 @@ do_setsockopt_string_allow_empty_relaxed (const void *const optval_,
// TODO use either do_setsockopt_string_allow_empty_relaxed or
// do_setsockopt_string_allow_empty_strict everywhere
if
(
optvallen_
>
0
&&
optvallen_
<=
max_len_
)
{
out_value_
->
assign
(
(
const
char
*
)
optval_
,
optvallen_
);
out_value_
->
assign
(
static_cast
<
const
char
*>
(
optval_
)
,
optvallen_
);
return
0
;
}
return
sockopt_invalid
();
...
...
@@ -312,7 +314,7 @@ int zmq::options_t::setsockopt (int option_,
case
ZMQ_ROUTING_ID
:
// Routing id is any binary string from 1 to 255 octets
if
(
optvallen_
>
0
&&
optvallen_
<
256
)
{
routing_id_size
=
(
unsigned
char
)
optvallen_
;
routing_id_size
=
static_cast
<
unsigned
char
>
(
optvallen_
)
;
memcpy
(
routing_id
,
optval_
,
routing_id_size
);
return
0
;
}
...
...
@@ -529,7 +531,8 @@ int zmq::options_t::setsockopt (int option_,
mechanism
=
ZMQ_NULL
;
return
0
;
}
else
if
(
optvallen_
>
0
&&
optvallen_
<
256
&&
optval_
!=
NULL
)
{
plain_username
.
assign
((
const
char
*
)
optval_
,
optvallen_
);
plain_username
.
assign
(
static_cast
<
const
char
*>
(
optval_
),
optvallen_
);
as_server
=
0
;
mechanism
=
ZMQ_PLAIN
;
return
0
;
...
...
@@ -541,7 +544,8 @@ int zmq::options_t::setsockopt (int option_,
mechanism
=
ZMQ_NULL
;
return
0
;
}
else
if
(
optvallen_
>
0
&&
optvallen_
<
256
&&
optval_
!=
NULL
)
{
plain_password
.
assign
((
const
char
*
)
optval_
,
optvallen_
);
plain_password
.
assign
(
static_cast
<
const
char
*>
(
optval_
),
optvallen_
);
as_server
=
0
;
mechanism
=
ZMQ_PLAIN
;
return
0
;
...
...
@@ -662,7 +666,7 @@ int zmq::options_t::setsockopt (int option_,
// Convert this to deciseconds from milliseconds
value
=
value
/
100
;
if
(
is_int
&&
value
>=
0
&&
value
<=
6553
)
{
heartbeat_ttl
=
(
uint16_t
)
value
;
heartbeat_ttl
=
static_cast
<
uint16_t
>
(
value
)
;
return
0
;
}
break
;
...
...
@@ -764,7 +768,7 @@ int zmq::options_t::getsockopt (int option_,
size_t
*
optvallen_
)
const
{
bool
is_int
=
(
*
optvallen_
==
sizeof
(
int
));
int
*
value
=
(
int
*
)
optval_
;
int
*
value
=
static_cast
<
int
*>
(
optval_
)
;
#if defined(ZMQ_ACT_MILITANT)
bool
malformed
=
true
;
// Did caller pass a bad option value?
#endif
...
...
@@ -786,7 +790,7 @@ int zmq::options_t::getsockopt (int option_,
case
ZMQ_AFFINITY
:
if
(
*
optvallen_
==
sizeof
(
uint64_t
))
{
*
(
(
uint64_t
*
)
optval_
)
=
affinity
;
*
(
static_cast
<
uint64_t
*>
(
optval_
)
)
=
affinity
;
return
0
;
}
break
;
...
...
@@ -882,7 +886,7 @@ int zmq::options_t::getsockopt (int option_,
case
ZMQ_MAXMSGSIZE
:
if
(
*
optvallen_
==
sizeof
(
int64_t
))
{
*
(
(
int64_t
*
)
optval_
)
=
maxmsgsize
;
*
(
static_cast
<
int64_t
*>
(
optval_
)
)
=
maxmsgsize
;
*
optvallen_
=
sizeof
(
int64_t
);
return
0
;
}
...
...
src/own.cpp
View file @
4e616f30
...
...
@@ -163,7 +163,7 @@ void zmq::own_t::process_term (int linger_)
// Send termination request to all owned objects.
for
(
owned_t
::
iterator
it
=
owned
.
begin
();
it
!=
owned
.
end
();
++
it
)
send_term
(
*
it
,
linger_
);
register_term_acks
(
(
int
)
owned
.
size
(
));
register_term_acks
(
static_cast
<
int
>
(
owned
.
size
()
));
owned
.
clear
();
// Start termination process and check whether by chance we cannot
...
...
src/pipe.cpp
View file @
4e616f30
...
...
@@ -301,7 +301,7 @@ void zmq::pipe_t::process_hiccup (void *pipe_)
// Plug in the new outpipe.
zmq_assert
(
pipe_
);
outpipe
=
(
upipe_t
*
)
pipe_
;
outpipe
=
static_cast
<
upipe_t
*>
(
pipe_
)
;
out_active
=
true
;
// If appropriate, notify the user about the hiccup.
...
...
src/plain_server.cpp
View file @
4e616f30
...
...
@@ -241,7 +241,7 @@ int zmq::plain_server_t::produce_error (msg_t *msg_) const
zmq_assert
(
rc
==
0
);
char
*
msg_data
=
static_cast
<
char
*>
(
msg_
->
data
());
memcpy
(
msg_data
,
"
\5
ERROR"
,
6
);
msg_data
[
6
]
=
(
char
)
status_code
.
length
(
);
msg_data
[
6
]
=
static_cast
<
char
>
(
status_code
.
length
()
);
memcpy
(
msg_data
+
7
,
status_code
.
c_str
(),
status_code
.
length
());
return
0
;
}
...
...
src/poller_base.cpp
View file @
4e616f30
...
...
@@ -132,5 +132,5 @@ void zmq::worker_poller_base_t::check_thread ()
void
zmq
::
worker_poller_base_t
::
worker_routine
(
void
*
arg_
)
{
(
(
worker_poller_base_t
*
)
arg_
)
->
loop
();
(
static_cast
<
worker_poller_base_t
*>
(
arg_
)
)
->
loop
();
}
src/radio.cpp
View file @
4e616f30
...
...
@@ -215,11 +215,11 @@ int zmq::radio_session_t::push_msg (msg_t *msg_)
// Set the msg type to either JOIN or LEAVE
if
(
data_size
>=
5
&&
memcmp
(
command_data
,
"
\4
JOIN"
,
5
)
==
0
)
{
group_length
=
(
int
)
data_size
-
5
;
group_length
=
static_cast
<
int
>
(
data_size
)
-
5
;
group
=
command_data
+
5
;
rc
=
join_leave_msg
.
init_join
();
}
else
if
(
data_size
>=
6
&&
memcmp
(
command_data
,
"
\5
LEAVE"
,
6
)
==
0
)
{
group_length
=
(
int
)
data_size
-
6
;
group_length
=
static_cast
<
int
>
(
data_size
)
-
6
;
group
=
command_data
+
6
;
rc
=
join_leave_msg
.
init_leave
();
}
...
...
@@ -252,7 +252,7 @@ int zmq::radio_session_t::pull_msg (msg_t *msg_)
return
rc
;
const
char
*
group
=
pending_msg
.
group
();
int
length
=
(
int
)
strlen
(
group
);
int
length
=
static_cast
<
int
>
(
strlen
(
group
)
);
// First frame is the group
rc
=
msg_
->
init_size
(
length
);
...
...
src/random.cpp
View file @
4e616f30
...
...
@@ -49,18 +49,18 @@
void
zmq
::
seed_random
()
{
#if defined ZMQ_HAVE_WINDOWS
int
pid
=
(
int
)
GetCurrentProcessId
(
);
int
pid
=
static_cast
<
int
>
(
GetCurrentProcessId
()
);
#else
int
pid
=
(
int
)
getpid
();
#endif
srand
(
(
unsigned
int
)
(
clock_t
::
now_us
()
+
pid
));
srand
(
static_cast
<
unsigned
int
>
(
clock_t
::
now_us
()
+
pid
));
}
uint32_t
zmq
::
generate_random
()
{
// Compensate for the fact that rand() returns signed integer.
uint32_t
low
=
(
uint32_t
)
rand
(
);
uint32_t
high
=
(
uint32_t
)
rand
(
);
uint32_t
low
=
static_cast
<
uint32_t
>
(
rand
()
);
uint32_t
high
=
static_cast
<
uint32_t
>
(
rand
()
);
high
<<=
(
sizeof
(
int
)
*
8
-
1
);
return
high
|
low
;
}
...
...
src/raw_decoder.cpp
View file @
4e616f30
...
...
@@ -57,7 +57,7 @@ int zmq::raw_decoder_t::decode (const uint8_t *data_,
size_t
&
bytes_used_
)
{
int
rc
=
in_progress
.
init
(
(
unsigned
char
*
)
data_
,
size_
,
in_progress
.
init
(
const_cast
<
unsigned
char
*>
(
data_
)
,
size_
,
shared_message_memory_allocator
::
call_dec_ref
,
allocator
.
buffer
(),
allocator
.
provide_content
());
...
...
src/reaper.cpp
View file @
4e616f30
...
...
@@ -35,7 +35,7 @@
zmq
::
reaper_t
::
reaper_t
(
class
ctx_t
*
ctx_
,
uint32_t
tid_
)
:
object_t
(
ctx_
,
tid_
),
mailbox_handle
(
(
poller_t
::
handle_t
)
NULL
),
mailbox_handle
(
static_cast
<
poller_t
::
handle_t
>
(
NULL
)
),
poller
(
NULL
),
sockets
(
0
),
terminating
(
false
)
...
...
src/req.cpp
View file @
4e616f30
...
...
@@ -82,7 +82,8 @@ int zmq::req_t::xsend (msg_t *msg_)
request_id
++
;
// Copy request id before sending (see issue #1695 for details).
uint32_t
*
request_id_copy
=
(
uint32_t
*
)
malloc
(
sizeof
(
uint32_t
));
uint32_t
*
request_id_copy
=
static_cast
<
uint32_t
*>
(
malloc
(
sizeof
(
uint32_t
)));
zmq_assert
(
request_id_copy
);
*
request_id_copy
=
request_id
;
...
...
src/router.cpp
View file @
4e616f30
...
...
@@ -212,8 +212,8 @@ int zmq::router_t::xsend (msg_t *msg_)
// Find the pipe associated with the routing id stored in the prefix.
// If there's no such pipe just silently ignore the message, unless
// router_mandatory is set.
blob_t
routing_id
(
(
unsigned
char
*
)
msg_
->
data
(),
msg_
->
size
(
),
zmq
::
reference_tag_t
());
blob_t
routing_id
(
static_cast
<
unsigned
char
*>
(
msg_
->
data
()
),
msg_
->
size
(),
zmq
::
reference_tag_t
());
outpipes_t
::
iterator
it
=
outpipes
.
find
(
routing_id
);
if
(
it
!=
outpipes
.
end
())
{
...
...
@@ -498,7 +498,8 @@ bool zmq::router_t::identify_peer (pipe_t *pipe_)
routing_id
.
set
(
buf
,
sizeof
buf
);
msg
.
close
();
}
else
{
routing_id
.
set
((
unsigned
char
*
)
msg
.
data
(),
msg
.
size
());
routing_id
.
set
(
static_cast
<
unsigned
char
*>
(
msg
.
data
()),
msg
.
size
());
outpipes_t
::
iterator
it
=
outpipes
.
find
(
routing_id
);
msg
.
close
();
...
...
src/select.cpp
View file @
4e616f30
...
...
@@ -295,7 +295,7 @@ void zmq::select_t::loop ()
{
while
(
true
)
{
// Execute any due timers.
int
timeout
=
(
int
)
execute_timers
(
);
int
timeout
=
static_cast
<
int
>
(
execute_timers
()
);
cleanup_retired
();
...
...
@@ -316,8 +316,8 @@ void zmq::select_t::loop ()
#if defined ZMQ_HAVE_OSX
struct
timeval
tv
=
{(
long
)
(
timeout
/
1000
),
timeout
%
1000
*
1000
};
#else
struct
timeval
tv
=
{
(
long
)
(
timeout
/
1000
),
(
long
)
(
timeout
%
1000
*
1000
)};
struct
timeval
tv
=
{
static_cast
<
long
>
(
timeout
/
1000
),
static_cast
<
long
>
(
timeout
%
1000
*
1000
)};
#endif
#if defined ZMQ_HAVE_WINDOWS
...
...
@@ -577,14 +577,15 @@ u_short zmq::select_t::determine_fd_family (fd_t fd_)
int
type
;
int
type_length
=
sizeof
(
int
);
int
rc
=
getsockopt
(
fd_
,
SOL_SOCKET
,
SO_TYPE
,
(
char
*
)
&
type
,
&
type_length
);
int
rc
=
getsockopt
(
fd_
,
SOL_SOCKET
,
SO_TYPE
,
reinterpret_cast
<
char
*>
(
&
type
)
,
&
type_length
);
if
(
rc
==
0
)
{
if
(
type
==
SOCK_DGRAM
)
return
AF_INET
;
else
{
rc
=
getsockname
(
fd_
,
(
sockaddr
*
)
&
addr
,
&
addr_size
);
rc
=
getsockname
(
fd_
,
reinterpret_cast
<
sockaddr
*>
(
&
addr
),
&
addr_size
);
// AF_INET and AF_INET6 can be mixed in select
// TODO: If proven otherwise, should simply return addr.sa_family
...
...
src/signaler.cpp
View file @
4e616f30
...
...
@@ -143,7 +143,8 @@ zmq::signaler_t::~signaler_t ()
if
(
w
!=
retired_fd
)
{
const
struct
linger
so_linger
=
{
1
,
0
};
int
rc
=
setsockopt
(
w
,
SOL_SOCKET
,
SO_LINGER
,
(
const
char
*
)
&
so_linger
,
sizeof
so_linger
);
reinterpret_cast
<
const
char
*>
(
&
so_linger
),
sizeof
so_linger
);
// Only check shutdown if WSASTARTUP was previously done
if
(
rc
==
0
||
WSAGetLastError
()
!=
WSANOTINITIALISED
)
{
wsa_assert
(
rc
!=
SOCKET_ERROR
);
...
...
@@ -187,7 +188,8 @@ void zmq::signaler_t::send ()
#elif defined ZMQ_HAVE_WINDOWS
unsigned
char
dummy
=
0
;
while
(
true
)
{
int
nbytes
=
::
send
(
w
,
(
char
*
)
&
dummy
,
sizeof
(
dummy
),
0
);
int
nbytes
=
::
send
(
w
,
reinterpret_cast
<
char
*>
(
&
dummy
),
sizeof
(
dummy
),
0
);
wsa_assert
(
nbytes
!=
SOCKET_ERROR
);
if
(
unlikely
(
nbytes
==
SOCKET_ERROR
))
continue
;
...
...
@@ -319,7 +321,8 @@ void zmq::signaler_t::recv ()
#else
unsigned
char
dummy
;
#if defined ZMQ_HAVE_WINDOWS
int
nbytes
=
::
recv
(
r
,
(
char
*
)
&
dummy
,
sizeof
(
dummy
),
0
);
int
nbytes
=
::
recv
(
r
,
reinterpret_cast
<
char
*>
(
&
dummy
),
sizeof
(
dummy
),
0
);
wsa_assert
(
nbytes
!=
SOCKET_ERROR
);
#elif defined ZMQ_HAVE_VXWORKS
ssize_t
nbytes
=
::
recv
(
r
,
(
char
*
)
&
dummy
,
sizeof
(
dummy
),
0
);
...
...
@@ -359,7 +362,8 @@ int zmq::signaler_t::recv_failable ()
#else
unsigned
char
dummy
;
#if defined ZMQ_HAVE_WINDOWS
int
nbytes
=
::
recv
(
r
,
(
char
*
)
&
dummy
,
sizeof
(
dummy
),
0
);
int
nbytes
=
::
recv
(
r
,
reinterpret_cast
<
char
*>
(
&
dummy
),
sizeof
(
dummy
),
0
);
if
(
nbytes
==
SOCKET_ERROR
)
{
const
int
last_error
=
WSAGetLastError
();
if
(
last_error
==
WSAEWOULDBLOCK
)
{
...
...
src/socket_base.cpp
View file @
4e616f30
...
...
@@ -196,7 +196,7 @@ zmq::socket_base_t::socket_base_t (ctx_t *parent_,
ctx_terminated
(
false
),
destroyed
(
false
),
poller
(
NULL
),
handle
(
(
poller_t
::
handle_t
)
NULL
),
handle
(
static_cast
<
poller_t
::
handle_t
>
(
NULL
)
),
last_tsc
(
0
),
ticks
(
0
),
rcvmore
(
false
),
...
...
@@ -410,8 +410,8 @@ int zmq::socket_base_t::getsockopt (int option_,
return
-
1
;
}
return
do_getsockopt
<
fd_t
>
(
optval_
,
optvallen_
,
((
mailbox_t
*
)
mailbox
)
->
get_fd
());
return
do_getsockopt
<
fd_t
>
(
optval_
,
optvallen_
,
(
static_cast
<
mailbox_t
*>
(
mailbox
)
)
->
get_fd
());
}
if
(
option_
==
ZMQ_EVENTS
)
{
...
...
@@ -462,7 +462,7 @@ void zmq::socket_base_t::add_signaler (signaler_t *s_)
zmq_assert
(
thread_safe
);
scoped_lock_t
sync_lock
(
sync
);
(
(
mailbox_safe_t
*
)
mailbox
)
->
add_signaler
(
s_
);
(
static_cast
<
mailbox_safe_t
*>
(
mailbox
)
)
->
add_signaler
(
s_
);
}
void
zmq
::
socket_base_t
::
remove_signaler
(
signaler_t
*
s_
)
...
...
@@ -470,7 +470,7 @@ void zmq::socket_base_t::remove_signaler (signaler_t *s_)
zmq_assert
(
thread_safe
);
scoped_lock_t
sync_lock
(
sync
);
(
(
mailbox_safe_t
*
)
mailbox
)
->
remove_signaler
(
s_
);
(
static_cast
<
mailbox_safe_t
*>
(
mailbox
)
)
->
remove_signaler
(
s_
);
}
int
zmq
::
socket_base_t
::
bind
(
const
char
*
addr_
)
...
...
@@ -1146,7 +1146,7 @@ int zmq::socket_base_t::send (msg_t *msg_, int flags_)
return
-
1
;
}
if
(
timeout
>
0
)
{
timeout
=
(
int
)
(
end
-
clock
.
now_ms
());
timeout
=
static_cast
<
int
>
(
end
-
clock
.
now_ms
());
if
(
timeout
<=
0
)
{
errno
=
EAGAIN
;
return
-
1
;
...
...
@@ -1241,7 +1241,7 @@ int zmq::socket_base_t::recv (msg_t *msg_, int flags_)
}
block
=
true
;
if
(
timeout
>
0
)
{
timeout
=
(
int
)
(
end
-
clock
.
now_ms
());
timeout
=
static_cast
<
int
>
(
end
-
clock
.
now_ms
());
if
(
timeout
<=
0
)
{
errno
=
EAGAIN
;
return
-
1
;
...
...
@@ -1259,7 +1259,7 @@ int zmq::socket_base_t::close ()
// Remove all existing signalers for thread safe sockets
if
(
thread_safe
)
(
(
mailbox_safe_t
*
)
mailbox
)
->
clear_signalers
();
(
static_cast
<
mailbox_safe_t
*>
(
mailbox
)
)
->
clear_signalers
();
// Mark the socket as dead
tag
=
0xdeadbeef
;
...
...
@@ -1291,7 +1291,7 @@ void zmq::socket_base_t::start_reaping (poller_t *poller_)
fd_t
fd
;
if
(
!
thread_safe
)
fd
=
(
(
mailbox_t
*
)
mailbox
)
->
get_fd
();
fd
=
(
static_cast
<
mailbox_t
*>
(
mailbox
)
)
->
get_fd
();
else
{
scoped_optional_lock_t
sync_lock
(
thread_safe
?
&
sync
:
NULL
);
...
...
@@ -1300,7 +1300,8 @@ void zmq::socket_base_t::start_reaping (poller_t *poller_)
// Add signaler to the safe mailbox
fd
=
reaper_signaler
->
get_fd
();
((
mailbox_safe_t
*
)
mailbox
)
->
add_signaler
(
reaper_signaler
);
(
static_cast
<
mailbox_safe_t
*>
(
mailbox
))
->
add_signaler
(
reaper_signaler
);
// Send a signal to make sure reaper handle existing commands
reaper_signaler
->
send
();
...
...
@@ -1394,7 +1395,7 @@ void zmq::socket_base_t::process_term (int linger_)
// Ask all attached pipes to terminate.
for
(
pipes_t
::
size_type
i
=
0
;
i
!=
pipes
.
size
();
++
i
)
pipes
[
i
]
->
terminate
(
false
);
register_term_acks
(
(
int
)
pipes
.
size
(
));
register_term_acks
(
static_cast
<
int
>
(
pipes
.
size
()
));
// Continue the termination process immediately.
own_t
::
process_term
(
linger_
);
...
...
@@ -1730,10 +1731,10 @@ void zmq::socket_base_t::monitor_event (int event_,
// Send event in first frame
zmq_msg_t
msg
;
zmq_msg_init_size
(
&
msg
,
6
);
uint8_t
*
data
=
(
uint8_t
*
)
zmq_msg_data
(
&
msg
);
uint8_t
*
data
=
static_cast
<
uint8_t
*>
(
zmq_msg_data
(
&
msg
)
);
// Avoid dereferencing uint32_t on unaligned address
uint16_t
event
=
(
uint16_t
)
event_
;
uint32_t
value
=
(
uint32_t
)
value_
;
uint16_t
event
=
static_cast
<
uint16_t
>
(
event_
)
;
uint32_t
value
=
static_cast
<
uint32_t
>
(
value_
)
;
memcpy
(
data
+
0
,
&
event
,
sizeof
(
event
));
memcpy
(
data
+
2
,
&
value
,
sizeof
(
value
));
zmq_sendmsg
(
monitor_socket
,
&
msg
,
ZMQ_SNDMORE
);
...
...
src/socket_poller.cpp
View file @
4e616f30
...
...
@@ -630,8 +630,8 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_,
}
else
if
(
timeout_
<
0
)
ptimeout
=
NULL
;
else
{
timeout
.
tv_sec
=
(
long
)
((
end
-
now
)
/
1000
);
timeout
.
tv_usec
=
(
long
)
((
end
-
now
)
%
1000
*
1000
);
timeout
.
tv_sec
=
static_cast
<
long
>
((
end
-
now
)
/
1000
);
timeout
.
tv_usec
=
static_cast
<
long
>
((
end
-
now
)
%
1000
*
1000
);
ptimeout
=
&
timeout
;
}
...
...
@@ -643,14 +643,17 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_,
// We just need to copy fd_count elements of fd_array.
// We gain huge memcpy() improvement if number of used SOCKETs is much lower than FD_SETSIZE.
memcpy
(
&
inset
,
&
pollset_in
,
(
char
*
)
(
pollset_in
.
fd_array
+
pollset_in
.
fd_count
)
-
(
char
*
)
&
pollset_in
);
reinterpret_cast
<
char
*>
(
pollset_in
.
fd_array
+
pollset_in
.
fd_count
)
-
reinterpret_cast
<
char
*>
(
&
pollset_in
));
memcpy
(
&
outset
,
&
pollset_out
,
(
char
*
)
(
pollset_out
.
fd_array
+
pollset_out
.
fd_count
)
-
(
char
*
)
&
pollset_out
);
reinterpret_cast
<
char
*>
(
pollset_out
.
fd_array
+
pollset_out
.
fd_count
)
-
reinterpret_cast
<
char
*>
(
&
pollset_out
));
memcpy
(
&
errset
,
&
pollset_err
,
(
char
*
)
(
pollset_err
.
fd_array
+
pollset_err
.
fd_count
)
-
(
char
*
)
&
pollset_err
);
reinterpret_cast
<
char
*>
(
pollset_err
.
fd_array
+
pollset_err
.
fd_count
)
-
reinterpret_cast
<
char
*>
(
&
pollset_err
));
int
rc
=
select
(
0
,
&
inset
,
&
outset
,
&
errset
,
ptimeout
);
if
(
unlikely
(
rc
==
SOCKET_ERROR
))
{
errno
=
zmq
::
wsa_error_to_errno
(
WSAGetLastError
());
...
...
src/socks.cpp
View file @
4e616f30
...
...
@@ -64,7 +64,7 @@ void zmq::socks_greeting_encoder_t::encode (const socks_greeting_t &greeting_)
uint8_t
*
ptr
=
buf
;
*
ptr
++
=
0x05
;
*
ptr
++
=
(
uint8_t
)
greeting_
.
num_methods
;
*
ptr
++
=
static_cast
<
uint8_t
>
(
greeting_
.
num_methods
)
;
for
(
uint8_t
i
=
0
;
i
<
greeting_
.
num_methods
;
i
++
)
*
ptr
++
=
greeting_
.
methods
[
i
];
...
...
@@ -179,7 +179,7 @@ void zmq::socks_request_encoder_t::encode (const socks_request_t &req)
ptr
+=
16
;
}
else
{
*
ptr
++
=
0x03
;
*
ptr
++
=
(
unsigned
char
)
req
.
hostname
.
size
(
);
*
ptr
++
=
static_cast
<
unsigned
char
>
(
req
.
hostname
.
size
()
);
memcpy
(
ptr
,
req
.
hostname
.
c_str
(),
req
.
hostname
.
size
());
ptr
+=
req
.
hostname
.
size
();
}
...
...
src/socks_connecter.cpp
View file @
4e616f30
...
...
@@ -64,7 +64,7 @@ zmq::socks_connecter_t::socks_connecter_t (class io_thread_t *io_thread_,
proxy_addr
(
proxy_addr_
),
status
(
unplugged
),
s
(
retired_fd
),
handle
(
(
handle_t
)
NULL
),
handle
(
static_cast
<
handle_t
>
(
NULL
)
),
handle_valid
(
false
),
delayed_start
(
delayed_start_
),
timer_started
(
false
),
...
...
@@ -178,7 +178,7 @@ void zmq::socks_connecter_t::out_event ()
||
status
==
sending_greeting
||
status
==
sending_request
);
if
(
status
==
waiting_for_proxy_connection
)
{
const
int
rc
=
(
int
)
check_proxy_connection
(
);
const
int
rc
=
static_cast
<
int
>
(
check_proxy_connection
()
);
if
(
rc
==
-
1
)
error
();
else
{
...
...
@@ -394,7 +394,8 @@ zmq::fd_t zmq::socks_connecter_t::check_proxy_connection ()
socklen_t
len
=
sizeof
err
;
#endif
int
rc
=
getsockopt
(
s
,
SOL_SOCKET
,
SO_ERROR
,
(
char
*
)
&
err
,
&
len
);
int
rc
=
getsockopt
(
s
,
SOL_SOCKET
,
SO_ERROR
,
reinterpret_cast
<
char
*>
(
&
err
),
&
len
);
// Assert if the error was caused by 0MQ bug.
// Networking problems are OK. No need to assert.
...
...
@@ -468,7 +469,7 @@ int zmq::socks_connecter_t::parse_address (const std::string &address_,
// Separate the hostname/port.
const
std
::
string
port_str
=
address_
.
substr
(
idx
+
1
);
// Parse the port number (0 is not a valid port).
port_
=
(
uint16_t
)
atoi
(
port_str
.
c_str
(
));
port_
=
static_cast
<
uint16_t
>
(
atoi
(
port_str
.
c_str
()
));
if
(
port_
==
0
)
{
errno
=
EINVAL
;
return
-
1
;
...
...
src/stream.cpp
View file @
4e616f30
...
...
@@ -108,7 +108,8 @@ int zmq::stream_t::xsend (msg_t *msg_)
if
(
msg_
->
flags
()
&
msg_t
::
more
)
{
// Find the pipe associated with the routing id stored in the prefix.
// If there's no such pipe return an error
blob_t
routing_id
((
unsigned
char
*
)
msg_
->
data
(),
msg_
->
size
());
blob_t
routing_id
(
static_cast
<
unsigned
char
*>
(
msg_
->
data
()),
msg_
->
size
());
outpipes_t
::
iterator
it
=
outpipes
.
find
(
routing_id
);
if
(
it
!=
outpipes
.
end
())
{
...
...
@@ -302,7 +303,8 @@ void zmq::stream_t::identify_peer (pipe_t *pipe_)
put_uint32
(
buffer
+
1
,
next_integral_routing_id
++
);
routing_id
.
set
(
buffer
,
sizeof
buffer
);
memcpy
(
options
.
routing_id
,
routing_id
.
data
(),
routing_id
.
size
());
options
.
routing_id_size
=
(
unsigned
char
)
routing_id
.
size
();
options
.
routing_id_size
=
static_cast
<
unsigned
char
>
(
routing_id
.
size
());
}
pipe_
->
set_router_socket_routing_id
(
routing_id
);
// Add the record into output pipes lookup table
...
...
src/stream_engine.cpp
View file @
4e616f30
...
...
@@ -67,7 +67,7 @@ zmq::stream_engine_t::stream_engine_t (fd_t fd_,
const
std
::
string
&
endpoint_
)
:
s
(
fd_
),
as_server
(
false
),
handle
(
(
handle_t
)
NULL
),
handle
(
static_cast
<
handle_t
>
(
NULL
)
),
inpos
(
NULL
),
insize
(
0
),
decoder
(
NULL
),
...
...
@@ -378,7 +378,7 @@ void zmq::stream_engine_t::out_event ()
outpos
=
NULL
;
outsize
=
encoder
->
encode
(
&
outpos
,
0
);
while
(
outsize
<
(
size_t
)
out_batch_size
)
{
while
(
outsize
<
static_cast
<
size_t
>
(
out_batch_size
)
)
{
if
((
this
->*
next_msg
)
(
&
tx_msg
)
==
-
1
)
break
;
encoder
->
load_msg
(
&
tx_msg
);
...
...
@@ -753,7 +753,7 @@ int zmq::stream_engine_t::process_routing_id_msg (msg_t *msg_)
// ZMQ 2.x peers receive published messages.
int
rc
=
subscription
.
init_size
(
1
);
errno_assert
(
rc
==
0
);
*
(
unsigned
char
*
)
subscription
.
data
(
)
=
1
;
*
static_cast
<
unsigned
char
*>
(
subscription
.
data
()
)
=
1
;
rc
=
session
->
push_msg
(
&
subscription
);
errno_assert
(
rc
==
0
);
}
...
...
@@ -1004,7 +1004,7 @@ bool zmq::stream_engine_t::init_properties (properties_t &properties)
// Private property to support deprecated SRCFD
std
::
ostringstream
stream
;
stream
<<
(
int
)
s
;
stream
<<
static_cast
<
int
>
(
s
)
;
std
::
string
fd_string
=
stream
.
str
();
properties
.
ZMQ_MAP_INSERT_OR_EMPLACE
(
std
::
string
(
"__fd"
),
ZMQ_MOVE
(
fd_string
));
...
...
@@ -1045,7 +1045,8 @@ int zmq::stream_engine_t::produce_ping_message (msg_t *msg_)
memcpy
(
msg_
->
data
(),
"
\4
PING"
,
5
);
uint16_t
ttl_val
=
htons
(
options
.
heartbeat_ttl
);
memcpy
(((
uint8_t
*
)
msg_
->
data
())
+
5
,
&
ttl_val
,
sizeof
(
ttl_val
));
memcpy
((
static_cast
<
uint8_t
*>
(
msg_
->
data
()))
+
5
,
&
ttl_val
,
sizeof
(
ttl_val
));
rc
=
mechanism
->
encode
(
msg_
);
next_msg
=
&
stream_engine_t
::
pull_and_encode
;
...
...
@@ -1074,7 +1075,8 @@ int zmq::stream_engine_t::process_heartbeat_message (msg_t *msg_)
if
(
memcmp
(
msg_
->
data
(),
"
\4
PING"
,
5
)
==
0
)
{
uint16_t
remote_heartbeat_ttl
;
// Get the remote heartbeat TTL to setup the timer
memcpy
(
&
remote_heartbeat_ttl
,
(
uint8_t
*
)
msg_
->
data
()
+
5
,
2
);
memcpy
(
&
remote_heartbeat_ttl
,
static_cast
<
uint8_t
*>
(
msg_
->
data
())
+
5
,
2
);
remote_heartbeat_ttl
=
ntohs
(
remote_heartbeat_ttl
);
// The remote heartbeat is in 10ths of a second
// so we multiply it by 100 to get the timer interval in ms.
...
...
@@ -1096,8 +1098,8 @@ int zmq::stream_engine_t::process_heartbeat_message (msg_t *msg_)
pong_msg
.
set_flags
(
msg_t
::
command
);
memcpy
(
pong_msg
.
data
(),
"
\4
PONG"
,
5
);
if
(
context_len
>
0
)
memcpy
((
(
uint8_t
*
)
pong_msg
.
data
(
))
+
5
,
(
(
uint8_t
*
)
msg_
->
data
(
))
+
7
,
context_len
);
memcpy
((
static_cast
<
uint8_t
*>
(
pong_msg
.
data
()
))
+
5
,
(
static_cast
<
uint8_t
*>
(
msg_
->
data
()
))
+
7
,
context_len
);
next_msg
=
&
stream_engine_t
::
produce_pong_message
;
out_event
();
...
...
@@ -1108,12 +1110,12 @@ int zmq::stream_engine_t::process_heartbeat_message (msg_t *msg_)
int
zmq
::
stream_engine_t
::
process_command_message
(
msg_t
*
msg_
)
{
uint8_t
cmd_name_size
=
*
(
(
uint8_t
*
)
msg_
->
data
(
));
uint8_t
cmd_name_size
=
*
(
static_cast
<
uint8_t
*>
(
msg_
->
data
()
));
// Malformed command
if
(
msg_
->
size
()
<
cmd_name_size
+
sizeof
(
cmd_name_size
))
return
-
1
;
uint8_t
*
cmd_name
=
(
(
uint8_t
*
)
msg_
->
data
(
))
+
1
;
uint8_t
*
cmd_name
=
(
static_cast
<
uint8_t
*>
(
msg_
->
data
()
))
+
1
;
if
(
cmd_name_size
==
4
&&
(
memcmp
(
cmd_name
,
"PING"
,
cmd_name_size
)
==
0
||
memcmp
(
cmd_name
,
"PONG"
,
cmd_name_size
)
==
0
))
...
...
src/sub.cpp
View file @
4e616f30
...
...
@@ -58,7 +58,7 @@ int zmq::sub_t::xsetsockopt (int option_,
msg_t
msg
;
int
rc
=
msg
.
init_size
(
optvallen_
+
1
);
errno_assert
(
rc
==
0
);
unsigned
char
*
data
=
(
unsigned
char
*
)
msg
.
data
(
);
unsigned
char
*
data
=
static_cast
<
unsigned
char
*>
(
msg
.
data
()
);
*
data
=
(
option_
==
ZMQ_SUBSCRIBE
);
// We explicitly allow a NULL subscription with size zero
if
(
optvallen_
)
{
...
...
src/tcp.cpp
View file @
4e616f30
...
...
@@ -54,8 +54,8 @@ int zmq::tune_tcp_socket (fd_t s_)
// so using Nagle wouldn't improve throughput in anyway, but it would
// hurt latency.
int
nodelay
=
1
;
int
rc
=
setsockopt
(
s_
,
IPPROTO_TCP
,
TCP_NODELAY
,
(
char
*
)
&
nodelay
,
sizeof
(
int
));
int
rc
=
setsockopt
(
s_
,
IPPROTO_TCP
,
TCP_NODELAY
,
reinterpret_cast
<
char
*>
(
&
nodelay
),
sizeof
(
int
));
tcp_assert_tuning_error
(
s_
,
rc
);
if
(
rc
!=
0
)
return
rc
;
...
...
@@ -72,16 +72,18 @@ int zmq::tune_tcp_socket (fd_t s_)
int
zmq
::
set_tcp_send_buffer
(
fd_t
sockfd_
,
int
bufsize_
)
{
const
int
rc
=
setsockopt
(
sockfd_
,
SOL_SOCKET
,
SO_SNDBUF
,
(
char
*
)
&
bufsize_
,
sizeof
bufsize_
);
const
int
rc
=
setsockopt
(
sockfd_
,
SOL_SOCKET
,
SO_SNDBUF
,
reinterpret_cast
<
char
*>
(
&
bufsize_
),
sizeof
bufsize_
);
tcp_assert_tuning_error
(
sockfd_
,
rc
);
return
rc
;
}
int
zmq
::
set_tcp_receive_buffer
(
fd_t
sockfd_
,
int
bufsize_
)
{
const
int
rc
=
setsockopt
(
sockfd_
,
SOL_SOCKET
,
SO_RCVBUF
,
(
char
*
)
&
bufsize_
,
sizeof
bufsize_
);
const
int
rc
=
setsockopt
(
sockfd_
,
SOL_SOCKET
,
SO_RCVBUF
,
reinterpret_cast
<
char
*>
(
&
bufsize_
),
sizeof
bufsize_
);
tcp_assert_tuning_error
(
sockfd_
,
rc
);
return
rc
;
}
...
...
@@ -184,8 +186,9 @@ int zmq::tune_tcp_maxrt (fd_t sockfd_, int timeout_)
#if defined(ZMQ_HAVE_WINDOWS) && defined(TCP_MAXRT)
// msdn says it's supported in >= Vista, >= Windows Server 2003
timeout_
/=
1000
;
// in seconds
int
rc
=
setsockopt
(
sockfd_
,
IPPROTO_TCP
,
TCP_MAXRT
,
(
char
*
)
&
timeout_
,
sizeof
(
timeout_
));
int
rc
=
setsockopt
(
sockfd_
,
IPPROTO_TCP
,
TCP_MAXRT
,
reinterpret_cast
<
char
*>
(
&
timeout_
),
sizeof
(
timeout_
));
tcp_assert_tuning_error
(
sockfd_
,
rc
);
return
rc
;
// FIXME: should be ZMQ_HAVE_TCP_USER_TIMEOUT
...
...
@@ -203,7 +206,7 @@ int zmq::tcp_write (fd_t s_, const void *data_, size_t size_)
{
#ifdef ZMQ_HAVE_WINDOWS
int
nbytes
=
send
(
s_
,
(
char
*
)
data_
,
(
int
)
size_
,
0
);
int
nbytes
=
send
(
s_
,
(
char
*
)
data_
,
static_cast
<
int
>
(
size_
)
,
0
);
// If not a single byte can be written to the socket in non-blocking mode
// we'll get an error (this may happen during the speculative write).
...
...
@@ -255,7 +258,8 @@ int zmq::tcp_read (fd_t s_, void *data_, size_t size_)
{
#ifdef ZMQ_HAVE_WINDOWS
const
int
rc
=
recv
(
s_
,
(
char
*
)
data_
,
(
int
)
size_
,
0
);
const
int
rc
=
recv
(
s_
,
static_cast
<
char
*>
(
data_
),
static_cast
<
int
>
(
size_
),
0
);
// If not a single byte can be read from the socket in non-blocking mode
// we'll get an error (this may happen during the speculative read).
...
...
@@ -307,7 +311,8 @@ void zmq::tcp_assert_tuning_error (zmq::fd_t s_, int rc_)
socklen_t
len
=
sizeof
err
;
#endif
int
rc
=
getsockopt
(
s_
,
SOL_SOCKET
,
SO_ERROR
,
(
char
*
)
&
err
,
&
len
);
int
rc
=
getsockopt
(
s_
,
SOL_SOCKET
,
SO_ERROR
,
reinterpret_cast
<
char
*>
(
&
err
),
&
len
);
// Assert if the error was caused by 0MQ bug.
// Networking problems are OK. No need to assert.
...
...
src/tcp_address.cpp
View file @
4e616f30
...
...
@@ -61,10 +61,11 @@ zmq::tcp_address_t::tcp_address_t (const sockaddr *sa, socklen_t sa_len) :
memset
(
&
address
,
0
,
sizeof
(
address
));
memset
(
&
source_address
,
0
,
sizeof
(
source_address
));
if
(
sa
->
sa_family
==
AF_INET
&&
sa_len
>=
(
socklen_t
)
sizeof
(
address
.
ipv4
))
if
(
sa
->
sa_family
==
AF_INET
&&
sa_len
>=
static_cast
<
socklen_t
>
(
sizeof
(
address
.
ipv4
)))
memcpy
(
&
address
.
ipv4
,
sa
,
sizeof
(
address
.
ipv4
));
else
if
(
sa
->
sa_family
==
AF_INET6
&&
sa_len
>=
(
socklen_t
)
sizeof
(
address
.
ipv6
))
&&
sa_len
>=
static_cast
<
socklen_t
>
(
sizeof
(
address
.
ipv6
)
))
memcpy
(
&
address
.
ipv6
,
sa
,
sizeof
(
address
.
ipv6
));
}
...
...
@@ -151,9 +152,9 @@ const sockaddr *zmq::tcp_address_t::addr () const
socklen_t
zmq
::
tcp_address_t
::
addrlen
()
const
{
if
(
address
.
generic
.
sa_family
==
AF_INET6
)
return
(
socklen_t
)
sizeof
(
address
.
ipv6
);
return
static_cast
<
socklen_t
>
(
sizeof
(
address
.
ipv6
)
);
else
return
(
socklen_t
)
sizeof
(
address
.
ipv4
);
return
static_cast
<
socklen_t
>
(
sizeof
(
address
.
ipv4
)
);
}
const
sockaddr
*
zmq
::
tcp_address_t
::
src_addr
()
const
...
...
@@ -164,9 +165,9 @@ const sockaddr *zmq::tcp_address_t::src_addr () const
socklen_t
zmq
::
tcp_address_t
::
src_addrlen
()
const
{
if
(
address
.
family
()
==
AF_INET6
)
return
(
socklen_t
)
sizeof
(
source_address
.
ipv6
);
return
static_cast
<
socklen_t
>
(
sizeof
(
source_address
.
ipv6
)
);
else
return
(
socklen_t
)
sizeof
(
source_address
.
ipv4
);
return
static_cast
<
socklen_t
>
(
sizeof
(
source_address
.
ipv4
)
);
}
bool
zmq
::
tcp_address_t
::
has_src_addr
()
const
...
...
@@ -291,15 +292,17 @@ bool zmq::tcp_address_mask_t::match_address (const struct sockaddr *ss,
const
uint8_t
*
our_bytes
,
*
their_bytes
;
if
(
ss
->
sa_family
==
AF_INET6
)
{
zmq_assert
(
ss_len
==
sizeof
(
struct
sockaddr_in6
));
their_bytes
=
(
const
uint8_t
*
)
&
(
((
const
struct
sockaddr_in6
*
)
ss
)
->
sin6_addr
);
our_bytes
=
(
const
uint8_t
*
)
&
address
.
ipv6
.
sin6_addr
;
their_bytes
=
reinterpret_cast
<
const
uint8_t
*>
(
&
(
(
reinterpret_cast
<
const
struct
sockaddr_in6
*>
(
ss
))
->
sin6_addr
));
our_bytes
=
reinterpret_cast
<
const
uint8_t
*>
(
&
address
.
ipv6
.
sin6_addr
);
mask
=
sizeof
(
struct
in6_addr
)
*
8
;
}
else
{
zmq_assert
(
ss_len
==
sizeof
(
struct
sockaddr_in
));
their_bytes
=
(
const
uint8_t
*
)
&
(((
const
struct
sockaddr_in
*
)
ss
)
->
sin_addr
);
our_bytes
=
(
const
uint8_t
*
)
&
address
.
ipv4
.
sin_addr
;
their_bytes
=
reinterpret_cast
<
const
uint8_t
*>
(
&
((
reinterpret_cast
<
const
struct
sockaddr_in
*>
(
ss
))
->
sin_addr
));
our_bytes
=
reinterpret_cast
<
const
uint8_t
*>
(
&
address
.
ipv4
.
sin_addr
);
mask
=
sizeof
(
struct
in_addr
)
*
8
;
}
if
(
address_mask
<
mask
)
...
...
src/tcp_connecter.cpp
View file @
4e616f30
...
...
@@ -69,7 +69,7 @@ zmq::tcp_connecter_t::tcp_connecter_t (class io_thread_t *io_thread_,
io_object_t
(
io_thread_
),
addr
(
addr_
),
s
(
retired_fd
),
handle
(
(
handle_t
)
NULL
),
handle
(
static_cast
<
handle_t
>
(
NULL
)
),
delayed_start
(
delayed_start_
),
connect_timer_started
(
false
),
reconnect_timer_started
(
false
),
...
...
@@ -166,7 +166,7 @@ void zmq::tcp_connecter_t::out_event ()
void
zmq
::
tcp_connecter_t
::
rm_handle
()
{
rm_fd
(
handle
);
handle
=
(
handle_t
)
NULL
;
handle
=
static_cast
<
handle_t
>
(
NULL
)
;
}
void
zmq
::
tcp_connecter_t
::
timer_event
(
int
id_
)
...
...
@@ -325,8 +325,8 @@ int zmq::tcp_connecter_t::open ()
// using the same source port on the client.
int
flag
=
1
;
#ifdef ZMQ_HAVE_WINDOWS
rc
=
setsockopt
(
s
,
SOL_SOCKET
,
SO_REUSEADDR
,
(
const
char
*
)
&
flag
,
sizeof
(
int
));
rc
=
setsockopt
(
s
,
SOL_SOCKET
,
SO_REUSEADDR
,
reinterpret_cast
<
const
char
*>
(
&
flag
),
sizeof
(
int
));
wsa_assert
(
rc
!=
SOCKET_ERROR
);
#elif defined ZMQ_HAVE_VXWORKS
rc
=
setsockopt
(
s
,
SOL_SOCKET
,
SO_REUSEADDR
,
(
char
*
)
&
flag
,
...
...
@@ -383,7 +383,8 @@ zmq::fd_t zmq::tcp_connecter_t::connect ()
socklen_t
len
=
sizeof
err
;
#endif
const
int
rc
=
getsockopt
(
s
,
SOL_SOCKET
,
SO_ERROR
,
(
char
*
)
&
err
,
&
len
);
const
int
rc
=
getsockopt
(
s
,
SOL_SOCKET
,
SO_ERROR
,
reinterpret_cast
<
char
*>
(
&
err
),
&
len
);
// Assert if the error was caused by 0MQ bug.
// Networking problems are OK. No need to assert.
...
...
src/tcp_listener.cpp
View file @
4e616f30
...
...
@@ -66,7 +66,7 @@ zmq::tcp_listener_t::tcp_listener_t (io_thread_t *io_thread_,
own_t
(
io_thread_
,
options_
),
io_object_t
(
io_thread_
),
s
(
retired_fd
),
handle
(
(
handle_t
)
NULL
),
handle
(
static_cast
<
handle_t
>
(
NULL
)
),
socket
(
socket_
)
{
}
...
...
@@ -87,7 +87,7 @@ void zmq::tcp_listener_t::process_plug ()
void
zmq
::
tcp_listener_t
::
process_term
(
int
linger_
)
{
rm_fd
(
handle
);
handle
=
(
handle_t
)
NULL
;
handle
=
static_cast
<
handle_t
>
(
NULL
)
;
close
();
own_t
::
process_term
(
linger_
);
}
...
...
@@ -157,14 +157,14 @@ int zmq::tcp_listener_t::get_address (std::string &addr_)
#else
socklen_t
sl
=
sizeof
(
ss
);
#endif
int
rc
=
getsockname
(
s
,
(
struct
sockaddr
*
)
&
ss
,
&
sl
);
int
rc
=
getsockname
(
s
,
reinterpret_cast
<
struct
sockaddr
*>
(
&
ss
)
,
&
sl
);
if
(
rc
!=
0
)
{
addr_
.
clear
();
return
rc
;
}
tcp_address_t
addr
(
(
struct
sockaddr
*
)
&
ss
,
sl
);
tcp_address_t
addr
(
reinterpret_cast
<
struct
sockaddr
*>
(
&
ss
)
,
sl
);
return
addr
.
to_string
(
addr_
);
}
...
...
@@ -236,8 +236,8 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
// Allow reusing of the address.
int
flag
=
1
;
#ifdef ZMQ_HAVE_WINDOWS
rc
=
setsockopt
(
s
,
SOL_SOCKET
,
SO_EXCLUSIVEADDRUSE
,
(
const
char
*
)
&
flag
,
sizeof
(
int
));
rc
=
setsockopt
(
s
,
SOL_SOCKET
,
SO_EXCLUSIVEADDRUSE
,
reinterpret_cast
<
const
char
*>
(
&
flag
),
sizeof
(
int
));
wsa_assert
(
rc
!=
SOCKET_ERROR
);
#elif defined ZMQ_HAVE_VXWORKS
rc
=
setsockopt
(
s
,
SOL_SOCKET
,
SO_REUSEADDR
,
(
char
*
)
&
flag
,
sizeof
(
int
));
...
...
@@ -302,7 +302,8 @@ zmq::fd_t zmq::tcp_listener_t::accept ()
#if defined ZMQ_HAVE_SOCK_CLOEXEC && defined HAVE_ACCEPT4
fd_t
sock
=
::
accept4
(
s
,
(
struct
sockaddr
*
)
&
ss
,
&
ss_len
,
SOCK_CLOEXEC
);
#else
fd_t
sock
=
::
accept
(
s
,
(
struct
sockaddr
*
)
&
ss
,
&
ss_len
);
fd_t
sock
=
::
accept
(
s
,
reinterpret_cast
<
struct
sockaddr
*>
(
&
ss
),
&
ss_len
);
#endif
#ifdef ZMQ_HAVE_WINDOWS
...
...
src/timers.cpp
View file @
4e616f30
...
...
@@ -146,7 +146,7 @@ long zmq::timers_t::timeout ()
// Live timer, lets return the timeout
if
(
cancelled_it
==
cancelled_timers
.
end
())
{
if
(
it
->
first
>
now
)
return
(
long
)
(
it
->
first
-
now
);
return
static_cast
<
long
>
(
it
->
first
-
now
);
else
return
0
;
}
...
...
src/trie.cpp
View file @
4e616f30
...
...
@@ -74,7 +74,8 @@ bool zmq::trie_t::add (unsigned char *prefix_, size_t size_)
unsigned
char
oldc
=
min
;
trie_t
*
oldp
=
next
.
node
;
count
=
(
min
<
c
?
c
-
min
:
min
-
c
)
+
1
;
next
.
table
=
(
trie_t
**
)
malloc
(
sizeof
(
trie_t
*
)
*
count
);
next
.
table
=
static_cast
<
trie_t
**>
(
malloc
(
sizeof
(
trie_t
*
)
*
count
));
alloc_assert
(
next
.
table
);
for
(
unsigned
short
i
=
0
;
i
!=
count
;
++
i
)
next
.
table
[
i
]
=
0
;
...
...
@@ -84,8 +85,8 @@ bool zmq::trie_t::add (unsigned char *prefix_, size_t size_)
// The new character is above the current character range.
unsigned
short
old_count
=
count
;
count
=
c
-
min
+
1
;
next
.
table
=
(
trie_t
**
)
realloc
((
void
*
)
next
.
table
,
sizeof
(
trie_t
*
)
*
count
);
next
.
table
=
static_cast
<
trie_t
**>
(
realloc
((
void
*
)
next
.
table
,
sizeof
(
trie_t
*
)
*
count
)
);
zmq_assert
(
next
.
table
);
for
(
unsigned
short
i
=
old_count
;
i
!=
count
;
i
++
)
next
.
table
[
i
]
=
NULL
;
...
...
@@ -93,8 +94,8 @@ bool zmq::trie_t::add (unsigned char *prefix_, size_t size_)
// The new character is below the current character range.
unsigned
short
old_count
=
count
;
count
=
(
min
+
old_count
)
-
c
;
next
.
table
=
(
trie_t
**
)
realloc
((
void
*
)
next
.
table
,
sizeof
(
trie_t
*
)
*
count
);
next
.
table
=
static_cast
<
trie_t
**>
(
realloc
((
void
*
)
next
.
table
,
sizeof
(
trie_t
*
)
*
count
)
);
zmq_assert
(
next
.
table
);
memmove
(
next
.
table
+
min
-
c
,
next
.
table
,
old_count
*
sizeof
(
trie_t
*
));
...
...
@@ -200,7 +201,8 @@ bool zmq::trie_t::rm (unsigned char *prefix_, size_t size_)
zmq_assert
(
count
>
new_min
-
min
);
count
=
count
-
(
new_min
-
min
);
next
.
table
=
(
trie_t
**
)
malloc
(
sizeof
(
trie_t
*
)
*
count
);
next
.
table
=
static_cast
<
trie_t
**>
(
malloc
(
sizeof
(
trie_t
*
)
*
count
));
alloc_assert
(
next
.
table
);
memmove
(
next
.
table
,
old_table
+
(
new_min
-
min
),
...
...
@@ -223,7 +225,8 @@ bool zmq::trie_t::rm (unsigned char *prefix_, size_t size_)
count
=
new_count
;
trie_t
**
old_table
=
next
.
table
;
next
.
table
=
(
trie_t
**
)
malloc
(
sizeof
(
trie_t
*
)
*
count
);
next
.
table
=
static_cast
<
trie_t
**>
(
malloc
(
sizeof
(
trie_t
*
)
*
count
));
alloc_assert
(
next
.
table
);
memmove
(
next
.
table
,
old_table
,
sizeof
(
trie_t
*
)
*
count
);
...
...
@@ -290,7 +293,7 @@ void zmq::trie_t::apply_helper (unsigned char **buff_,
// Adjust the buffer.
if
(
buffsize_
>=
maxbuffsize_
)
{
maxbuffsize_
=
buffsize_
+
256
;
*
buff_
=
(
unsigned
char
*
)
realloc
(
*
buff_
,
maxbuffsize_
);
*
buff_
=
static_cast
<
unsigned
char
*>
(
realloc
(
*
buff_
,
maxbuffsize_
)
);
zmq_assert
(
*
buff_
);
}
...
...
src/udp_engine.cpp
View file @
4e616f30
...
...
@@ -55,7 +55,7 @@ zmq::udp_engine_t::udp_engine_t (const options_t &options_) :
plugged
(
false
),
fd
(
-
1
),
session
(
NULL
),
handle
(
(
handle_t
)
NULL
),
handle
(
static_cast
<
handle_t
>
(
NULL
)
),
address
(
NULL
),
options
(
options_
),
send_enabled
(
false
),
...
...
@@ -135,8 +135,9 @@ void zmq::udp_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_)
}
int
loop
=
options
.
multicast_loop
;
int
rc
=
setsockopt
(
fd
,
level
,
optname
,
(
char
*
)
&
loop
,
sizeof
(
loop
));
int
rc
=
setsockopt
(
fd
,
level
,
optname
,
reinterpret_cast
<
char
*>
(
&
loop
),
sizeof
(
loop
));
#ifdef ZMQ_HAVE_WINDOWS
wsa_assert
(
rc
!=
SOCKET_ERROR
);
...
...
@@ -151,7 +152,8 @@ void zmq::udp_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_)
// If a bind interface is provided we tell the
// kernel to use it to send multicast packets
rc
=
setsockopt
(
fd
,
IPPROTO_IPV6
,
IPV6_MULTICAST_IF
,
(
char
*
)
&
bind_if
,
sizeof
(
bind_if
));
reinterpret_cast
<
char
*>
(
&
bind_if
),
sizeof
(
bind_if
));
}
else
{
rc
=
0
;
}
...
...
@@ -160,9 +162,9 @@ void zmq::udp_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_)
udp_addr
->
bind_addr
()
->
ipv4
.
sin_addr
;
if
(
bind_addr
.
s_addr
!=
INADDR_ANY
)
{
rc
=
setsockopt
(
fd
,
IPPROTO_IP
,
IP_MULTICAST_IF
,
(
char
*
)
&
bind_addr
,
sizeof
(
bind_addr
));
rc
=
setsockopt
(
fd
,
IPPROTO_IP
,
IP_MULTICAST_IF
,
reinterpret_cast
<
char
*>
(
&
bind_addr
)
,
sizeof
(
bind_addr
));
}
else
{
rc
=
0
;
}
...
...
@@ -176,7 +178,7 @@ void zmq::udp_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_)
}
}
else
{
/// XXX fixme ?
out_address
=
(
sockaddr
*
)
&
raw_address
;
out_address
=
reinterpret_cast
<
sockaddr
*>
(
&
raw_address
)
;
out_addrlen
=
sizeof
(
sockaddr_in
);
}
...
...
@@ -185,8 +187,8 @@ void zmq::udp_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_)
if
(
recv_enabled
)
{
int
on
=
1
;
int
rc
=
setsockopt
(
fd
,
SOL_SOCKET
,
SO_REUSEADDR
,
(
char
*
)
&
on
,
sizeof
(
on
));
int
rc
=
setsockopt
(
fd
,
SOL_SOCKET
,
SO_REUSEADDR
,
reinterpret_cast
<
char
*>
(
&
on
)
,
sizeof
(
on
));
#ifdef ZMQ_HAVE_WINDOWS
wsa_assert
(
rc
!=
SOCKET_ERROR
);
#else
...
...
@@ -231,8 +233,9 @@ void zmq::udp_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_)
mreq
.
imr_multiaddr
=
mcast_addr
->
ipv4
.
sin_addr
;
mreq
.
imr_interface
=
bind_addr
->
ipv4
.
sin_addr
;
rc
=
setsockopt
(
fd
,
IPPROTO_IP
,
IP_ADD_MEMBERSHIP
,
(
char
*
)
&
mreq
,
sizeof
(
mreq
));
rc
=
setsockopt
(
fd
,
IPPROTO_IP
,
IP_ADD_MEMBERSHIP
,
reinterpret_cast
<
char
*>
(
&
mreq
),
sizeof
(
mreq
));
errno_assert
(
rc
==
0
);
}
else
if
(
mcast_addr
->
family
()
==
AF_INET6
)
{
...
...
@@ -244,8 +247,9 @@ void zmq::udp_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_)
mreq
.
ipv6mr_multiaddr
=
mcast_addr
->
ipv6
.
sin6_addr
;
mreq
.
ipv6mr_interface
=
iface
;
rc
=
setsockopt
(
fd
,
IPPROTO_IPV6
,
IPV6_ADD_MEMBERSHIP
,
(
char
*
)
&
mreq
,
sizeof
(
mreq
));
rc
=
setsockopt
(
fd
,
IPPROTO_IPV6
,
IPV6_ADD_MEMBERSHIP
,
reinterpret_cast
<
char
*>
(
&
mreq
),
sizeof
(
mreq
));
errno_assert
(
rc
==
0
);
}
else
{
...
...
@@ -284,14 +288,14 @@ void zmq::udp_engine_t::sockaddr_to_msg (zmq::msg_t *msg, sockaddr_in *addr)
char
*
name
=
inet_ntoa
(
addr
->
sin_addr
);
char
port
[
6
];
sprintf
(
port
,
"%d"
,
(
int
)
ntohs
(
addr
->
sin_port
));
sprintf
(
port
,
"%d"
,
static_cast
<
int
>
(
ntohs
(
addr
->
sin_port
)
));
int
size
=
(
int
)
strlen
(
name
)
+
(
int
)
strlen
(
port
)
+
1
+
1
;
// Colon + NULL
int
size
=
static_cast
<
int
>
(
strlen
(
name
))
+
static_cast
<
int
>
(
strlen
(
port
)
)
+
1
+
1
;
// Colon + NULL
int
rc
=
msg
->
init_size
(
size
);
errno_assert
(
rc
==
0
);
msg
->
set_flags
(
msg_t
::
more
);
char
*
address
=
(
char
*
)
msg
->
data
(
);
char
*
address
=
static_cast
<
char
*>
(
msg
->
data
()
);
strcpy
(
address
,
name
);
strcat
(
address
,
":"
);
...
...
@@ -306,7 +310,7 @@ int zmq::udp_engine_t::resolve_raw_address (char *name_, size_t length_)
// Find delimiter, cannot use memrchr as it is not supported on windows
if
(
length_
!=
0
)
{
int
chars_left
=
(
int
)
length_
;
int
chars_left
=
static_cast
<
int
>
(
length_
)
;
char
*
current_char
=
name_
+
length_
;
do
{
if
(
*
(
--
current_char
)
==
':'
)
{
...
...
@@ -325,7 +329,7 @@ int zmq::udp_engine_t::resolve_raw_address (char *name_, size_t length_)
std
::
string
port_str
(
delimiter
+
1
,
name_
+
length_
-
delimiter
-
1
);
// Parse the port number (0 is not a valid port).
uint16_t
port
=
(
uint16_t
)
atoi
(
port_str
.
c_str
(
));
uint16_t
port
=
static_cast
<
uint16_t
>
(
atoi
(
port_str
.
c_str
()
));
if
(
port
==
0
)
{
errno
=
EINVAL
;
return
-
1
;
...
...
@@ -358,7 +362,8 @@ void zmq::udp_engine_t::out_event ()
size_t
size
;
if
(
options
.
raw_socket
)
{
rc
=
resolve_raw_address
((
char
*
)
group_msg
.
data
(),
group_size
);
rc
=
resolve_raw_address
(
static_cast
<
char
*>
(
group_msg
.
data
()),
group_size
);
// We discard the message if address is not valid
if
(
rc
!=
0
)
{
...
...
@@ -378,7 +383,7 @@ void zmq::udp_engine_t::out_event ()
size
=
group_size
+
body_size
+
1
;
// TODO: check if larger than maximum size
out_buffer
[
0
]
=
(
unsigned
char
)
group_size
;
out_buffer
[
0
]
=
static_cast
<
unsigned
char
>
(
group_size
)
;
memcpy
(
out_buffer
+
1
,
group_msg
.
data
(),
group_size
);
memcpy
(
out_buffer
+
1
+
group_size
,
body_msg
.
data
(),
body_size
);
}
...
...
@@ -390,8 +395,9 @@ void zmq::udp_engine_t::out_event ()
errno_assert
(
rc
==
0
);
#ifdef ZMQ_HAVE_WINDOWS
rc
=
sendto
(
fd
,
(
const
char
*
)
out_buffer
,
(
int
)
size
,
0
,
out_address
,
(
int
)
out_addrlen
);
rc
=
sendto
(
fd
,
reinterpret_cast
<
const
char
*>
(
out_buffer
),
static_cast
<
int
>
(
size
),
0
,
out_address
,
static_cast
<
int
>
(
out_addrlen
));
wsa_assert
(
rc
!=
SOCKET_ERROR
);
#elif defined ZMQ_HAVE_VXWORKS
rc
=
sendto
(
fd
,
(
caddr_t
)
out_buffer
,
size
,
0
,
...
...
@@ -428,8 +434,9 @@ void zmq::udp_engine_t::in_event ()
sockaddr_storage
in_address
;
socklen_t
in_addrlen
=
sizeof
(
sockaddr_storage
);
#ifdef ZMQ_HAVE_WINDOWS
int
nbytes
=
recvfrom
(
fd
,
(
char
*
)
in_buffer
,
MAX_UDP_MSG
,
0
,
(
sockaddr
*
)
&
in_address
,
&
in_addrlen
);
int
nbytes
=
recvfrom
(
fd
,
reinterpret_cast
<
char
*>
(
in_buffer
),
MAX_UDP_MSG
,
0
,
reinterpret_cast
<
sockaddr
*>
(
&
in_address
),
&
in_addrlen
);
const
int
last_error
=
WSAGetLastError
();
if
(
nbytes
==
SOCKET_ERROR
)
{
wsa_assert
(
last_error
==
WSAENETDOWN
||
last_error
==
WSAENETRESET
...
...
@@ -465,7 +472,7 @@ void zmq::udp_engine_t::in_event ()
body_size
=
nbytes
;
body_offset
=
0
;
}
else
{
char
*
group_buffer
=
(
char
*
)
in_buffer
+
1
;
char
*
group_buffer
=
reinterpret_cast
<
char
*>
(
in_buffer
)
+
1
;
int
group_size
=
in_buffer
[
0
];
rc
=
msg
.
init_size
(
group_size
);
...
...
src/v1_decoder.cpp
View file @
4e616f30
...
...
@@ -70,7 +70,8 @@ int zmq::v1_decoder_t::one_byte_size_ready (unsigned char const *)
return
-
1
;
}
if
(
maxmsgsize
>=
0
&&
(
int64_t
)
(
*
tmpbuf
-
1
)
>
maxmsgsize
)
{
if
(
maxmsgsize
>=
0
&&
static_cast
<
int64_t
>
(
*
tmpbuf
-
1
)
>
maxmsgsize
)
{
errno
=
EMSGSIZE
;
return
-
1
;
}
...
...
@@ -104,7 +105,8 @@ int zmq::v1_decoder_t::eight_byte_size_ready (unsigned char const *)
}
// Message size must not exceed the maximum allowed size.
if
(
maxmsgsize
>=
0
&&
payload_length
-
1
>
(
uint64_t
)
maxmsgsize
)
{
if
(
maxmsgsize
>=
0
&&
payload_length
-
1
>
static_cast
<
uint64_t
>
(
maxmsgsize
))
{
errno
=
EMSGSIZE
;
return
-
1
;
}
...
...
src/v1_encoder.cpp
View file @
4e616f30
...
...
@@ -63,7 +63,7 @@ void zmq::v1_encoder_t::message_ready ()
// For longer messages write 0xff escape character followed by 8-byte
// message size. In both cases 'flags' field follows.
if
(
size
<
255
)
{
tmpbuf
[
0
]
=
(
unsigned
char
)
size
;
tmpbuf
[
0
]
=
static_cast
<
unsigned
char
>
(
size
)
;
tmpbuf
[
1
]
=
(
in_progress
->
flags
()
&
msg_t
::
more
);
next_step
(
tmpbuf
,
2
,
&
v1_encoder_t
::
size_ready
,
false
);
}
else
{
...
...
src/v2_decoder.cpp
View file @
4e616f30
...
...
@@ -124,7 +124,7 @@ int zmq::v2_decoder_t::size_ready (uint64_t msg_size,
// construct message using n bytes from the buffer as storage
// increase buffer ref count
// if the message will be a large message, pass a valid refcnt memory location as well
rc
=
in_progress
.
init
(
(
unsigned
char
*
)
read_pos
,
rc
=
in_progress
.
init
(
const_cast
<
unsigned
char
*>
(
read_pos
)
,
static_cast
<
size_t
>
(
msg_size
),
shared_message_memory_allocator
::
call_dec_ref
,
buffer
(),
provide_content
());
...
...
src/wire.hpp
View file @
4e616f30
...
...
@@ -49,47 +49,54 @@ inline uint8_t get_uint8 (const unsigned char *buffer_)
inline
void
put_uint16
(
unsigned
char
*
buffer_
,
uint16_t
value
)
{
buffer_
[
0
]
=
(
unsigned
char
)
(((
value
)
>>
8
)
&
0xff
);
buffer_
[
1
]
=
(
unsigned
char
)
(
value
&
0xff
);
buffer_
[
0
]
=
static_cast
<
unsigned
char
>
(((
value
)
>>
8
)
&
0xff
);
buffer_
[
1
]
=
static_cast
<
unsigned
char
>
(
value
&
0xff
);
}
inline
uint16_t
get_uint16
(
const
unsigned
char
*
buffer_
)
{
return
(((
uint16_t
)
buffer_
[
0
])
<<
8
)
|
((
uint16_t
)
buffer_
[
1
]);
return
((
static_cast
<
uint16_t
>
(
buffer_
[
0
]))
<<
8
)
|
(
static_cast
<
uint16_t
>
(
buffer_
[
1
]));
}
inline
void
put_uint32
(
unsigned
char
*
buffer_
,
uint32_t
value
)
{
buffer_
[
0
]
=
(
unsigned
char
)
(((
value
)
>>
24
)
&
0xff
);
buffer_
[
1
]
=
(
unsigned
char
)
(((
value
)
>>
16
)
&
0xff
);
buffer_
[
2
]
=
(
unsigned
char
)
(((
value
)
>>
8
)
&
0xff
);
buffer_
[
3
]
=
(
unsigned
char
)
(
value
&
0xff
);
buffer_
[
0
]
=
static_cast
<
unsigned
char
>
(((
value
)
>>
24
)
&
0xff
);
buffer_
[
1
]
=
static_cast
<
unsigned
char
>
(((
value
)
>>
16
)
&
0xff
);
buffer_
[
2
]
=
static_cast
<
unsigned
char
>
(((
value
)
>>
8
)
&
0xff
);
buffer_
[
3
]
=
static_cast
<
unsigned
char
>
(
value
&
0xff
);
}
inline
uint32_t
get_uint32
(
const
unsigned
char
*
buffer_
)
{
return
(((
uint32_t
)
buffer_
[
0
])
<<
24
)
|
(((
uint32_t
)
buffer_
[
1
])
<<
16
)
|
(((
uint32_t
)
buffer_
[
2
])
<<
8
)
|
((
uint32_t
)
buffer_
[
3
]);
return
((
static_cast
<
uint32_t
>
(
buffer_
[
0
]))
<<
24
)
|
((
static_cast
<
uint32_t
>
(
buffer_
[
1
]))
<<
16
)
|
((
static_cast
<
uint32_t
>
(
buffer_
[
2
]))
<<
8
)
|
(
static_cast
<
uint32_t
>
(
buffer_
[
3
]));
}
inline
void
put_uint64
(
unsigned
char
*
buffer_
,
uint64_t
value
)
{
buffer_
[
0
]
=
(
unsigned
char
)
(((
value
)
>>
56
)
&
0xff
);
buffer_
[
1
]
=
(
unsigned
char
)
(((
value
)
>>
48
)
&
0xff
);
buffer_
[
2
]
=
(
unsigned
char
)
(((
value
)
>>
40
)
&
0xff
);
buffer_
[
3
]
=
(
unsigned
char
)
(((
value
)
>>
32
)
&
0xff
);
buffer_
[
4
]
=
(
unsigned
char
)
(((
value
)
>>
24
)
&
0xff
);
buffer_
[
5
]
=
(
unsigned
char
)
(((
value
)
>>
16
)
&
0xff
);
buffer_
[
6
]
=
(
unsigned
char
)
(((
value
)
>>
8
)
&
0xff
);
buffer_
[
7
]
=
(
unsigned
char
)
(
value
&
0xff
);
buffer_
[
0
]
=
static_cast
<
unsigned
char
>
(((
value
)
>>
56
)
&
0xff
);
buffer_
[
1
]
=
static_cast
<
unsigned
char
>
(((
value
)
>>
48
)
&
0xff
);
buffer_
[
2
]
=
static_cast
<
unsigned
char
>
(((
value
)
>>
40
)
&
0xff
);
buffer_
[
3
]
=
static_cast
<
unsigned
char
>
(((
value
)
>>
32
)
&
0xff
);
buffer_
[
4
]
=
static_cast
<
unsigned
char
>
(((
value
)
>>
24
)
&
0xff
);
buffer_
[
5
]
=
static_cast
<
unsigned
char
>
(((
value
)
>>
16
)
&
0xff
);
buffer_
[
6
]
=
static_cast
<
unsigned
char
>
(((
value
)
>>
8
)
&
0xff
);
buffer_
[
7
]
=
static_cast
<
unsigned
char
>
(
value
&
0xff
);
}
inline
uint64_t
get_uint64
(
const
unsigned
char
*
buffer_
)
{
return
(((
uint64_t
)
buffer_
[
0
])
<<
56
)
|
(((
uint64_t
)
buffer_
[
1
])
<<
48
)
|
(((
uint64_t
)
buffer_
[
2
])
<<
40
)
|
(((
uint64_t
)
buffer_
[
3
])
<<
32
)
|
(((
uint64_t
)
buffer_
[
4
])
<<
24
)
|
(((
uint64_t
)
buffer_
[
5
])
<<
16
)
|
(((
uint64_t
)
buffer_
[
6
])
<<
8
)
|
((
uint64_t
)
buffer_
[
7
]);
return
((
static_cast
<
uint64_t
>
(
buffer_
[
0
]))
<<
56
)
|
((
static_cast
<
uint64_t
>
(
buffer_
[
1
]))
<<
48
)
|
((
static_cast
<
uint64_t
>
(
buffer_
[
2
]))
<<
40
)
|
((
static_cast
<
uint64_t
>
(
buffer_
[
3
]))
<<
32
)
|
((
static_cast
<
uint64_t
>
(
buffer_
[
4
]))
<<
24
)
|
((
static_cast
<
uint64_t
>
(
buffer_
[
5
]))
<<
16
)
|
((
static_cast
<
uint64_t
>
(
buffer_
[
6
]))
<<
8
)
|
(
static_cast
<
uint64_t
>
(
buffer_
[
7
]));
}
}
...
...
src/xpub.cpp
View file @
4e616f30
...
...
@@ -89,7 +89,7 @@ void zmq::xpub_t::xread_activated (pipe_t *pipe_)
msg_t
sub
;
while
(
pipe_
->
read
(
&
sub
))
{
// Apply the subscription to the trie
unsigned
char
*
const
data
=
(
unsigned
char
*
)
sub
.
data
(
);
unsigned
char
*
const
data
=
static_cast
<
unsigned
char
*>
(
sub
.
data
()
);
const
size_t
size
=
sub
.
size
();
metadata_t
*
metadata
=
sub
.
metadata
();
if
(
size
>
0
&&
(
*
data
==
0
||
*
data
==
1
))
{
...
...
@@ -183,7 +183,8 @@ int zmq::xpub_t::xsetsockopt (int option_,
int
rc
=
welcome_msg
.
init_size
(
optvallen_
);
errno_assert
(
rc
==
0
);
unsigned
char
*
data
=
(
unsigned
char
*
)
welcome_msg
.
data
();
unsigned
char
*
data
=
static_cast
<
unsigned
char
*>
(
welcome_msg
.
data
());
memcpy
(
data
,
optval_
,
optvallen_
);
}
else
welcome_msg
.
init
();
...
...
@@ -232,8 +233,8 @@ int zmq::xpub_t::xsend (msg_t *msg_)
// For the first part of multi-part message, find the matching pipes.
if
(
!
more
)
{
subscriptions
.
match
(
(
unsigned
char
*
)
msg_
->
data
(),
msg_
->
size
(
),
mark_as_matching
,
this
);
subscriptions
.
match
(
static_cast
<
unsigned
char
*>
(
msg_
->
data
()
),
m
sg_
->
size
(),
m
ark_as_matching
,
this
);
// If inverted matching is used, reverse the selection now
if
(
options
.
invert_matching
)
{
dist
.
reverse_match
();
...
...
src/xsub.cpp
View file @
4e616f30
...
...
@@ -94,7 +94,7 @@ void zmq::xsub_t::xhiccuped (pipe_t *pipe_)
int
zmq
::
xsub_t
::
xsend
(
msg_t
*
msg_
)
{
size_t
size
=
msg_
->
size
();
unsigned
char
*
data
=
(
unsigned
char
*
)
msg_
->
data
(
);
unsigned
char
*
data
=
static_cast
<
unsigned
char
*>
(
msg_
->
data
()
);
if
(
size
>
0
&&
*
data
==
1
)
{
// Process subscribe message
...
...
@@ -212,8 +212,8 @@ const zmq::blob_t &zmq::xsub_t::get_credential () const
bool
zmq
::
xsub_t
::
match
(
msg_t
*
msg_
)
{
bool
matching
=
s
ubscriptions
.
check
((
unsigned
char
*
)
msg_
->
data
(
),
msg_
->
size
());
bool
matching
=
subscriptions
.
check
(
s
tatic_cast
<
unsigned
char
*>
(
msg_
->
data
()
),
msg_
->
size
());
return
matching
^
options
.
invert_matching
;
}
...
...
@@ -222,13 +222,13 @@ void zmq::xsub_t::send_subscription (unsigned char *data_,
size_t
size_
,
void
*
arg_
)
{
pipe_t
*
pipe
=
(
pipe_t
*
)
arg_
;
pipe_t
*
pipe
=
static_cast
<
pipe_t
*>
(
arg_
)
;
// Create the subscription message.
msg_t
msg
;
int
rc
=
msg
.
init_size
(
size_
+
1
);
errno_assert
(
rc
==
0
);
unsigned
char
*
data
=
(
unsigned
char
*
)
msg
.
data
(
);
unsigned
char
*
data
=
static_cast
<
unsigned
char
*>
(
msg
.
data
()
);
data
[
0
]
=
1
;
// We explicitly allow a NULL subscription with size zero
...
...
src/zmq.cpp
View file @
4e616f30
This diff is collapsed.
Click to expand it.
src/zmq_utils.cpp
View file @
4e616f30
...
...
@@ -60,7 +60,7 @@ void zmq_sleep (int seconds_)
void
*
zmq_stopwatch_start
()
{
uint64_t
*
watch
=
(
uint64_t
*
)
malloc
(
sizeof
(
uint64_t
));
uint64_t
*
watch
=
static_cast
<
uint64_t
*>
(
malloc
(
sizeof
(
uint64_t
)
));
alloc_assert
(
watch
);
*
watch
=
zmq
::
clock_t
::
now_us
();
return
(
void
*
)
watch
;
...
...
@@ -69,8 +69,8 @@ void *zmq_stopwatch_start ()
unsigned
long
zmq_stopwatch_intermediate
(
void
*
watch_
)
{
uint64_t
end
=
zmq
::
clock_t
::
now_us
();
uint64_t
start
=
*
(
uint64_t
*
)
watch_
;
return
(
unsigned
long
)
(
end
-
start
);
uint64_t
start
=
*
static_cast
<
uint64_t
*>
(
watch_
)
;
return
static_cast
<
unsigned
long
>
(
end
-
start
);
}
unsigned
long
zmq_stopwatch_stop
(
void
*
watch_
)
...
...
@@ -287,14 +287,14 @@ void *zmq_atomic_counter_new (void)
void
zmq_atomic_counter_set
(
void
*
counter_
,
int
value_
)
{
(
(
zmq
::
atomic_counter_t
*
)
counter_
)
->
set
(
value_
);
(
static_cast
<
zmq
::
atomic_counter_t
*>
(
counter_
)
)
->
set
(
value_
);
}
// Increment the atomic counter, and return the old value
int
zmq_atomic_counter_inc
(
void
*
counter_
)
{
return
(
(
zmq
::
atomic_counter_t
*
)
counter_
)
->
add
(
1
);
return
(
static_cast
<
zmq
::
atomic_counter_t
*>
(
counter_
)
)
->
add
(
1
);
}
// Decrement the atomic counter and return 1 (if counter >= 1), or
...
...
@@ -302,20 +302,20 @@ int zmq_atomic_counter_inc (void *counter_)
int
zmq_atomic_counter_dec
(
void
*
counter_
)
{
return
(
(
zmq
::
atomic_counter_t
*
)
counter_
)
->
sub
(
1
)
?
1
:
0
;
return
(
static_cast
<
zmq
::
atomic_counter_t
*>
(
counter_
)
)
->
sub
(
1
)
?
1
:
0
;
}
// Return actual value of atomic counter
int
zmq_atomic_counter_value
(
void
*
counter_
)
{
return
(
(
zmq
::
atomic_counter_t
*
)
counter_
)
->
get
();
return
(
static_cast
<
zmq
::
atomic_counter_t
*>
(
counter_
)
)
->
get
();
}
// Destroy atomic counter, and set reference to NULL
void
zmq_atomic_counter_destroy
(
void
**
counter_p_
)
{
delete
(
(
zmq
::
atomic_counter_t
*
)
*
counter_p_
);
delete
(
static_cast
<
zmq
::
atomic_counter_t
*>
(
*
counter_p_
)
);
*
counter_p_
=
NULL
;
}
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