From 0ed8ece5e2a75f0782dc5286feea11388b6c9696 Mon Sep 17 00:00:00 2001 From: haller Date: Mon, 12 Dec 2005 00:05:25 +0000 Subject: * correction de bug dans gsTransmitter * Préparation des répertoires pour diverses idées d'implémentation farfelu --- i/simulotron/src/gs/gs_transmitter.cc | 4 ++++ i/simulotron/src/gs/test_gs.cc | 21 +++++++-------------- 2 files changed, 11 insertions(+), 14 deletions(-) (limited to 'i/simulotron') diff --git a/i/simulotron/src/gs/gs_transmitter.cc b/i/simulotron/src/gs/gs_transmitter.cc index 0a0fd44..e593cdb 100644 --- a/i/simulotron/src/gs/gs_transmitter.cc +++ b/i/simulotron/src/gs/gs_transmitter.cc @@ -28,6 +28,7 @@ #include "socket/socket_client.hh" #include +#include GSTransmitter::GSTransmitter(SocketClient & socket) :socket_(socket) @@ -52,6 +53,9 @@ GSTransmitter::getGS(GSMessage & gsm) std::string strRead (socket_.read ()); strBrut_ += strRead; } + // Si la chaine à moins de 4 octect, y'a pas de message + if (strBrut_.size() < 4) + return -1; // On récupère la taille de la gs grace au 4 premier octect size = static_cast (strBrut_[0]) << 24 | static_cast (strBrut_[1]) << 16 diff --git a/i/simulotron/src/gs/test_gs.cc b/i/simulotron/src/gs/test_gs.cc index a2d8724..5367a3d 100644 --- a/i/simulotron/src/gs/test_gs.cc +++ b/i/simulotron/src/gs/test_gs.cc @@ -79,8 +79,7 @@ int main(void) // Reception des messages // une string GSMessage gsm; - if (gst.getGS(gsm) != 0) - throw std::runtime_error ("CHIER!! Reception mal passé"); + while (gst.getGS(gsm) != 0); if (strDepart != gsm.getGS()) { std::cout << "CHIER String altéré\n" @@ -91,8 +90,7 @@ int main(void) } gsm.clear(); // Un char - if (gst.getGS(gsm) != 0) - throw std::runtime_error ("CHIER!! Reception mal passé"); + while (gst.getGS(gsm) != 0); gsm.readGS(&b, sizeof(char)); if ( a != b) { @@ -104,8 +102,7 @@ int main(void) } gsm.clear(); // Un short - if (gst.getGS(gsm) != 0) - throw std::runtime_error ("CHIER!! Reception mal passé"); + while (gst.getGS(gsm) != 0); gsm.readGS(&s2, sizeof(short)); if ( s1 != s2) { @@ -117,8 +114,7 @@ int main(void) } gsm.clear(); // Un int positif - if (gst.getGS(gsm) != 0) - throw std::runtime_error ("CHIER!! Reception mal passé"); + while (gst.getGS(gsm) != 0); gsm.readGS(&i2, sizeof(int)); if ( i1 != i2) { @@ -130,8 +126,7 @@ int main(void) } gsm.clear(); // Un int negatif - if (gst.getGS(gsm) != 0) - throw std::runtime_error ("CHIER!! Reception mal passé"); + while (gst.getGS(gsm) != 0); gsm.readGS(&i4, sizeof(int)); if ( i3 != i4) { @@ -143,8 +138,7 @@ int main(void) } gsm.clear(); // Un Long - if (gst.getGS(gsm) != 0) - throw std::runtime_error ("CHIER!! Reception mal passé"); + while (gst.getGS(gsm) != 0); gsm.readGS(&l2, sizeof(long)); if ( l1 != l2) { @@ -156,8 +150,7 @@ int main(void) } gsm.clear(); // Un gros message - if (gst.getGS(gsm) != 0) - throw std::runtime_error ("CHIER!! Reception mal passé"); + while (gst.getGS(gsm) != 0); gsm.readGS(&s2,sizeof(short)); gsm.readGS(&l2,sizeof(long)); gsm.readGS(&i4,sizeof(int)); -- cgit v1.2.3