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
99e53698
Unverified
Commit
99e53698
authored
Mar 19, 2019
by
Simon Giesecke
Committed by
GitHub
Mar 19, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3456 from bluca/test_fd_port
Problem: TCP and UDP test sockets use hard-coded port
parents
168aa83d
98875a9d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
43 deletions
+34
-43
.gitignore
.gitignore
+1
-0
test_stream_exceeds_buffer.cpp
tests/test_stream_exceeds_buffer.cpp
+1
-25
test_zmq_poll_fd.cpp
tests/test_zmq_poll_fd.cpp
+3
-18
testutil.hpp
tests/testutil.hpp
+29
-0
No files found.
.gitignore
View file @
99e53698
...
...
@@ -74,6 +74,7 @@ test_ctx_options
test_iov
test_security
test_security_curve
test_security_no_zap_handler
test_probe_router
test_stream
test_spec_dealer
...
...
tests/test_stream_exceeds_buffer.cpp
View file @
99e53698
...
...
@@ -40,13 +40,6 @@ void tearDown ()
teardown_test_context
();
}
#if defined(ZMQ_HAVE_WINDOWS)
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdexcept>
#define close closesocket
#endif
void
test_stream_exceeds_buffer
()
{
const
int
msgsize
=
8193
;
...
...
@@ -60,26 +53,9 @@ void test_stream_exceeds_buffer ()
TEST_ASSERT_SUCCESS_RAW_ERRNO
(
setsockopt
(
server_sock
,
SOL_SOCKET
,
SO_REUSEADDR
,
(
char
*
)
&
enable
,
sizeof
(
enable
)));
struct
sockaddr_in
saddr
;
memset
(
&
saddr
,
0
,
sizeof
(
saddr
));
saddr
.
sin_family
=
AF_INET
;
saddr
.
sin_addr
.
s_addr
=
INADDR_ANY
;
#if !defined(_WIN32_WINNT) || (_WIN32_WINNT >= 0x0600)
saddr
.
sin_port
=
0
;
#else
saddr
.
sin_port
=
htons
(
12345
);
#endif
TEST_ASSERT_SUCCESS_RAW_ERRNO
(
bind
(
server_sock
,
(
struct
sockaddr
*
)
&
saddr
,
sizeof
(
saddr
)));
struct
sockaddr_in
saddr
=
bind_bsd_socket
(
server_sock
);
TEST_ASSERT_SUCCESS_RAW_ERRNO
(
listen
(
server_sock
,
1
));
#if !defined(_WIN32_WINNT) || (_WIN32_WINNT >= 0x0600)
socklen_t
saddr_len
=
sizeof
(
saddr
);
TEST_ASSERT_SUCCESS_RAW_ERRNO
(
getsockname
(
server_sock
,
(
struct
sockaddr
*
)
&
saddr
,
&
saddr_len
));
#endif
sprintf
(
my_endpoint
,
"tcp://127.0.0.1:%d"
,
ntohs
(
saddr
.
sin_port
));
void
*
zsock
=
test_context_socket
(
ZMQ_STREAM
);
...
...
tests/test_zmq_poll_fd.cpp
View file @
99e53698
...
...
@@ -45,18 +45,6 @@ void tearDown ()
void
test_poll_fd
()
{
struct
addrinfo
*
addr
,
hint
;
hint
.
ai_flags
=
AI_NUMERICHOST
;
hint
.
ai_family
=
AF_INET
;
hint
.
ai_socktype
=
SOCK_DGRAM
;
hint
.
ai_protocol
=
IPPROTO_UDP
;
hint
.
ai_addrlen
=
0
;
hint
.
ai_canonname
=
NULL
;
hint
.
ai_addr
=
NULL
;
hint
.
ai_next
=
NULL
;
TEST_ASSERT_SUCCESS_ERRNO
(
getaddrinfo
(
"127.0.0.1"
,
"6650"
,
&
hint
,
&
addr
));
int
recv_socket
=
socket
(
AF_INET
,
SOCK_DGRAM
,
IPPROTO_UDP
);
TEST_ASSERT_NOT_EQUAL
(
-
1
,
recv_socket
);
...
...
@@ -64,8 +52,7 @@ void test_poll_fd ()
TEST_ASSERT_SUCCESS_ERRNO
(
setsockopt
(
recv_socket
,
SOL_SOCKET
,
SO_REUSEADDR
,
&
flag
,
sizeof
(
int
)));
TEST_ASSERT_SUCCESS_ERRNO
(
bind
(
recv_socket
,
addr
->
ai_addr
,
addr
->
ai_addrlen
));
struct
sockaddr_in
saddr
=
bind_bsd_socket
(
recv_socket
);
void
*
sb
=
test_context_socket
(
ZMQ_REP
);
...
...
@@ -82,8 +69,8 @@ void test_poll_fd ()
char
buf
[
10
];
memset
(
buf
,
1
,
10
);
TEST_ASSERT_SUCCESS_ERRNO
(
send
to
(
send_socket
,
buf
,
10
,
0
,
addr
->
ai_addr
,
addr
->
ai_addrlen
));
TEST_ASSERT_SUCCESS_ERRNO
(
sendto
(
send
_socket
,
buf
,
10
,
0
,
(
struct
sockaddr
*
)
&
saddr
,
sizeof
(
saddr
)
));
TEST_ASSERT_EQUAL
(
1
,
zmq_poll
(
pollitems
,
2
,
1
));
TEST_ASSERT_BITS_LOW
(
ZMQ_POLLIN
,
pollitems
[
0
].
revents
);
...
...
@@ -93,8 +80,6 @@ void test_poll_fd ()
close
(
send_socket
);
close
(
recv_socket
);
freeaddrinfo
(
addr
);
}
int
main
()
...
...
tests/testutil.hpp
View file @
99e53698
...
...
@@ -55,6 +55,7 @@
#define ENDPOINT_3 "tcp://127.0.0.1:5558"
#define ENDPOINT_4 "udp://127.0.0.1:5559"
#define ENDPOINT_5 "udp://127.0.0.1:5560"
#define PORT_6 5561
#undef NDEBUG
#include <time.h>
...
...
@@ -94,6 +95,9 @@
// duplicated from fd.hpp
#ifdef ZMQ_HAVE_WINDOWS
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdexcept>
#define close closesocket
typedef
int
socket_size_t
;
const
char
*
as_setsockopt_opt_t
(
const
void
*
opt
)
...
...
@@ -474,4 +478,29 @@ int test_inet_pton (int af_, const char *src_, void *dst_)
#endif
}
// Binds an ipv4 BSD socket to an ephemeral port, returns the compiled sockaddr
struct
sockaddr_in
bind_bsd_socket
(
int
socket
)
{
struct
sockaddr_in
saddr
;
memset
(
&
saddr
,
0
,
sizeof
(
saddr
));
saddr
.
sin_family
=
AF_INET
;
saddr
.
sin_addr
.
s_addr
=
INADDR_ANY
;
#if !defined(_WIN32_WINNT) || (_WIN32_WINNT >= 0x0600)
saddr
.
sin_port
=
0
;
#else
saddr
.
sin_port
=
htons
(
PORT_6
);
#endif
int
rc
=
bind
(
socket
,
(
struct
sockaddr
*
)
&
saddr
,
sizeof
(
saddr
));
assert
(
rc
==
0
);
#if !defined(_WIN32_WINNT) || (_WIN32_WINNT >= 0x0600)
socklen_t
saddr_len
=
sizeof
(
saddr
);
rc
=
getsockname
(
socket
,
(
struct
sockaddr
*
)
&
saddr
,
&
saddr_len
);
assert
(
rc
==
0
);
#endif
return
saddr
;
}
#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