NewMadeleine

Documentation

« back to PM2 home.
nm_rpc_private.h
Go to the documentation of this file.
1/*
2 * NewMadeleine
3 * Copyright (C) 2016-2026 (see AUTHORS file)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
16#ifndef NM_RPC_PRIVATE_H
17#define NM_RPC_PRIVATE_H
18
24#include <assert.h>
25#include <stdatomic.h>
26#include <nm_public.h>
27#include <nm_core_interface.h>
28
41
55
70
71
72/* ** inline function ************************************** */
73
76
78 void*hptr, nm_len_t hlen, struct nm_data_s*p_body)
79{
80 nm_rpc_req_t p_req = nm_rpc_isend(p_service, p_gate, tag, hptr, hlen, p_body);
81 nm_rpc_req_wait(p_req);
82}
83
85{
86 p_req->priority = priority;
87}
88
89static inline void nm_rpc_req_wait(nm_rpc_req_t p_req)
90{
91 nm_sr_swait(p_req->request.p_session, &p_req->request);
92 nm_rpc_req_delete(p_req);
93}
94
95static inline void nm_rpc_req_wait_all(nm_rpc_req_t*p_reqs, int n)
96{
97 assert((void*)&p_reqs[0]->request == (void*)p_reqs[0]); /* nm_sr_request_t must be the first field in nm_rpc_req_s */
99 int i;
100 for(i = 0; i < n; i++)
101 {
102 if(p_reqs[i] != NULL)
103 nm_rpc_req_delete(p_reqs[i]);
104 }
105}
106
107static inline void*nm_rpc_service_get_ref(struct nm_rpc_service_s*p_service)
108{
109 return p_service->ref;
110}
111
112static inline nm_gate_t nm_rpc_get_source(struct nm_rpc_token_s*p_token)
113{
115 return p_gate;
116}
117
118static inline nm_tag_t nm_rpc_get_tag(struct nm_rpc_token_s*p_token)
119{
121 return tag;
122}
123
125{
126 return p_token->p_service;
127}
128
129static inline void*nm_rpc_token_get_ref(struct nm_rpc_token_s*p_token)
130{
131 return p_token->ref;
132}
133
134static inline void nm_rpc_token_set_ref(struct nm_rpc_token_s*p_token, void*ref)
135{
136 p_token->ref = ref;
137}
138
139static inline void nm_rpc_token_delay(struct nm_rpc_token_s*p_token)
140{
141 p_token->delayed = 1;
142}
143
144static inline void nm_rpc_recv_header_data(nm_rpc_token_t p_token, struct nm_data_s*p_header)
145{
146 assert(nm_datav_size(&p_token->bodyv) == 0); /* all headers must be unpacked before body chunks */
147 const nm_len_t peek_offset = nm_datav_size(&p_token->headerv); /* compute size of headers so far */
148 const nm_len_t peek_size = nm_data_size(p_header);
149 struct nm_data_s datav;
150 nm_datav_add_chunk_data(&p_token->headerv, p_header);
151 nm_data_datav_build(&datav, &p_token->headerv); /* build data type for full header */
152 int rc = nm_sr_recv_peek_offset(p_token->p_service->p_session, &p_token->request, &datav, peek_offset, peek_size);
153 if(rc != NM_ESUCCESS)
154 {
155 NM_FATAL("# nm_rpc: rc = %d in nm_sr_recv_peek()\n", rc);
156 }
157 nm_datav_uncommit(&p_token->headerv);
158 nm_sr_recv_offset(p_token->p_service->p_session, &p_token->request, peek_offset + peek_size);
159}
160
161static inline void nm_rpc_recv_header(nm_rpc_token_t p_token, void*hptr, nm_len_t hlen)
162{
163 struct nm_data_s data;
164 nm_data_contiguous_build(&data, (void*)hptr, hlen);
165 nm_rpc_recv_header_data(p_token, &data);
166}
167
168static inline void nm_rpc_irecv_body_data(struct nm_rpc_token_s*p_token, struct nm_data_s*p_body)
169{
170 nm_datav_add_chunk_data(&p_token->bodyv, p_body);
171}
172
173static inline void nm_rpc_irecv_body(nm_rpc_token_t p_token, void*ptr, nm_len_t len)
174{
175 struct nm_data_s data;
176 nm_data_contiguous_build(&data, (void*)ptr, len);
177 nm_rpc_irecv_body_data(p_token, &data);
178}
179
180#endif /* NM_RPC_PRIVATE_H */
static void nm_datav_uncommit(struct nm_datav_s *p_datav)
'uncommit' a datav: explicitely declare that nm_data pointing to this datav has been destroyed.
Definition nm_data.h:879
static nm_len_t nm_datav_size(struct nm_datav_s *p_datav)
get the size (number of bytes) of data contained in the datav
Definition nm_data.h:868
static void nm_datav_add_chunk_data(struct nm_datav_s *p_datav, const struct nm_data_s *p_data)
add a chunk of data to datav; given p_data content is copied.
Definition nm_data.h:833
static nm_len_t nm_data_size(const struct nm_data_s *p_data)
returns the amount of data contained in the descriptor
Definition nm_data.h:674
@ NM_ESUCCESS
successful operation
Definition nm_errno.h:36
void(* nm_rpc_handler_t)(nm_rpc_token_t p_token)
a RPC handler called upon request invocation
nm_rpc_req_t nm_rpc_isend(nm_rpc_service_t p_service, nm_gate_t p_gate, nm_tag_t tag, void *hptr, nm_len_t hlen, struct nm_data_s *p_body)
Legacy function to send an rpc request with one header and one nm_data body; non-blocking.
void(* nm_rpc_req_notifier_t)(nm_rpc_req_t p_req, void *ref)
a RPC req notifier, called when the request send operation is completed
void(* nm_rpc_finalizer_t)(nm_rpc_token_t p_token)
a RPC finalizer, called when all data has been received
static nm_gate_t nm_sr_request_get_gate(nm_sr_request_t *p_request)
static int nm_sr_swait(nm_session_t p_session, nm_sr_request_t *p_request)
Wait for the completion of a non blocking send request.
static nm_tag_t nm_sr_request_get_tag(nm_sr_request_t *p_request)
Retrieve the tag from a sendrecv request.
static void nm_sr_request_wait_all(nm_sr_request_t **p_requests, int n)
wait for completion of an array of requests
static void nm_sr_recv_offset(nm_session_t p_session, nm_sr_request_t *p_request, nm_len_t offset)
set offset of data to receive; data before offset will be discarded
static int nm_sr_recv_peek_offset(nm_session_t p_session, nm_sr_request_t *p_request, const struct nm_data_s *p_data, nm_len_t peek_offset, nm_len_t peek_len)
peek for already received (unexpected) data, with offset and explicit len
nm_tag_t tag
the user-supplied tag
assert(p_data->ops.p_traversal !=NULL)
static void nm_data_contiguous_build(struct nm_data_s *p_data, void *ptr, nm_len_t len)
Definition nm_data.h:561
static void nm_data_datav_build(struct nm_data_s *p_datav_data, struct nm_datav_s *p_datav)
frontend to build a nm_data from a datav
Definition nm_data.h:599
nm_len_t len
Definition nm_data.h:1007
static nm_gate_t p_gate
nm_prio_t priority
Definition nm_headers.h:6
uint16_t hlen
length in header (header + data in header)
Definition nm_headers.h:5
This is the common public header for NewMad.
#define NM_FATAL(format,...)
Definition nm_public.h:67
static void nm_rpc_req_set_priority(nm_rpc_req_t p_req, nm_prio_t priority)
static nm_rpc_service_t nm_rpc_get_service(struct nm_rpc_token_s *p_token)
static void nm_rpc_recv_header(nm_rpc_token_t p_token, void *hptr, nm_len_t hlen)
void nm_rpc_req_delete(nm_rpc_req_t p_rpc_req)
static void * nm_rpc_service_get_ref(struct nm_rpc_service_s *p_service)
PUK_LIST_DECLARE_TYPE(nm_rpc_token)
static void nm_rpc_token_set_ref(struct nm_rpc_token_s *p_token, void *ref)
static void nm_rpc_send(nm_rpc_service_t p_service, nm_gate_t p_gate, nm_tag_t tag, void *hptr, nm_len_t hlen, struct nm_data_s *p_body)
static void nm_rpc_req_wait(nm_rpc_req_t p_req)
static void nm_rpc_irecv_body(nm_rpc_token_t p_token, void *ptr, nm_len_t len)
PUK_LIST_CREATE_FUNCS(nm_rpc_token)
static nm_tag_t nm_rpc_get_tag(struct nm_rpc_token_s *p_token)
static void * nm_rpc_token_get_ref(struct nm_rpc_token_s *p_token)
static void nm_rpc_recv_header_data(nm_rpc_token_t p_token, struct nm_data_s *p_header)
static void nm_rpc_irecv_body_data(struct nm_rpc_token_s *p_token, struct nm_data_s *p_body)
static void nm_rpc_req_wait_all(nm_rpc_req_t *p_reqs, int n)
static nm_gate_t nm_rpc_get_source(struct nm_rpc_token_s *p_token)
static void nm_rpc_token_delay(struct nm_rpc_token_s *p_token)
int32_t nm_prio_t
message priority
Definition nm_types.h:78
uint64_t nm_tag_t
user tags, 64 bits, contained in indirect hashtable
Definition nm_types.h:56
uint64_t nm_len_t
data length used by nmad
Definition nm_types.h:68
a data descriptor, used to pack/unpack data from app layout to/from contiguous buffers
Definition nm_data.h:200
encapsulate a dynamic vector of nm_data
Definition nm_data.h:255
Connection to another process.
Definition nm_gate.h:109
an outgoing rpc request
struct nm_datav_s headerv
vector of user-supplied chunks of headers
nm_prio_t priority
nm_sr_request_t request
the sendrecv request, actually allocated here
nm_rpc_req_notifier_t p_notifier
notification function to call uppon req completion
struct nm_datav_s bodyv
vector of user-supplied chunks of body
nm_len_t extra_hlen
size added to default header size
void * p_notifier_ref
user-supplied parameter for the notifier
struct nm_rpc_service_s * p_service
descriptor for a registered RPC service
atomic_bool stop_ack
received ACK from the last synchronizing request
atomic_bool running
whether the service is currently running
nm_tag_t tag
tag(s) to listen to for this service
nm_session_t p_session
session used to send/recv requests
nm_tag_t tag_mask
tag mask to apply to above tag
nm_rpc_finalizer_t p_finalizer
user-supplied function, called upon data body arrival
nm_rpc_handler_t p_handler
user-supplied function, called upon header arrival
struct nm_rpc_token_list_s token_list
tokens given to rpc handlers
nm_spinlock_t token_list_lock
lock for the above list
void * ref
user-supplied ref for the service
an incoming rpc request
void * ref
user ref for the token
nm_sr_request_t request
the sr request used for the full rpc_body_data
struct nm_datav_s bodyv
struct nm_rpc_service_s * p_service
service this token belongs to
int delayed
if set to 1, unpack data later
PUK_LIST_LINK(nm_rpc_token)
struct nm_datav_s headerv
internal defintion of the sendrecv request
nm_session_t p_session
session this request belongs to