summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhaller2005-12-12 00:05:25 +0000
committerhaller2005-12-12 00:05:25 +0000
commit0ed8ece5e2a75f0782dc5286feea11388b6c9696 (patch)
tree182caebc18002fa26c016a97867e62e6e6f0b37c
parent3e691f04f750340df2d1071e99a5889b9b81c05b (diff)
* correction de bug dans gsTransmitter
* Préparation des répertoires pour diverses idées d'implémentation farfelu
-rw-r--r--i/simulotron/src/gs/gs_transmitter.cc4
-rw-r--r--i/simulotron/src/gs/test_gs.cc21
2 files changed, 11 insertions, 14 deletions
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 <sys/select.h>
+#include <iostream>
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<int> (strBrut_[0]) << 24
| static_cast<int> (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));