summaryrefslogtreecommitdiff
path: root/i/simulotron/src/gs
diff options
context:
space:
mode:
authorhaller2005-12-07 16:36:13 +0000
committerhaller2005-12-07 16:36:13 +0000
commit3e691f04f750340df2d1071e99a5889b9b81c05b (patch)
tree04fd4eb1c8a4378e98a1d805c0234cd2a88bddb6 /i/simulotron/src/gs
parent6dd92c230db1e1c27b02f54a86fb710c1d7269fc (diff)
* Ajout d'une fonction getFD dans les classe socket*
* Mini-optimisation dans GSTransmitter * rajout d'une bidouille pour rendre GSTransmitter non bloquant
Diffstat (limited to 'i/simulotron/src/gs')
-rw-r--r--i/simulotron/src/gs/gs_transmitter.cc25
1 files changed, 19 insertions, 6 deletions
diff --git a/i/simulotron/src/gs/gs_transmitter.cc b/i/simulotron/src/gs/gs_transmitter.cc
index e9b6648..0a0fd44 100644
--- a/i/simulotron/src/gs/gs_transmitter.cc
+++ b/i/simulotron/src/gs/gs_transmitter.cc
@@ -27,6 +27,8 @@
#include "gs/gs_message.hh"
#include "socket/socket_client.hh"
+#include <sys/select.h>
+
GSTransmitter::GSTransmitter(SocketClient & socket)
:socket_(socket)
{
@@ -36,29 +38,40 @@ GSTransmitter::GSTransmitter(SocketClient & socket)
int
GSTransmitter::getGS(GSMessage & gsm)
{
- ///BUG Pas portable le code, suppose des int à 4 octect
+ ///\bug Pas portable le code, suppose des int à 4 octect
+ fd_set fds;
+ timeval tv = {0, 0};
unsigned int size = 0;
- std::string strRead (socket_.read ());
- strBrut_ += strRead;
+
+ FD_ZERO(&fds);
+ FD_SET(socket_.getFD(), &fds);
+ //On lit le socket que si y'a quelque chose à lire
+ ///\bug C'est top ca?
+ if(select(socket_.getFD() + 1, &fds, NULL, NULL, &tv) > 0)
+ {
+ std::string strRead (socket_.read ());
+ strBrut_ += strRead;
+ }
+ // 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
| static_cast<int> (strBrut_[2]) << 8
| static_cast<int> (strBrut_[3]);
if(size > strBrut_.size() - 4)
return -1;
- strRead = strBrut_.substr (4, size);
+ gsm.writeGS (strBrut_.substr(4, size).data(), size);
strBrut_.erase (0, size + 4);
- gsm.writeGS (strRead.data (), size);
return 0;
}
void
GSTransmitter::putGS(const GSMessage & gsm)
{
- ///BUG Pas portable le code, suppose des int à 4 octect
+ ///\bug Pas portable le code, suppose des int à 4 octect
std::string gs(gsm.getGS ());
char bsize[4];
int size = gs.size();
+ // On transfore la taille de la gs en 4 octect qui seront envoyé en premier
bsize[0] = static_cast<char> (size >> 24);
bsize[1] = static_cast<char> (size >> 16);
bsize[2] = static_cast<char> (size >> 8);