summaryrefslogtreecommitdiff
path: root/i/marvin/src/socket
diff options
context:
space:
mode:
authorhaller2006-04-19 05:05:30 +0000
committerhaller2006-04-19 05:05:30 +0000
commitc1f05dce8df57d06ac04d7a7490216fad787f054 (patch)
tree5429eddbfa99802b9dd0394735da6ac615c42167 /i/marvin/src/socket
parent16302ab0ce9263a31e36b93648959575e8c5c02b (diff)
* Correction du commentaire avec le \0 qui fait chier Doxygen et Kermit
* Avancement du SocketDataBuffer
Diffstat (limited to 'i/marvin/src/socket')
-rw-r--r--i/marvin/src/socket/socket_databuffer.cc58
-rw-r--r--i/marvin/src/socket/socket_databuffer.hh7
2 files changed, 65 insertions, 0 deletions
diff --git a/i/marvin/src/socket/socket_databuffer.cc b/i/marvin/src/socket/socket_databuffer.cc
index 8267ddd..241b8f3 100644
--- a/i/marvin/src/socket/socket_databuffer.cc
+++ b/i/marvin/src/socket/socket_databuffer.cc
@@ -23,3 +23,61 @@
// }}}
#include "socket_databuffer.h"
+// Constructeur
+SocketDataBuffer::SocketDataBuffer(void)
+ :SocketClient(), isReceiving_(false), dbSize_(0) // TODO Ça sert à quelque chose où il le fait implicitement?
+{
+}
+
+// Constructeur accept
+SocketDataBuffer::SocketDataBuffer(SocketServer & socketServer)
+ :SocketClient(socketServer), isReceiving_(false), dbSize_(0)
+{
+}
+
+// Récupère un DataBuffer
+bool
+SocketDataBuffer::read(DataBuffer & dbReaded, bool bloquant)
+{
+ bool dbRecu;
+ if (!isReceiving_)
+ {
+ // On récupère les données du socket
+ dbRecu = read(buffer_, bloquant);
+ if(!dbRecu)
+ return false;
+ // On extrait la taille de la DB si possible
+ if(buffer_.size() < 4)
+ {
+ isReceiving_ = true;
+ return false;
+ }
+ else
+ {
+ dbSize_ &= buffer_[0] << 24;
+ dbSize_ &= buffer_[1] << 16;
+ dbSize_ &= buffer_[2] << 8;
+ dbSize_ &= buffer_[3];
+ }
+ TODO
+
+
+}
+
+// Ecrit un DB dans le socket
+void
+SocketDataBuffer::write(const DataBuffer & db)
+{
+ // On met une en-tête de 4 octects déterminant la taille de la DB
+ unsigned dbSize = db.size();
+ write(std::string(static_cast<const char *>(&dbSize)), sizeof(unsigned));
+ // On récupère les données de la dataBuffer
+ uint8_t * donnees = new uint8_t[dbSize];
+ db.read(donnees, dbSize);
+ if (db.size() != 0)
+ throw std::runtime_exception("ERREUR DE CODAGE dans SocketDataBuffer"
+ "::Write");
+ // On envoie le tout et on nettoie l'allocation
+ write(std::string(static_cast<const char *>(donnees), dbSize));
+ delete [] donnees;
+}
diff --git a/i/marvin/src/socket/socket_databuffer.hh b/i/marvin/src/socket/socket_databuffer.hh
index 01f239b..e28c8cd 100644
--- a/i/marvin/src/socket/socket_databuffer.hh
+++ b/i/marvin/src/socket/socket_databuffer.hh
@@ -28,6 +28,13 @@
/// TCP/IP
class SocketDataBuffer : public SocketClient
{
+ private:
+ /// En cours de reception d'un DB
+ bool isReceiving_;
+ /// Taille de la DB à recevoir
+ unsigned dbSize_;
+ /// Tampon provisoire
+ std::string buffer_;
public:
/// Constructeur
SocketDataBuffer(void);