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
c128fac7
Commit
c128fac7
authored
Sep 02, 2013
by
Pieter Hintjens
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #639 from minrk/test_linger
add test_linger
parents
6fa274eb
c646ac96
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
0 deletions
+106
-0
Makefile.am
tests/Makefile.am
+2
-0
test_linger.cpp
tests/test_linger.cpp
+104
-0
No files found.
tests/Makefile.am
View file @
c128fac7
...
...
@@ -16,6 +16,7 @@ noinst_PROGRAMS = test_pair_inproc \
test_connect_delay
\
test_last_endpoint
\
test_term_endpoint
\
test_linger
\
test_monitor
\
test_router_mandatory
\
test_probe_router
\
...
...
@@ -50,6 +51,7 @@ test_hwm_SOURCES = test_hwm.cpp
test_reqrep_device_SOURCES
=
test_reqrep_device.cpp
test_sub_forward_SOURCES
=
test_sub_forward.cpp
test_invalid_rep_SOURCES
=
test_invalid_rep.cpp
test_linger_SOURCES
=
test_linger.cpp
test_msg_flags_SOURCES
=
test_msg_flags.cpp
test_connect_resolve_SOURCES
=
test_connect_resolve.cpp
test_connect_delay_SOURCES
=
test_connect_delay.cpp
...
...
tests/test_linger.cpp
0 → 100644
View file @
c128fac7
/*
Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
0MQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../include/zmq_utils.h"
#include <stdio.h>
#include <string.h>
#include "testutil.hpp"
#define URL "tcp://127.0.0.1:5560"
// sender connects a PUSH socket
// and sends a message of a given size,
// closing the socket and terminating the context immediately.
// LINGER should prevent this from dropping messages.
static
void
sender
(
void
*
vsize
)
{
void
*
context
=
zmq_ctx_new
();
void
*
push
=
zmq_socket
(
context
,
ZMQ_PUSH
);
zmq_msg_t
msg
;
size_t
size
=
((
size_t
*
)
vsize
)[
0
];
int
rc
=
zmq_connect
(
push
,
URL
);
assert
(
rc
==
0
);
rc
=
zmq_msg_init_size
(
&
msg
,
size
);
assert
(
rc
==
0
);
char
*
buf
=
(
char
*
)
zmq_msg_data
(
&
msg
);
assert
(
buf
!=
NULL
);
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
buf
[
i
]
=
'x'
;
}
printf
(
"Sending %lu B ... "
,
zmq_msg_size
(
&
msg
));
rc
=
zmq_msg_send
(
&
msg
,
push
,
0
);
assert
((
size_t
)
rc
==
size
);
rc
=
zmq_msg_close
(
&
msg
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
push
);
assert
(
rc
==
0
);
rc
=
zmq_ctx_term
(
context
);
assert
(
rc
==
0
);
}
int
main
(
void
)
{
void
*
context
=
zmq_ctx_new
();
void
*
pull
=
zmq_socket
(
context
,
ZMQ_PULL
);
zmq_msg_t
msg
;
int
rc
=
zmq_bind
(
pull
,
URL
);
assert
(
rc
==
0
);
// Symptom of test failure is message never received
int
rcvtimeo
=
1000
;
rc
=
zmq_setsockopt
(
pull
,
ZMQ_RCVTIMEO
,
&
rcvtimeo
,
sizeof
(
int
));
assert
(
rc
==
0
);
for
(
int
p
=
0
;
p
<
25
;
p
+=
4
)
{
size_t
size
=
1
<<
p
;
// Start the sender thread
void
*
send_thread
=
zmq_threadstart
(
&
sender
,
(
void
*
)
&
size
);
zmq_msg_init
(
&
msg
);
rc
=
zmq_msg_recv
(
&
msg
,
pull
,
0
);
if
(
rc
==
-
1
)
{
printf
(
"%s
\n
"
,
zmq_strerror
(
zmq_errno
()));
}
else
{
printf
(
"Received.
\n
"
);
}
assert
((
size_t
)
rc
==
size
);
zmq_msg_close
(
&
msg
);
zmq_threadclose
(
send_thread
);
}
zmq_close
(
pull
);
zmq_ctx_term
(
context
);
return
0
;
}
\ No newline at end of file
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