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
3ee65906
Commit
3ee65906
authored
May 14, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: various warnings regarding SOCKET vs. int in test_security_curve
Solution: Use fd_t
parent
28631d1c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
66 deletions
+53
-66
test_poller.cpp
tests/test_poller.cpp
+0
-24
test_security_curve.cpp
tests/test_security_curve.cpp
+23
-23
testutil.hpp
tests/testutil.hpp
+30
-19
No files found.
tests/test_poller.cpp
View file @
3ee65906
...
...
@@ -42,30 +42,6 @@ void tearDown ()
teardown_test_context
();
}
// duplicated from fd.hpp
#ifdef ZMQ_HAVE_WINDOWS
#define close closesocket
#if defined _MSC_VER && _MSC_VER <= 1400
typedef
UINT_PTR
fd_t
;
enum
{
retired_fd
=
(
fd_t
)
(
~
0
)
};
#else
typedef
SOCKET
fd_t
;
enum
{
retired_fd
=
(
fd_t
)
INVALID_SOCKET
};
#endif
#else
typedef
int
fd_t
;
enum
{
retired_fd
=
-
1
};
#endif
fd_t
get_fd
(
void
*
socket
)
{
fd_t
fd
;
...
...
tests/test_security_curve.cpp
View file @
3ee65906
...
...
@@ -241,9 +241,9 @@ void test_curve_security_with_plain_client_credentials ()
expect_zmtp_mechanism_mismatch
(
client
,
my_endpoint
,
server
,
server_mon
);
}
in
t
connect_vanilla_socket
(
char
*
my_endpoint
)
fd_
t
connect_vanilla_socket
(
char
*
my_endpoint
)
{
in
t
s
;
fd_
t
s
;
struct
sockaddr_in
ip4addr
;
unsigned
short
int
port
;
...
...
@@ -267,7 +267,7 @@ int connect_vanilla_socket (char *my_endpoint)
void
test_curve_security_unauthenticated_message
()
{
// Unauthenticated messages from a vanilla socket shouldn't be received
in
t
s
=
connect_vanilla_socket
(
my_endpoint
);
fd_
t
s
=
connect_vanilla_socket
(
my_endpoint
);
// send anonymous ZMTP/1.0 greeting
send
(
s
,
"
\x01\x00
"
,
2
,
0
);
// send sneaky message that shouldn't be received
...
...
@@ -279,7 +279,7 @@ void test_curve_security_unauthenticated_message ()
close
(
s
);
}
void
send_all
(
int
fd
,
const
char
*
data
,
size_t
size
)
void
send_all
(
fd_t
fd
,
const
char
*
data
,
socket_
size_t
size
)
{
while
(
size
>
0
)
{
int
res
=
send
(
fd
,
data
,
size
,
0
);
...
...
@@ -289,12 +289,12 @@ void send_all (int fd, const char *data, size_t size)
}
}
template
<
size_t
N
>
void
send
(
in
t
fd
,
const
char
(
&
data
)[
N
])
template
<
size_t
N
>
void
send
(
fd_
t
fd
,
const
char
(
&
data
)[
N
])
{
send_all
(
fd
,
data
,
N
-
1
);
}
void
send_greeting
(
in
t
s
)
void
send_greeting
(
fd_
t
s
)
{
send
(
s
,
"
\xff\0\0\0\0\0\0\0\0\x7f
"
);
// signature
send
(
s
,
"
\x03\x00
"
);
// version 3.0
...
...
@@ -305,7 +305,7 @@ void send_greeting (int s)
void
test_curve_security_invalid_hello_wrong_length
()
{
in
t
s
=
connect_vanilla_socket
(
my_endpoint
);
fd_
t
s
=
connect_vanilla_socket
(
my_endpoint
);
// send GREETING
send_greeting
(
s
);
...
...
@@ -360,7 +360,7 @@ uint64_t htonll (uint64_t value)
}
#endif
template
<
size_t
N
>
void
send_command
(
in
t
s
,
char
(
&
command
)[
N
])
template
<
size_t
N
>
void
send_command
(
fd_
t
s
,
char
(
&
command
)[
N
])
{
if
(
N
<
256
)
{
send
(
s
,
"
\x04
"
);
...
...
@@ -376,7 +376,7 @@ template <size_t N> void send_command (int s, char (&command)[N])
void
test_curve_security_invalid_hello_command_name
()
{
in
t
s
=
connect_vanilla_socket
(
my_endpoint
);
fd_
t
s
=
connect_vanilla_socket
(
my_endpoint
);
send_greeting
(
s
);
...
...
@@ -401,7 +401,7 @@ void test_curve_security_invalid_hello_command_name ()
void
test_curve_security_invalid_hello_version
()
{
in
t
s
=
connect_vanilla_socket
(
my_endpoint
);
fd_
t
s
=
connect_vanilla_socket
(
my_endpoint
);
send_greeting
(
s
);
...
...
@@ -424,7 +424,7 @@ void test_curve_security_invalid_hello_version ()
close
(
s
);
}
void
flush_read
(
in
t
fd
)
void
flush_read
(
fd_
t
fd
)
{
int
res
;
char
buf
[
256
];
...
...
@@ -434,9 +434,9 @@ void flush_read (int fd)
TEST_ASSERT_NOT_EQUAL
(
-
1
,
res
);
}
void
recv_all
(
int
fd
,
uint8_t
*
data
,
size_t
len
)
void
recv_all
(
fd_t
fd
,
uint8_t
*
data
,
socket_
size_t
len
)
{
size_t
received
=
0
;
s
ocket_s
ize_t
received
=
0
;
while
(
received
<
len
)
{
int
res
=
recv
(
fd
,
(
char
*
)
data
,
len
,
0
);
TEST_ASSERT_GREATER_THAN_INT
(
0
,
res
);
...
...
@@ -446,17 +446,17 @@ void recv_all (int fd, uint8_t *data, size_t len)
}
}
void
recv_greeting
(
in
t
fd
)
void
recv_greeting
(
fd_
t
fd
)
{
uint8_t
greeting
[
64
];
recv_all
(
fd
,
greeting
,
64
);
// TODO assert anything about the greeting received from the server?
}
in
t
connect_exchange_greeting_and_send_hello
(
char
*
my_endpoint
,
zmq
::
curve_client_tools_t
&
tools
)
fd_
t
connect_exchange_greeting_and_send_hello
(
char
*
my_endpoint
,
zmq
::
curve_client_tools_t
&
tools
)
{
in
t
s
=
connect_vanilla_socket
(
my_endpoint
);
fd_
t
s
=
connect_vanilla_socket
(
my_endpoint
);
send_greeting
(
s
);
recv_greeting
(
s
);
...
...
@@ -474,7 +474,7 @@ void test_curve_security_invalid_initiate_wrong_length ()
{
zmq
::
curve_client_tools_t
tools
=
make_curve_client_tools
();
in
t
s
=
connect_exchange_greeting_and_send_hello
(
my_endpoint
,
tools
);
fd_
t
s
=
connect_exchange_greeting_and_send_hello
(
my_endpoint
,
tools
);
// receive but ignore WELCOME
flush_read
(
s
);
...
...
@@ -497,13 +497,13 @@ void test_curve_security_invalid_initiate_wrong_length ()
close
(
s
);
}
in
t
connect_exchange_greeting_and_hello_welcome
(
fd_
t
connect_exchange_greeting_and_hello_welcome
(
char
*
my_endpoint
,
void
*
server_mon
,
int
timeout
,
zmq
::
curve_client_tools_t
&
tools
)
{
in
t
s
=
connect_exchange_greeting_and_send_hello
(
my_endpoint
,
tools
);
fd_
t
s
=
connect_exchange_greeting_and_send_hello
(
my_endpoint
,
tools
);
// receive but ignore WELCOME
uint8_t
welcome
[
welcome_length
+
2
];
...
...
@@ -524,7 +524,7 @@ int connect_exchange_greeting_and_hello_welcome (
void
test_curve_security_invalid_initiate_command_name
()
{
zmq
::
curve_client_tools_t
tools
=
make_curve_client_tools
();
in
t
s
=
connect_exchange_greeting_and_hello_welcome
(
fd_
t
s
=
connect_exchange_greeting_and_hello_welcome
(
my_endpoint
,
server_mon
,
timeout
,
tools
);
char
initiate
[
257
];
...
...
@@ -546,7 +546,7 @@ void test_curve_security_invalid_initiate_command_name ()
void
test_curve_security_invalid_initiate_command_encrypted_cookie
()
{
zmq
::
curve_client_tools_t
tools
=
make_curve_client_tools
();
in
t
s
=
connect_exchange_greeting_and_hello_welcome
(
fd_
t
s
=
connect_exchange_greeting_and_hello_welcome
(
my_endpoint
,
server_mon
,
timeout
,
tools
);
char
initiate
[
257
];
...
...
@@ -568,7 +568,7 @@ void test_curve_security_invalid_initiate_command_encrypted_cookie ()
void
test_curve_security_invalid_initiate_command_encrypted_content
()
{
zmq
::
curve_client_tools_t
tools
=
make_curve_client_tools
();
in
t
s
=
connect_exchange_greeting_and_hello_welcome
(
fd_
t
s
=
connect_exchange_greeting_and_hello_welcome
(
my_endpoint
,
server_mon
,
timeout
,
tools
);
char
initiate
[
257
];
...
...
tests/testutil.hpp
View file @
3ee65906
...
...
@@ -88,6 +88,32 @@
#endif
#endif
// duplicated from fd.hpp
#ifdef ZMQ_HAVE_WINDOWS
#define close closesocket
typedef
int
socket_size_t
;
#if defined _MSC_VER && _MSC_VER <= 1400
typedef
UINT_PTR
fd_t
;
enum
{
retired_fd
=
(
fd_t
)
(
~
0
)
};
#else
typedef
SOCKET
fd_t
;
enum
{
retired_fd
=
(
fd_t
)
INVALID_SOCKET
};
#endif
#else
typedef
size_t
socket_size_t
;
typedef
int
fd_t
;
enum
{
retired_fd
=
-
1
};
#endif
#define LIBZMQ_UNUSED(object) (void) object
// Bounce a message from client to server and back
...
...
@@ -351,11 +377,11 @@ int is_ipv6_available (void)
test_addr
.
sin6_family
=
AF_INET6
;
inet_pton
(
AF_INET6
,
"::1"
,
&
(
test_addr
.
sin6_addr
));
#ifdef ZMQ_HAVE_WINDOWS
SOCKET
fd
=
socket
(
AF_INET6
,
SOCK_STREAM
,
IPPROTO_IP
);
if
(
fd
==
INVALID_SOCKET
)
fd_t
fd
=
socket
(
AF_INET6
,
SOCK_STREAM
,
IPPROTO_IP
);
if
(
fd
==
retired_fd
)
ipv6
=
0
;
else
{
#ifdef ZMQ_HAVE_WINDOWS
setsockopt
(
fd
,
SOL_SOCKET
,
SO_REUSEADDR
,
(
const
char
*
)
&
ipv6
,
sizeof
(
int
));
rc
=
setsockopt
(
fd
,
IPPROTO_IPV6
,
IPV6_V6ONLY
,
(
const
char
*
)
&
ipv6
,
...
...
@@ -367,13 +393,7 @@ int is_ipv6_available (void)
if
(
rc
==
SOCKET_ERROR
)
ipv6
=
0
;
}
closesocket
(
fd
);
}
#else
int
fd
=
socket
(
AF_INET6
,
SOCK_STREAM
,
IPPROTO_IP
);
if
(
fd
==
-
1
)
ipv6
=
0
;
else
{
setsockopt
(
fd
,
SOL_SOCKET
,
SO_REUSEADDR
,
&
ipv6
,
sizeof
(
int
));
rc
=
setsockopt
(
fd
,
IPPROTO_IPV6
,
IPV6_V6ONLY
,
&
ipv6
,
sizeof
(
int
));
if
(
rc
!=
0
)
...
...
@@ -383,9 +403,9 @@ int is_ipv6_available (void)
if
(
rc
!=
0
)
ipv6
=
0
;
}
#endif
close
(
fd
);
}
#endif
return
ipv6
;
#endif // _WIN32_WINNT < 0x0600
...
...
@@ -442,13 +462,4 @@ int test_inet_pton (int af_, const char *src_, void *dst_)
#endif
}
#if defined(ZMQ_HAVE_WINDOWS)
int
close
(
int
fd
)
{
return
closesocket
(
fd
);
}
#endif
#endif
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