summaryrefslogtreecommitdiff
path: root/i/marvin/src
diff options
context:
space:
mode:
Diffstat (limited to 'i/marvin/src')
-rw-r--r--i/marvin/src/log/log_server.cc20
-rw-r--r--i/marvin/src/log/log_server.hh8
-rw-r--r--i/marvin/src/socket/socket_client.cc22
-rw-r--r--i/marvin/src/socket/socket_client.hh2
4 files changed, 29 insertions, 23 deletions
diff --git a/i/marvin/src/log/log_server.cc b/i/marvin/src/log/log_server.cc
index bba80f5..126ed66 100644
--- a/i/marvin/src/log/log_server.cc
+++ b/i/marvin/src/log/log_server.cc
@@ -23,26 +23,32 @@
//
// }}}
#include "log_server.hh"
-#include "socket/socket_databuffer.hh"
+#include "socket/socket_client.hh"
-LogServer::LogServer(DataBuffer & db, const Address & address)
- :ss_(address),db_(db)
+LogServer::LogServer(DataInput & di, const Address & address)
+ :ss_(address),di_(di)
{
}
-LogServer::LogServer(DataBuffer & db, const std::string & address,
+LogServer::LogServer(DataInput & di, const std::string & address,
int port)
- :ss_(address, port),db_(db)
+ :ss_(address, port),di_(di)
{
}
void
LogServer::listen(void)
{
+ int charBuffer;
+
+ const unsigned BUFFER_SIZE = 256;
+ // Buffer de taille completement arbitraire
+ uint8_t buffer[BUFFER_SIZE];
// Ouvre les oreilles du socket
ss_.listen(1);
// Attend gentillement une connection
- SocketDataBuffer sdb(ss_);
+ SocketClient sc(ss_);
// Paf on envoie la sauce
- sdb.write(db_);
+ while((charBuffer = di_.read(buffer, BUFFER_SIZE)) != 0)
+ sc.write(buffer, charBuffer);
}
diff --git a/i/marvin/src/log/log_server.hh b/i/marvin/src/log/log_server.hh
index c9b9cf5..a18de15 100644
--- a/i/marvin/src/log/log_server.hh
+++ b/i/marvin/src/log/log_server.hh
@@ -26,7 +26,7 @@
// }}}
#include "socket/socket_server.hh"
-#include "data/data_buffer.hh"
+#include "data/data_input.hh"
/// Classe pour récupérer les logs.
/// La classe construit un serveur en fin de match pour pouvoir récupérer les
@@ -37,12 +37,12 @@ class LogServer
/// La socket serveur qui attend la ze connection
SocketServer ss_;
/// La dataBuffer à transmettre (avec les logs dedans c'est mieux)
- DataBuffer & db_;
+ DataInput & di_;
public:
/// Constructeur
- LogServer(DataBuffer & db, const Address & address);
+ LogServer(DataInput & di, const Address & address);
/// Constructeur
- LogServer(DataBuffer & db, const std::string & address, int port);
+ LogServer(DataInput & di, const std::string & address, int port);
/// Mise en écoute du serveur
void listen(void);
};
diff --git a/i/marvin/src/socket/socket_client.cc b/i/marvin/src/socket/socket_client.cc
index 9dd19fa..951ea6a 100644
--- a/i/marvin/src/socket/socket_client.cc
+++ b/i/marvin/src/socket/socket_client.cc
@@ -95,19 +95,17 @@ SocketClient::read (std::string & strReaded, bool bloquant)
void
SocketClient::write (const std::string & str)
{
- char buffer[BUFFER_SIZE];
- unsigned int pos = 0;
- int retval = 0;
+ write(reinterpret_cast<const uint8_t *>(str.data()), str.size());
+}
- while (str.size () != pos)
- {
- int size = str.size () - pos < BUFFER_SIZE - 1 ? str.size () - pos:BUFFER_SIZE - 1;
- str.copy (buffer, size, pos);
- pos += size;
- retval = ::write (socket_, buffer, size);
- if (retval < 0)
- throw errno_exception ("SocketClient: erreur d'écriture (write()) ", errno);
- }
+void
+SocketClient::write (const uint8_t * buffer, unsigned size)
+{
+ int retval;
+
+ retval = ::write (socket_, buffer, size);
+ if (retval < 0)
+ throw errno_exception ("SocketClient: erreur d'écriture (write()) ", errno);
}
//int
diff --git a/i/marvin/src/socket/socket_client.hh b/i/marvin/src/socket/socket_client.hh
index 066f5fd..d17a983 100644
--- a/i/marvin/src/socket/socket_client.hh
+++ b/i/marvin/src/socket/socket_client.hh
@@ -55,6 +55,8 @@ class SocketClient :public NonCopyable
bool read (std::string & strReaded, bool bloquant);
/// écrit dans le socket
void write (const std::string & str);
+ /// écrit dans le socket
+ void write (const uint8_t * buffer, unsigned size);
};
#endif //socket_client_hh