@@ -40,6 +40,10 @@ class Concore{
4040 string inpath = " ./in" ;
4141 string outpath = " ./out" ;
4242
43+ // Shared memory segment size in bytes.
44+ // Increase this constant if your payloads exceed 4096 bytes.
45+ // All nodes in a study must be compiled with the same SHM_SIZE.
46+ // Payloads >= SHM_SIZE throw std::runtime_error (no silent truncation).
4347 static constexpr size_t SHM_SIZE = 4096 ;
4448
4549 int shmId_create = -1 ;
@@ -683,9 +687,13 @@ class Concore{
683687 outfile<<val[val.size ()-1 ]<<' ]' ;
684688 std::string result = outfile.str ();
685689 if (result.size () >= SHM_SIZE ) {
686- std::cerr << " ERROR: write_SM payload (" << result.size ()
687- << " bytes) exceeds " << SHM_SIZE - 1
688- << " -byte shared memory limit. Data truncated!" << std::endl;
690+ throw std::runtime_error (
691+ " concore SHM write failed: payload (" +
692+ std::to_string (result.size ()) +
693+ " bytes) exceeds SHM_SIZE (" +
694+ std::to_string (SHM_SIZE ) +
695+ " ). Aborting. No data written. Increase SHM_SIZE in concore.hpp."
696+ );
689697 }
690698 std::strncpy (sharedData_create, result.c_str (), SHM_SIZE - 1 );
691699 sharedData_create[SHM_SIZE - 1 ] = ' \0 ' ;
@@ -711,15 +719,19 @@ class Concore{
711719 void write_SM (int port, string name, string val, int delta=0 ){
712720 chrono::milliseconds timespan ((int )(2000 *delay));
713721 this_thread::sleep_for (timespan);
722+ if (val.size () >= SHM_SIZE ) {
723+ throw std::runtime_error (
724+ " concore SHM write failed: payload (" +
725+ std::to_string (val.size ()) +
726+ " bytes) exceeds SHM_SIZE (" +
727+ std::to_string (SHM_SIZE ) +
728+ " ). Aborting. No data written. Increase SHM_SIZE in concore.hpp."
729+ );
730+ }
714731 try {
715732 if (shmId_create != -1 ){
716733 if (sharedData_create == nullptr )
717734 throw 506 ;
718- if (val.size () >= SHM_SIZE ) {
719- std::cerr << " ERROR: write_SM payload (" << val.size ()
720- << " bytes) exceeds " << SHM_SIZE - 1
721- << " -byte shared memory limit. Data truncated!" << std::endl;
722- }
723735 std::strncpy (sharedData_create, val.c_str (), SHM_SIZE - 1 );
724736 sharedData_create[SHM_SIZE - 1 ] = ' \0 ' ;
725737 }
0 commit comments