summaryrefslogtreecommitdiff
path: root/i/simulotron/src/gs
diff options
context:
space:
mode:
Diffstat (limited to 'i/simulotron/src/gs')
-rw-r--r--i/simulotron/src/gs/gs_message.cc9
-rw-r--r--i/simulotron/src/gs/gs_message.hh4
-rw-r--r--i/simulotron/src/gs/test_gs.cc16
3 files changed, 26 insertions, 3 deletions
diff --git a/i/simulotron/src/gs/gs_message.cc b/i/simulotron/src/gs/gs_message.cc
index 541c14c..0ab8bb8 100644
--- a/i/simulotron/src/gs/gs_message.cc
+++ b/i/simulotron/src/gs/gs_message.cc
@@ -56,12 +56,21 @@ GSMessage::readGS(void * data, size_t size)
}
void
+GSMessage::getString(std::string & str)
+{
+ std::string tmp (igs_, gs_.end());
+ str.assign(tmp.c_str());
+ igs_ += str.size() + 1;
+}
+
+void
GSMessage::getString(std::string & str, size_t size)
{
str.assign(igs_, igs_ + size);
igs_ += size;
}
+///\todo Est-ce vraiment bien ca? et pourquoi une fct templaté?
void
GSMessage::appendGS (const void * data, size_t size)
{
diff --git a/i/simulotron/src/gs/gs_message.hh b/i/simulotron/src/gs/gs_message.hh
index 45ed43d..cfb0b41 100644
--- a/i/simulotron/src/gs/gs_message.hh
+++ b/i/simulotron/src/gs/gs_message.hh
@@ -44,7 +44,9 @@ class GSMessage
const std::string & getGS (void) const;
/// Récupération de données de la gs
void readGS (void * data, size_t size);
- /// Récupère des données sous forme d'une string
+ /// Récupère des données sous la forme d'une string terminé par un \0
+ void getString (std::string & str);
+ /// Récupère des données sous forme d'une string de taille fixe
void getString (std::string & str, size_t size);
/// Ecriture à la fin de la gs
void appendGS (const void * data, size_t size);
diff --git a/i/simulotron/src/gs/test_gs.cc b/i/simulotron/src/gs/test_gs.cc
index 7416949..acf47f9 100644
--- a/i/simulotron/src/gs/test_gs.cc
+++ b/i/simulotron/src/gs/test_gs.cc
@@ -90,7 +90,8 @@ int testGSServer(SocketServer & sockServ)
// une string
GSMessage gsm;
while (gst.getGS(gsm) != 0);
- if (strDepart != gsm.getGS())
+ gsm.getString(strDest);
+ if (strDepart != strDest)
{
std::cout << "CHIER String altéré\n"
<< "Message d'origine: " << strDepart << "\n"
@@ -163,6 +164,7 @@ int testGSServer(SocketServer & sockServ)
while (gst.getGS(gsm) != 0);
gsm.readGS(&s2,sizeof(short));
gsm.readGS(&l2,sizeof(long));
+ gsm.getString(strDest);
gsm.readGS(&i4,sizeof(int));
if ( s1 != s2)
{
@@ -180,6 +182,15 @@ int testGSServer(SocketServer & sockServ)
<< std::endl;
return 1;
}
+ if ( strDepart != strDest)
+ {
+ std::cout << "CHIER String altéré\n"
+ << "Message d'origine: " << strDepart << "\n"
+ << "Message d'arrivé: " << gsm.getGS()
+ << std::endl;
+ return 1;
+ }
+
if ( i3 != i4)
{
std::cout << "CHIER int negatif altéré\n"
@@ -200,7 +211,7 @@ void testGSClient(int pauseMode)
// Création du transmitter
GSTransmitter gst(std::string("127.0.0.1"), 4242);
GSMessage g1,g2,g3,g4,g5,g6,g7;
- g1.appendGS(strDepart.data(), strDepart.size());
+ g1.appendGS(strDepart.c_str(), strDepart.size() + 1);
gst.putGS(g1);
g2.appendGS(&a, sizeof(char));
gst.putGS(g2);
@@ -215,6 +226,7 @@ void testGSClient(int pauseMode)
g7.appendGS(&l1, sizeof(long));
g7.insertFrontGS(&s1, sizeof(short));
+ g7.appendGS(strDepart.c_str(), strDepart.size() + 1);
g7.appendGS(&i3, sizeof(int));
gst.putGS(g7);
}