summaryrefslogtreecommitdiff
path: root/i/simulotron/src/socket/socket_server.cc
diff options
context:
space:
mode:
Diffstat (limited to 'i/simulotron/src/socket/socket_server.cc')
-rw-r--r--i/simulotron/src/socket/socket_server.cc59
1 files changed, 45 insertions, 14 deletions
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;
}