summaryrefslogtreecommitdiff
path: root/i/simulotron/src
diff options
context:
space:
mode:
authorhaller2005-12-02 00:40:03 +0000
committerhaller2005-12-02 00:40:03 +0000
commit8becc9cd13865719346d029a263e9ad4143915c6 (patch)
treeba1aee1b353a20da8b12c2df92d9159bcdbca694 /i/simulotron/src
parentab21fd007709cc4103bbdbe6dc9360b71475a01b (diff)
Mise à jour du configure.ac
Correction des flags et libs pour test_socket modification de socket (problèmes à résoudre)
Diffstat (limited to 'i/simulotron/src')
-rw-r--r--i/simulotron/src/socket/Makefile.incl.am3
-rw-r--r--i/simulotron/src/socket/socket.cc22
-rw-r--r--i/simulotron/src/socket/socket.hh4
3 files changed, 25 insertions, 4 deletions
diff --git a/i/simulotron/src/socket/Makefile.incl.am b/i/simulotron/src/socket/Makefile.incl.am
index a554b58..0cbe7bc 100644
--- a/i/simulotron/src/socket/Makefile.incl.am
+++ b/i/simulotron/src/socket/Makefile.incl.am
@@ -3,4 +3,5 @@ socket_S = socket/socket.cc socket/socket.hh $(address_S) $(errno_exception_S)
check_PROGRAMS += test_socket
test_socket_SOURCES = socket/test_socket.cc $(socket_S)
-test_socket_LDFLAGS = -pthread
+test_socket_CXXFLAGS = -pthread -g -W -Wall
+test_socket_LDADD = -lpthread
diff --git a/i/simulotron/src/socket/socket.cc b/i/simulotron/src/socket/socket.cc
index b696690..0e7f819 100644
--- a/i/simulotron/src/socket/socket.cc
+++ b/i/simulotron/src/socket/socket.cc
@@ -22,10 +22,22 @@ Socket::Socket(int socket)
socket_ = socket;
}
+Socket::Socket(Socket & socket)
+{
+ socket_ = socket.socket_;
+ socket.socket_ = -1;
+}
+
Socket::~Socket(void)
{
- // XXX Pas faisable car les copy détruise les socket
- //close(socket_);
+ if(socket_ >= 0)
+ ::close(socket_);
+}
+
+Socket & Socket::operator= (Socket & socket)
+{
+ socket_ = socket.socket_;
+ socket.socket_ = -1;
}
void Socket::connect(const Address & address)
@@ -46,7 +58,6 @@ Socket Socket::accept(Address & address)
socklen_t length = sizeof(sockaddr_in);
int socket = ::accept(socket_, &addr, &length);
-
if (socket < 0)
throw errno_exception("Chaussette bloqué à la douane", errno);
address = Address(&addr, length);
@@ -104,3 +115,8 @@ void Socket::putChar(char c)
{
::write(socket_, &c, 1);
}
+
+int Socket::getFD(void)
+{
+ return socket_;
+}
diff --git a/i/simulotron/src/socket/socket.hh b/i/simulotron/src/socket/socket.hh
index 3d054fa..92fddfd 100644
--- a/i/simulotron/src/socket/socket.hh
+++ b/i/simulotron/src/socket/socket.hh
@@ -14,8 +14,12 @@ class Socket
Socket(const Address & address);
/// Constructeur à partir d'un fd
Socket(int socket);
+ /// Constructeur par recopie
+ Socket(Socket & socket);
/// Destructeur
~Socket(void);
+ /// operateur d'affectation
+ Socket & operator= (Socket & socket);
/// Connect le client au serveur
void connect(const Address & address);
/// Ecoute le port