From 349a66d2b2f8e725df8634f9d2947319245fb291 Mon Sep 17 00:00:00 2001 From: haller Date: Sun, 27 Nov 2005 23:27:49 +0000 Subject: Ebauche de classe socket Mise en place de la structure automake/autoconf pour le simulotron --- i/simulotron/AUTHORS | 0 i/simulotron/COPYING | 0 i/simulotron/ChangeLog | 0 i/simulotron/INSTALL | 0 i/simulotron/Makefile.am | 1 + i/simulotron/NEWS | 0 i/simulotron/README | 0 i/simulotron/configure.ac | 33 +++++++++++++++++++++++++++ i/simulotron/doc/Makefile.am | 0 i/simulotron/src/Makefile.am | 7 ++++++ i/simulotron/src/main.cc | 5 +++++ i/simulotron/src/socket/socket.cc | 41 ++++++++++++++++++++++++++++++++++ i/simulotron/src/socket/socket.hh | 29 ++++++++++++++++++++++++ i/simulotron/test/Makefile.am | 2 ++ i/simulotron/test/socket/Makefile.am | 5 +++++ i/simulotron/test/socket/testsocket.cc | 5 +++++ 16 files changed, 128 insertions(+) create mode 100644 i/simulotron/AUTHORS create mode 100644 i/simulotron/COPYING create mode 100644 i/simulotron/ChangeLog create mode 100644 i/simulotron/INSTALL create mode 100644 i/simulotron/Makefile.am create mode 100644 i/simulotron/NEWS create mode 100644 i/simulotron/README create mode 100644 i/simulotron/configure.ac create mode 100644 i/simulotron/doc/Makefile.am create mode 100644 i/simulotron/src/Makefile.am create mode 100644 i/simulotron/src/main.cc create mode 100644 i/simulotron/src/socket/socket.cc create mode 100644 i/simulotron/src/socket/socket.hh create mode 100644 i/simulotron/test/Makefile.am create mode 100644 i/simulotron/test/socket/Makefile.am create mode 100644 i/simulotron/test/socket/testsocket.cc (limited to 'i/simulotron') diff --git a/i/simulotron/AUTHORS b/i/simulotron/AUTHORS new file mode 100644 index 0000000..e69de29 diff --git a/i/simulotron/COPYING b/i/simulotron/COPYING new file mode 100644 index 0000000..e69de29 diff --git a/i/simulotron/ChangeLog b/i/simulotron/ChangeLog new file mode 100644 index 0000000..e69de29 diff --git a/i/simulotron/INSTALL b/i/simulotron/INSTALL new file mode 100644 index 0000000..e69de29 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 diff --git a/i/simulotron/README b/i/simulotron/README new file mode 100644 index 0000000..e69de29 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 ) +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 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 + +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; +} -- cgit v1.2.3