@@ -54,12 +54,20 @@ void process_body(int read_fd, int send_fd, bool isMultiOutput) {
5454 return  (PyObject*) NULL ;
5555 }
5656
57-  //  serialize pydata
58-  auto  pydata_str = pickl.pickle (pydata);
59-  if  (PyErr_Occurred ()) return  (PyObject*) NULL ;
57+  //  we may have a fastflow constant as data to send out to index
58+  void  *constant = NULL ;
59+  std::string pydata_str = " "  ;
60+  if  (PyObject_TypeCheck (pydata, &py_ff_constant_type) != 0 ) {
61+  py_ff_constant_object* _const_result = reinterpret_cast <py_ff_constant_object*>(pydata);
62+  constant = _const_result->ff_const ;
63+  } else  {
64+  //  serialize pydata
65+  pydata_str = pickl.pickle (pydata);
66+  if  (PyErr_Occurred ()) return  (PyObject*) NULL ;
67+  }
6068
6169 Message message;
62-  create_message_ff_send_out_to (message, pydata_str, index );
70+  create_message_ff_send_out_to (message, index, constant, pydata_str );
6371
6472 //  send response
6573 int  err = sendMessage (read_fd, send_fd, message);
@@ -140,7 +148,7 @@ void process_body(int read_fd, int send_fd, bool isMultiOutput) {
140148 cleanup_exit ();
141149}
142150
143- #define  EMPTY_TUPLE_STR  " (t." 
151+ #define  SERIALIZED_EMPTY_TUPLE  " (t." 
144152
145153class  base_process  {
146154public:  
@@ -214,22 +222,22 @@ class base_process {
214222 send_fd = mainToChildFD[1 ];
215223 read_fd = childToMainFD[0 ];
216224
217-  int  err = sendMessage (read_fd, send_fd, { .type  = MESSAGE_TYPE_REMOTE_FUNCTION_CALL , .data  = node_str, .f_name  = " "   });
225+  int  err = sendMessage (read_fd, send_fd, { .type  = MESSAGE_TYPE_REMOTE_PROCEDURE_CALL , .data  = node_str, .f_name  = " "   });
218226 if  (err <= 0 ) handleError (" send serialized node"  , returnValue = -1 );
219227
220228 if  (err > 0  && has_svc_init) {
221229 Message response;
222-  auto  empty_tuple = std::string (EMPTY_TUPLE_STR );
223-  int  err = remote_function_call (send_fd, read_fd, empty_tuple, " svc_init"  , response);
230+  auto  empty_tuple = std::string (SERIALIZED_EMPTY_TUPLE );
231+  int  err = remote_procedure_call (send_fd, read_fd, empty_tuple, " svc_init"  , response);
224232 if  (err <= 0 ) {
225233 handleError (" read result of remote call of svc_init"  , );
226234 } else  {
227235 //  Hold the main GIL
228236 PyEval_RestoreThread (tstate);
229237 PyObject *svc_init_result = pickl.unpickle (response.data );
230238 CHECK_ERROR_THEN (" unpickle svc_init_result failure: "  , returnValue = -1 ;)
239+ 
231240 returnValue = 0 ;
232-  //  if we are here, then the GIL was acquired before
233241 if  (PyLong_Check (svc_init_result)) {
234242 long  res_as_long = PyLong_AsLong (svc_init_result);
235243 returnValue = static_cast <int >(res_as_long);
@@ -249,31 +257,35 @@ class base_process {
249257 }
250258
251259 void * svc (void  *arg) {
252-  auto  is_ff_marker = arg ==  ff::FF_GO_ON; 
253-  std::string serialized_data = is_ff_marker  || arg == NULL  ? EMPTY_TUPLE_STR :*reinterpret_cast <std::string*>(arg);
260+  //  arg may be equal to  ff::FF_GO_ON in case of a node of a first set of an a2a that hasn't input channels 
261+  std::string serialized_data = arg ==  NULL   || arg == ff::FF_GO_ON  ? SERIALIZED_EMPTY_TUPLE :*reinterpret_cast <std::string*>(arg);
254262
255263 Message response;
256-  int  err = remote_function_call (send_fd, read_fd, serialized_data, " svc"  , response);
264+  int  err = remote_procedure_call (send_fd, read_fd, serialized_data, " svc"  , response);
257265 if  (err <= 0 ) {
258266 handleError (" remote call of svc"  , );
259267 LOG (" an error occurred, abort."  );
260268 return  NULL ;
261269 }
262270
263-  while (response.type  == MESSAGE_TYPE_REMOTE_FUNCTION_CALL) {
271+  while (response.type  == MESSAGE_TYPE_REMOTE_PROCEDURE_CALL) {
272+  //  the only supported remote procedure call from the child process
273+  //  if the call of ff_send_out_to (as of today...)
264274 if  (response.f_name .compare (" ff_send_out_to"  ) != 0 ) {
265275 handleError (" got invalid f_name"  , );
266276 LOG (" an error occurred, got invalid f_name. Abort."  );
267277 return  NULL ;
268278 }
269279
270280 //  parse received ff_send_out_to request
271-  int  sendout_index = 0 ;
272-  std::string* ser_data = new  std::string ();
273-  parse_message_ff_send_out_to (response, ser_data, &sendout_index);
281+  int  index;
282+  void  *constant = NULL ;
283+  std::string *data = new  std::string ();
284+  parse_message_ff_send_out_to (response, &constant, &index, data);
274285
286+  if  (constant != NULL ) free (data);
275287 //  finally perform ff_send_out_to
276-  bool  result = registered_callback->ff_send_out_to (ser_data, sendout_index );
288+  bool  result = registered_callback->ff_send_out_to (constant !=  NULL  ? constant:data, index );
277289
278290 //  send ff_send_out_to result
279291 err = sendMessage (read_fd, send_fd, { .type  = MESSAGE_TYPE_RESPONSE, .data  = result ? " t"  :" f"  , .f_name  = " "   });
@@ -294,6 +306,7 @@ class base_process {
294306
295307 //  got response of svc
296308 if  (response.type  == MESSAGE_TYPE_RESPONSE_GO_ON) return  ff::FF_GO_ON;
309+  if  (response.type  == MESSAGE_TYPE_RESPONSE_EOS) return  ff::FF_EOS;
297310 if  (response.data .compare (none_str) == 0 ) return  ff::FF_EOS;
298311
299312 return  new  std::string (response.data );
@@ -317,8 +330,8 @@ class base_process {
317330
318331 if  (has_svc_end) {
319332 Message response;
320-  auto  empty_tuple = std::string (EMPTY_TUPLE_STR );
321-  int  err = remote_function_call (send_fd, read_fd, empty_tuple, " svc_end"  , response);
333+  auto  empty_tuple = std::string (SERIALIZED_EMPTY_TUPLE );
334+  int  err = remote_procedure_call (send_fd, read_fd, empty_tuple, " svc_end"  , response);
322335 if  (err <= 0 ) handleError (" read result of remote call of svc_end"  , );
323336 }
324337
0 commit comments