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
5f009e52
Commit
5f009e52
authored
Jan 30, 2013
by
Pieter Hintjens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Various cleanups to test programs
parent
18a14aed
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
37 deletions
+25
-37
test_connect_delay.cpp
tests/test_connect_delay.cpp
+2
-4
test_disconnect_inproc.cpp
tests/test_disconnect_inproc.cpp
+2
-9
test_last_endpoint.cpp
tests/test_last_endpoint.cpp
+4
-5
test_raw_sock.cpp
tests/test_raw_sock.cpp
+17
-19
No files found.
tests/test_connect_delay.cpp
View file @
5f009e52
...
...
@@ -61,12 +61,12 @@ int main (void)
assert
(
from
);
val
=
0
;
zmq_setsockopt
(
from
,
ZMQ_LINGER
,
&
val
,
sizeof
(
val
));
zmq_setsockopt
(
from
,
ZMQ_LINGER
,
&
val
,
sizeof
(
val
));
// This pipe will not connect
rc
=
zmq_connect
(
from
,
"tcp://localhost:5556"
);
assert
(
rc
==
0
);
// This pipe will
rc
=
zmq_connect
(
from
,
"tcp://localhost:
5
555"
);
rc
=
zmq_connect
(
from
,
"tcp://localhost:
6
555"
);
assert
(
rc
==
0
);
// We send 10 messages, 5 should just get stuck in the queue
...
...
@@ -112,7 +112,6 @@ int main (void)
// cause the pipe attachment to be delayed until the connection
// succeeds.
context
=
zmq_ctx_new
();
fprintf
(
stderr
,
" Rerunning with DELAY_ATTACH_ON_CONNECT
\n
"
);
// Bind the valid socket
to
=
zmq_socket
(
context
,
ZMQ_PULL
);
...
...
@@ -182,7 +181,6 @@ int main (void)
// block. Then we reconnect and verify messages flow again.
context
=
zmq_ctx_new
();
void
*
context2
=
zmq_ctx_new
();
fprintf
(
stderr
,
" Running DELAY_ATTACH_ON_CONNECT with disconnect
\n
"
);
to
=
zmq_socket
(
context2
,
ZMQ_PULL
);
assert
(
to
);
...
...
tests/test_disconnect_inproc.cpp
View file @
5f009e52
...
...
@@ -40,16 +40,14 @@ int main(int argc, char** argv) {
zmq_msg_t
msg
;
zmq_msg_init
(
&
msg
);
zmq_msg_recv
(
&
msg
,
pubSocket
,
0
);
int
msgSize
=
zmq_msg_size
(
&
msg
);
char
*
buffer
=
(
char
*
)
zmq_msg_data
(
&
msg
);
if
(
buffer
[
0
]
==
0
)
{
assert
(
isSubscribed
);
printf
(
"unsubscribing from '%s'
\n
"
,
strndup
(
buffer
+
1
,
msgSize
-
1
));
isSubscribed
=
false
;
}
else
{
}
else
{
assert
(
!
isSubscribed
);
printf
(
"subscribing on '%s'
\n
"
,
strndup
(
buffer
+
1
,
msgSize
-
1
));
isSubscribed
=
true
;
}
...
...
@@ -66,11 +64,6 @@ int main(int argc, char** argv) {
zmq_msg_t
msg
;
zmq_msg_init
(
&
msg
);
zmq_msg_recv
(
&
msg
,
subSocket
,
0
);
int
msgSize
=
zmq_msg_size
(
&
msg
);
char
*
buffer
=
(
char
*
)
zmq_msg_data
(
&
msg
);
printf
(
"received on subscriber '%s'
\n
"
,
strndup
(
buffer
,
msgSize
));
zmq_getsockopt
(
subSocket
,
ZMQ_RCVMORE
,
&
more
,
&
more_size
);
zmq_msg_close
(
&
msg
);
...
...
tests/test_last_endpoint.cpp
View file @
5f009e52
...
...
@@ -29,11 +29,10 @@ static void do_bind_and_verify (void *s, const char *endpoint)
{
int
rc
=
zmq_bind
(
s
,
endpoint
);
assert
(
rc
==
0
);
char
test
[
255
];
size_t
siz
=
255
;
rc
=
zmq_getsockopt
(
s
,
ZMQ_LAST_ENDPOINT
,
test
,
&
siz
);
assert
(
rc
==
0
&&
strcmp
(
test
,
endpoint
)
==
0
);
char
reported
[
255
];
size_t
size
=
255
;
rc
=
zmq_getsockopt
(
s
,
ZMQ_LAST_ENDPOINT
,
reported
,
&
size
);
assert
(
rc
==
0
&&
strcmp
(
reported
,
endpoint
)
==
0
);
}
int
main
(
void
)
...
...
tests/test_raw_sock.cpp
View file @
5f009e52
...
...
@@ -37,7 +37,7 @@
//ToDo: Windows?
const
char
*
test_str
=
"TEST-STRING"
;
int
tcp_client
()
int
tcp_client
(
void
)
{
struct
sockaddr_in
serv_addr
;
struct
hostent
*
server
;
...
...
@@ -64,7 +64,7 @@ int tcp_client ()
return
sockfd
;
}
int
tcp_server
()
int
tcp_server
(
void
)
{
int
listenfd
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
assert
(
listenfd
!=
-
1
);
...
...
@@ -129,20 +129,18 @@ void tcp_client_read (int sockfd)
size_t
tcp_read
(
int
s
,
char
*
buf
,
size_t
bufsize
)
{
size_t
bytes_read
=
0
;
struct
pollfd
pfd
=
{
s
,
POLLIN
};
int
rc
=
poll
(
&
pfd
,
1
,
100
);
while
(
rc
>
0
&&
bytes_read
<
bufsize
)
{
int
n
=
read
(
s
,
buf
+
bytes_read
,
bufsize
-
bytes_read
);
if
(
n
<=
0
)
return
bytes_read
;
bytes_read
+=
n
;
rc
=
poll
(
&
pfd
,
1
,
100
);
size_t
total_size
=
0
;
struct
pollfd
pfd
=
{
s
,
POLLIN
};
int
rc
=
poll
(
&
pfd
,
1
,
1000
);
assert
(
rc
>
0
);
while
(
rc
>
0
&&
total_size
<
bufsize
)
{
int
chunk_size
=
read
(
s
,
buf
+
total_size
,
bufsize
-
total_size
);
assert
(
chunk_size
>=
0
);
total_size
+=
chunk_size
;
rc
=
poll
(
&
pfd
,
1
,
1000
);
}
return
bytes_read
;
return
total_size
;
}
void
tcp_client_close
(
int
sockfd
)
...
...
@@ -150,7 +148,7 @@ void tcp_client_close (int sockfd)
close
(
sockfd
);
}
void
test_zmq_connect
()
void
test_zmq_connect
(
void
)
{
void
*
ctx
=
zmq_init
(
1
);
assert
(
ctx
);
...
...
@@ -182,8 +180,8 @@ void test_zmq_connect ()
char
buffer
[
128
];
size_t
bytes_read
=
tcp_read
(
server_fd
,
buffer
,
sizeof
buffer
);
assert
(
bytes_read
==
strlen
(
test_str
)
&&
memcmp
(
buffer
,
test_str
,
bytes_read
)
==
0
);
assert
(
bytes_read
==
strlen
(
test_str
)
);
assert
(
memcmp
(
buffer
,
test_str
,
bytes_read
)
==
0
);
rc
=
close
(
server_fd
);
assert
(
rc
==
0
);
...
...
@@ -196,7 +194,7 @@ void test_zmq_connect ()
assert
(
rc
==
0
);
}
int
main
()
int
main
(
void
)
{
fprintf
(
stderr
,
"test_raw_sock running...
\n
"
);
...
...
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