summaryrefslogtreecommitdiff
path: root/i/simulotron
diff options
context:
space:
mode:
authorhaller2005-11-27 23:27:49 +0000
committerhaller2005-11-27 23:27:49 +0000
commit349a66d2b2f8e725df8634f9d2947319245fb291 (patch)
tree6f9f912b82d4ed14978e0f296a7864fb03c6d656 /i/simulotron
parentdb934e657caf4c471a1adf521127892eed4e14fd (diff)
Ebauche de classe socket
Mise en place de la structure automake/autoconf pour le simulotron
Diffstat (limited to 'i/simulotron')
-rw-r--r--i/simulotron/AUTHORS0
-rw-r--r--i/simulotron/COPYING0
-rw-r--r--i/simulotron/ChangeLog0
-rw-r--r--i/simulotron/INSTALL0
-rw-r--r--i/simulotron/Makefile.am1
-rw-r--r--i/simulotron/NEWS0
-rw-r--r--i/simulotron/README0
-rw-r--r--i/simulotron/configure.ac33
-rw-r--r--i/simulotron/doc/Makefile.am0
-rw-r--r--i/simulotron/src/Makefile.am7
-rw-r--r--i/simulotron/src/main.cc5
-rw-r--r--i/simulotron/src/socket/socket.cc41
-rw-r--r--i/simulotron/src/socket/socket.hh29
-rw-r--r--i/simulotron/test/Makefile.am2
-rw-r--r--i/simulotron/test/socket/Makefile.am5
-rw-r--r--i/simulotron/test/socket/testsocket.cc5
16 files changed, 128 insertions, 0 deletions
diff --git a/i/simulotron/AUTHORS b/i/simulotron/AUTHORS
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/i/simulotron/AUTHORS
diff --git a/i/simulotron/COPYING b/i/simulotron/COPYING
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/i/simulotron/COPYING
diff --git a/i/simulotron/ChangeLog b/i/simulotron/ChangeLog
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/i/simulotron/ChangeLog
diff --git a/i/simulotron/INSTALL b/i/simulotron/INSTALL
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/i/simulotron/INSTALL
diff --git a/i/simulotron/Makefile.am b/i/simulotron/Makefile.am
new file mode 100644
index 0000000..f4166ba
--- /dev/null
+++ b/i/simulotron/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS=src test doc
diff --git a/i/simulotron/NEWS b/i/simulotron/NEWS
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/i/simulotron/NEWS
diff --git a/i/simulotron/README b/i/simulotron/README
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/i/simulotron/README
diff --git a/i/simulotron/configure.ac b/i/simulotron/configure.ac
new file mode 100644
index 0000000..2936c96
--- /dev/null
+++ b/i/simulotron/configure.ac
@@ -0,0 +1,33 @@
+# -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ(2.59)
+AC_INIT(simulotron, 2006.0.01, APBTeam <si2e@efrei.fr>)
+AC_CONFIG_AUX_DIR(config)
+AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
+AC_CONFIG_SRCDIR([src/main.cc])
+
+CXXFLAGS=
+
+# Checks for programs
+AC_PROG_CXX
+
+# Checks for libraries.
+
+# Checks for header files.
+AC_CHECK_HEADERS([sys/socket.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_HEADER_STDBOOL
+AC_C_CONST
+
+# Checks for library functions.
+AC_CHECK_FUNCS([socket])
+
+
+AC_CONFIG_FILES([Makefile
+ doc/Makefile
+ src/Makefile
+ test/Makefile
+ test/socket/Makefile])
+AC_OUTPUT
diff --git a/i/simulotron/doc/Makefile.am b/i/simulotron/doc/Makefile.am
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/i/simulotron/doc/Makefile.am
diff --git a/i/simulotron/src/Makefile.am b/i/simulotron/src/Makefile.am
new file mode 100644
index 0000000..2970e77
--- /dev/null
+++ b/i/simulotron/src/Makefile.am
@@ -0,0 +1,7 @@
+bin_PROGRAMS = simulotron
+simulotron_SOURCES = main.cc \
+ socket/socket.cc socket/socket.hh
+
+simulotron_CXXFLAGS = -g -Wall -fmessage-length=0
+simulotron_LDADD =
+INCLUDES = -I../../src
diff --git a/i/simulotron/src/main.cc b/i/simulotron/src/main.cc
new file mode 100644
index 0000000..2992206
--- /dev/null
+++ b/i/simulotron/src/main.cc
@@ -0,0 +1,5 @@
+
+int main(void)
+{
+ return 0;
+}
diff --git a/i/simulotron/src/socket/socket.cc b/i/simulotron/src/socket/socket.cc
new file mode 100644
index 0000000..2f7139c
--- /dev/null
+++ b/i/simulotron/src/socket/socket.cc
@@ -0,0 +1,41 @@
+#include <sys/socket.h>
+
+Socket::Socket(const std::string & address, int port, bool block)
+{
+ // Crée le file descriptor du socket
+ socket_ = socket (PF_INET, SOCK_STREAM, 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);
+}
+
+void Socket::connect(const Address & address)
+{
+ if (connect (socket_, address.getSockaddr(), sizeof(*address.getSockaddr()) < 0))
+ throw errno_exception("Impossible de mettre la chaussette", errno);
+}
+
+void Socket::listen(int maxQueue)
+{
+ if( listen(socket_, maxQueue) < 0 )
+ throw errno_exception("Impossible d'écouter la mer dans la chaussette", errno);
+}
+
+Socket Socket::accept(Address & address)
+{
+ sockaddr addr;
+ socklen_t length;
+
+ int socket = accept(socket_, &addr, &length);
+
+ if (socket < 0)
+ throw errno_exception("Chaussette bloqué à la douane", errno);
+ address = Address(addr, length);
+
+ return Socket(socket);
+}
+
+
diff --git a/i/simulotron/src/socket/socket.hh b/i/simulotron/src/socket/socket.hh
new file mode 100644
index 0000000..c1b47df
--- /dev/null
+++ b/i/simulotron/src/socket/socket.hh
@@ -0,0 +1,29 @@
+class Socket
+{
+ private:
+ /// Ze socket
+ int socket_;
+ public:
+ /// Constructeur
+ Socket(const Address & adress, bool block = false);
+ /// Constructeur à partir d'un fd
+ Socket(int socket);
+ /// Connect le client au serveur
+ void connect(void);
+ /// Ecoute le port
+ void listen(void);
+ /// accepte une connection
+ void accept(void);
+ /// lit du socket
+ void read(void);
+ /// écrit dans le socket
+ void write(void);
+ /// lit un charactère du socket
+ void getChar(void);
+ /// écrit un charactère dans le socket
+ void putChar(void);
+ /// Drapeau connecté
+ bool isConnected(void);
+ private:
+ void bind();
+};
diff --git a/i/simulotron/test/Makefile.am b/i/simulotron/test/Makefile.am
new file mode 100644
index 0000000..d4e15a5
--- /dev/null
+++ b/i/simulotron/test/Makefile.am
@@ -0,0 +1,2 @@
+SUBDIRS = socket
+TESTS = socket/testsocket
diff --git a/i/simulotron/test/socket/Makefile.am b/i/simulotron/test/socket/Makefile.am
new file mode 100644
index 0000000..344d20c
--- /dev/null
+++ b/i/simulotron/test/socket/Makefile.am
@@ -0,0 +1,5 @@
+check_PROGRAMS = testsocket
+testsocket_SOURCES = testsocket.cc \
+ ../../src/date/diffdate.cc ../../src/date/diffdate.hh
+AM_CXXFLAGS=-g -W -Wall -fmessage-length=0
+INCLUDES= -I../../src
diff --git a/i/simulotron/test/socket/testsocket.cc b/i/simulotron/test/socket/testsocket.cc
new file mode 100644
index 0000000..2992206
--- /dev/null
+++ b/i/simulotron/test/socket/testsocket.cc
@@ -0,0 +1,5 @@
+
+int main(void)
+{
+ return 0;
+}