Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
margo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
13
Issues
13
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
sds
margo
Commits
2bc6ec83
Commit
2bc6ec83
authored
Mar 29, 2016
by
Philip Carns
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reorg examples to use rpc for shutdown
parent
34637d8d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
6 deletions
+57
-6
examples/Makefile.subdir
examples/Makefile.subdir
+1
-2
examples/client.c
examples/client.c
+17
-1
examples/my-rpc.c
examples/my-rpc.c
+29
-0
examples/my-rpc.h
examples/my-rpc.h
+2
-0
examples/server.c
examples/server.c
+8
-3
No files found.
examples/Makefile.subdir
View file @
2bc6ec83
bin_PROGRAMS
+=
examples/client examples/server
examples_client_SOURCES
=
\
examples/client.c
\
examples/my-rpc.c
examples/client.c
examples_client_LDADD
=
src/libmargo.a
examples_server_SOURCES
=
\
...
...
examples/client.c
View file @
2bc6ec83
...
...
@@ -33,6 +33,7 @@ struct run_my_rpc_args
static
void
run_my_rpc
(
void
*
_arg
);
static
hg_id_t
my_rpc_id
;
static
hg_id_t
my_rpc_shutdown_id
;
int
main
(
int
argc
,
char
**
argv
)
{
...
...
@@ -49,6 +50,8 @@ int main(int argc, char **argv)
na_context_t
*
na_context
;
hg_context_t
*
hg_context
;
hg_class_t
*
hg_class
;
na_addr_t
svr_addr
=
NA_ADDR_NULL
;
hg_handle_t
handle
;
/* boilerplate HG initialization steps */
/***************************************/
...
...
@@ -133,7 +136,9 @@ int main(int argc, char **argv)
/* register RPC */
my_rpc_id
=
MERCURY_REGISTER
(
hg_class
,
"my_rpc"
,
my_rpc_in_t
,
my_rpc_out_t
,
my_rpc_ult_handler
);
NULL
);
my_rpc_shutdown_id
=
MERCURY_REGISTER
(
hg_class
,
"my_shutdown_rpc"
,
void
,
void
,
NULL
);
for
(
i
=
0
;
i
<
4
;
i
++
)
{
...
...
@@ -176,6 +181,17 @@ int main(int argc, char **argv)
}
}
/* send one rpc to server to shut it down */
/* find addr for server */
ret
=
margo_na_addr_lookup
(
mid
,
network_class
,
na_context
,
"tcp://localhost:1234"
,
&
svr_addr
);
assert
(
ret
==
0
);
/* create handle */
ret
=
HG_Create
(
hg_context
,
svr_addr
,
my_rpc_shutdown_id
,
&
handle
);
assert
(
ret
==
0
);
margo_forward
(
mid
,
handle
,
NULL
);
/* shut down everything */
margo_finalize
(
mid
);
...
...
examples/my-rpc.c
View file @
2bc6ec83
...
...
@@ -18,6 +18,8 @@
* close.
*/
extern
ABT_eventual
*
shutdown_eventual
;
static
void
my_rpc_ult
(
void
*
_arg
)
{
hg_handle_t
*
handle
=
_arg
;
...
...
@@ -84,3 +86,30 @@ static void my_rpc_ult(void *_arg)
return
;
}
DEFINE_MARGO_RPC_HANDLER
(
my_rpc_ult
)
static
void
my_rpc_shutdown_ult
(
void
*
_arg
)
{
hg_handle_t
*
handle
=
_arg
;
hg_return_t
hret
;
struct
hg_info
*
hgi
;
margo_instance_id
mid
;
printf
(
"Got RPC request to shutdown
\n
"
);
hgi
=
HG_Get_info
(
*
handle
);
assert
(
hgi
);
mid
=
margo_hg_class_to_instance
(
hgi
->
hg_class
);
hret
=
HG_Respond
(
*
handle
,
NULL
,
NULL
,
NULL
);
assert
(
hret
==
HG_SUCCESS
);
HG_Destroy
(
*
handle
);
margo_finalize
(
mid
);
ABT_eventual_set
(
*
shutdown_eventual
,
NULL
,
0
);
return
;
}
DEFINE_MARGO_RPC_HANDLER
(
my_rpc_shutdown_ult
)
examples/my-rpc.h
View file @
2bc6ec83
...
...
@@ -17,4 +17,6 @@ MERCURY_GEN_PROC(my_rpc_in_t,
((
hg_bulk_t
)(
bulk_handle
)))
DECLARE_MARGO_RPC_HANDLER
(
my_rpc_ult
)
DECLARE_MARGO_RPC_HANDLER
(
my_rpc_shutdown_ult
)
#endif
/* __MY_RPC */
examples/server.c
View file @
2bc6ec83
...
...
@@ -13,6 +13,8 @@
#include "my-rpc.h"
ABT_eventual
*
shutdown_eventual
;
/* example server program. Starts HG engine, registers the example RPC type,
* and then executes indefinitely.
*/
...
...
@@ -32,6 +34,8 @@ int main(int argc, char **argv)
hg_class_t
*
hg_class
;
int
single_pool_mode
=
0
;
shutdown_eventual
=
&
eventual
;
if
(
argc
>
2
)
{
fprintf
(
stderr
,
"Usage: ./server <single>
\n
"
);
...
...
@@ -136,10 +140,13 @@ int main(int argc, char **argv)
mid
=
margo_init
(
handler_pool
,
handler_pool
,
hg_context
,
hg_class
);
else
mid
=
margo_init
(
progress_pool
,
handler_pool
,
hg_context
,
hg_class
);
assert
(
mid
);
/* register RPC */
MERCURY_REGISTER
(
hg_class
,
"my_rpc"
,
my_rpc_in_t
,
my_rpc_out_t
,
my_rpc_ult_handler
);
MERCURY_REGISTER
(
hg_class
,
"my_shutdown_rpc"
,
void
,
void
,
my_rpc_shutdown_ult_handler
);
/* suspend this ULT until someone tells us to shut down */
ret
=
ABT_eventual_create
(
0
,
&
eventual
);
...
...
@@ -149,11 +156,9 @@ int main(int argc, char **argv)
return
(
-
1
);
}
/* wait for shutdown (assume that margo will be finalized by an RPC) */
ABT_eventual_wait
(
eventual
,
NULL
);
/* shut down everything */
margo_finalize
(
mid
);
if
(
!
single_pool_mode
)
{
ABT_xstream_join
(
progress_xstream
);
...
...
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