summaryrefslogtreecommitdiff
path: root/i/simulotron/src
diff options
context:
space:
mode:
authorhaller2005-12-03 18:10:59 +0000
committerhaller2005-12-03 18:10:59 +0000
commit2e87c72204b7e2627af6ce9af3566509d239ef15 (patch)
tree504b13a16ecdce175e43bb37315b43c571932590 /i/simulotron/src
parent6e48eaad66126f83480729a38dca1897f2066c11 (diff)
Mise au normes RCS des fichiers du commit (enfin je crois)
Diffstat (limited to 'i/simulotron/src')
-rw-r--r--i/simulotron/src/main.cc28
-rw-r--r--i/simulotron/src/socket/socket_client.cc92
-rw-r--r--i/simulotron/src/socket/socket_client.hh45
-rw-r--r--i/simulotron/src/socket/socket_server.cc59
-rw-r--r--i/simulotron/src/socket/socket_server.hh36
-rw-r--r--i/simulotron/src/socket/test_socket.cc24
6 files changed, 224 insertions, 60 deletions
diff --git a/i/simulotron/src/main.cc b/i/simulotron/src/main.cc
index 2992206..fa1d5e8 100644
--- a/i/simulotron/src/main.cc
+++ b/i/simulotron/src/main.cc
@@ -1,5 +1,29 @@
-
-int main(void)
+/* main.cc - Fonction main du simulotron */
+/* Simulotron - Programme de simulation de robot {{{
+ *
+ * Copyright (C) 2005 Nicolas Haller
+ *
+ * Robot APB Team/Efrei 2005.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+int
+main (void)
{
return 0;
}
diff --git a/i/simulotron/src/socket/socket_client.cc b/i/simulotron/src/socket/socket_client.cc
index 3b7b05b..1224389 100644
--- a/i/simulotron/src/socket/socket_client.cc
+++ b/i/simulotron/src/socket/socket_client.cc
@@ -1,3 +1,27 @@
+/* socket_client.cc - Définition de la classe des sockets client */
+/* Simulotron - Programme de simulation de robot {{{
+ *
+ * Copyright (C) 2005 Nicolas Haller
+ *
+ * Robot APB Team/Efrei 2005.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
#include "socket/socket_client.hh"
#include "socket/socket_server.hh"
#include "socket/address.hh"
@@ -6,81 +30,85 @@
#include <sys/socket.h>
#include <cerrno>
-SocketClient::SocketClient(const Address & address)
+SocketClient::SocketClient (const Address & address)
{
// Crée le file descriptor du socket
socket_ = socket (PF_INET, SOCK_STREAM, 0);
- if(socket_ < 0)
+ if (socket_ < 0)
throw errno_exception ("La chaussette n'a pas pu être tricoté", errno);
-
// On bind le socket
- if(::bind (socket_, address.getSockaddr(), sizeof(*address.getSockaddr())) < 0)
- throw errno_exception("Impossible d'assigner la chausette", errno);
+ if (::bind (socket_, address.getSockaddr (), sizeof (*address.getSockaddr ())) < 0)
+ throw errno_exception ("Impossible d'assigner la chausette", errno);
}
-SocketClient::SocketClient(SocketServer & socketServer)
+SocketClient::SocketClient (SocketServer & socketServer)
{
- socket_ = socketServer.accept();
+ socket_ = socketServer.accept ();
if (socket_ < 0)
- throw errno_exception("Problème lors de la construction d'une chaussette cliente par accept", errno);
+ throw errno_exception ("Problème lors de la construction d'une chaussette cliente par accept", errno);
}
-SocketClient::~SocketClient(void)
+SocketClient::~SocketClient (void)
{
- if(socket_ >= 0)
- ::close(socket_);
+ if (socket_ >= 0)
+ ::close (socket_);
}
-void SocketClient::connect(const Address & address)
+void
+SocketClient::connect (const Address & address)
{
- if (::connect (socket_, address.getSockaddr(), sizeof(sockaddr_in)) < 0)
- throw errno_exception("Impossible de mettre la chaussette", errno);
+ if (::connect (socket_, address.getSockaddr (), sizeof (sockaddr_in)) < 0)
+ throw errno_exception ("Impossible de mettre la chaussette", errno);
}
-std::string SocketClient::read(void)
+std::string
+SocketClient::read (void)
{
std::string str;
int charReaded;
char buffer[BUFFER_SIZE];
do
{
- charReaded = ::read(socket_, buffer, BUFFER_SIZE - 1);
- if(charReaded < 0)
- throw errno_exception("SocketClient: problème de lecture", errno);
+ charReaded = ::read (socket_, buffer, BUFFER_SIZE - 1);
+ if (charReaded < 0)
+ throw errno_exception ("SocketClient: problème de lecture", errno);
buffer[charReaded] = 0;
str += buffer;
- }while(charReaded == BUFFER_SIZE - 1);
+ }while (charReaded == BUFFER_SIZE - 1);
return str;
}
-void SocketClient::write(const std::string & str)
+void
+SocketClient::write (const std::string & str)
{
char buffer[BUFFER_SIZE];
unsigned int pos = 0;
int retval = 0;
- while(str.size() != pos)
+ while (str.size () != pos)
{
- int size = str.size() - pos < BUFFER_SIZE - 1 ? str.size() - pos:BUFFER_SIZE - 1;
- str.copy(buffer, size, pos);
+ int size = str.size () - pos < BUFFER_SIZE - 1 ? str.size () - pos:BUFFER_SIZE - 1;
+ str.copy (buffer, size, pos);
pos += size;
buffer[size] = 0;
- retval = ::write(socket_, buffer, size);
- if(retval < 0)
- throw errno_exception("SocketClient: erreur d'écriture (write()) ", errno);
+ retval = ::write (socket_, buffer, size);
+ if (retval < 0)
+ throw errno_exception ("SocketClient: erreur d'écriture (write()) ", errno);
}
}
-char SocketClient::getChar(void)
+char
+SocketClient::getChar (void)
{
char getted;
- if(::read(socket_, &getted, 1) < 0)
- throw errno_exception("SocketClient: erreur d'écriture (write()) ", errno);
+ if (::read (socket_, &getted, 1) < 0)
+ throw errno_exception ("SocketClient: erreur d'écriture (write()) ", errno);
return getted;
}
-void SocketClient::putChar(char c)
+void
+SocketClient::putChar (char c)
{
- if(::write(socket_, &c, 1) < 0)
- throw errno_exception("SocketClient: erreur d'écriture (write()) ", errno);
+ if (::write (socket_, &c, 1) < 0)
+ throw errno_exception ("SocketClient: erreur d'écriture (write()) ", errno);
}
diff --git a/i/simulotron/src/socket/socket_client.hh b/i/simulotron/src/socket/socket_client.hh
index 112a4dd..a024bec 100644
--- a/i/simulotron/src/socket/socket_client.hh
+++ b/i/simulotron/src/socket/socket_client.hh
@@ -1,4 +1,31 @@
+#ifndef socket_client_hh
+#define socket_client_hh
+/* socket_client.hh - Classe des socket client */
+/* Simulotron - Programme de simulation de robot {{{
+ *
+ * Copyright (C) 2005 Nicolas Haller
+ *
+ * Robot APB Team/Efrei 2005.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
#include <string>
+
class Address;
class SocketServer;
@@ -12,19 +39,21 @@ class SocketClient
static const int BUFFER_SIZE = 256;
public:
/// Constructeur
- SocketClient(const Address & address);
+ SocketClient (const Address & address);
/// Constructeur accept
- SocketClient(SocketServer & socketServer);
+ SocketClient (SocketServer & socketServer);
/// Destructeur
- ~SocketClient(void);
+ ~SocketClient (void);
/// Connect le client au serveur
- void connect(const Address & address);
+ void connect (const Address & address);
/// lit du socket
- std::string read(void);
+ std::string read (void);
/// écrit dans le socket
- void write(const std::string & str);
+ void write (const std::string & str);
/// lit un charactère du socket
- char getChar(void);
+ char getChar (void);
/// écrit un charactère dans le socket
- void putChar(char c);
+ void putChar (char c);
};
+
+#endif //socket_client_hh
diff --git a/i/simulotron/src/socket/socket_server.cc b/i/simulotron/src/socket/socket_server.cc
index c214ca7..6014171 100644
--- a/i/simulotron/src/socket/socket_server.cc
+++ b/i/simulotron/src/socket/socket_server.cc
@@ -1,3 +1,28 @@
+/* socket_serveur.cc - Définition de la classe des sockets client */
+/* Simulotron - Programme de simulation de robot {{{
+ *
+ * Copyright (C) 2005 Nicolas Haller
+ *
+ * Robot APB Team/Efrei 2005.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
#include "socket/socket_server.hh"
#include "utils/errno_exception.hh"
#include "socket/address.hh"
@@ -5,35 +30,41 @@
#include <sys/socket.h>
#include <cerrno>
-SocketServer::SocketServer(const Address & address)
+SocketServer::SocketServer (const Address & address)
{
+ static const int reuse_s = 1;
// Crée le file descriptor du socket
socket_ = socket (PF_INET, SOCK_STREAM, 0);
- if(socket_ < 0)
+ if (socket_ < 0)
throw errno_exception ("La chaussette n'a pas pu être tricoté", errno);
-
+ // On règle la réusabilité du socket
+ if (setsockopt (socket_, SOL_SOCKET, SO_REUSEADDR,
+ &reuse_s, sizeof (int)) == -1)
+ throw errno_exception ("Erreur setsockopt : reusable", errno);
// On bind le socket
- if(::bind (socket_, address.getSockaddr(), sizeof(*address.getSockaddr())) < 0)
- throw errno_exception("Impossible d'assigner la chausette", errno);
+ if (::bind (socket_, address.getSockaddr (), sizeof (*address.getSockaddr ())) < 0)
+ throw errno_exception ("Impossible d'assigner la chausette", errno);
}
-SocketServer::~SocketServer(void)
+SocketServer::~SocketServer (void)
{
- if(socket_ >= 0)
- ::close(socket_);
+ if (socket_ >= 0)
+ ::close (socket_);
}
-void SocketServer::listen(int maxQueue)
+ void
+SocketServer::listen (int maxQueue)
{
- if(::listen(socket_, maxQueue) < 0 )
- throw errno_exception("Impossible d'écouter la mer dans la chaussette", errno);
+ if (::listen (socket_, maxQueue) < 0 )
+ throw errno_exception ("Impossible d'écouter la mer dans la chaussette", errno);
}
-int SocketServer::accept(void)
+ int
+SocketServer::accept (void)
{
- int socket = ::accept(socket_, 0, 0);
+ int socket = ::accept (socket_, 0, 0);
if (socket < 0)
- throw errno_exception("Chaussette bloqué à la douane", errno);
+ throw errno_exception ("Chaussette bloqué à la douane", errno);
return socket;
}
diff --git a/i/simulotron/src/socket/socket_server.hh b/i/simulotron/src/socket/socket_server.hh
index bac6687..3b95949 100644
--- a/i/simulotron/src/socket/socket_server.hh
+++ b/i/simulotron/src/socket/socket_server.hh
@@ -1,3 +1,29 @@
+#ifndef socket_server_hh
+#define socket_server_hh
+/* socket_server.hh - Classe des sockets serveur */
+/* Simulotron - Programme de simulation de robot {{{
+ *
+ * Copyright (C) 2005 Nicolas Haller
+ *
+ * Robot APB Team/Efrei 2005.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
#include <string>
class Address;
@@ -8,11 +34,13 @@ class SocketServer
int socket_;
public:
/// Constructeur
- SocketServer(const Address & address);
+ SocketServer (const Address & address);
/// Destructeur
- ~SocketServer(void);
+ ~SocketServer (void);
/// Ecoute le port
- void listen(int maxQueue);
+ void listen (int maxQueue);
/// accepte une connection et renvoie le fd
- int accept(void);
+ int accept (void);
};
+
+#endif //socket_server_hh
diff --git a/i/simulotron/src/socket/test_socket.cc b/i/simulotron/src/socket/test_socket.cc
index 66ad30f..a2c729e 100644
--- a/i/simulotron/src/socket/test_socket.cc
+++ b/i/simulotron/src/socket/test_socket.cc
@@ -1,3 +1,27 @@
+/* test_socket.cc - Programme de test des sockets. */
+/* Simulotron - Programme de simulation de robot {{{
+ *
+ * Copyright (C) 2005 Nicolas Haller
+ *
+ * Robot APB Team/Efrei 2005.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
#include "socket/address.hh"
#include "socket/socket_server.hh"
#include "socket/socket_client.hh"