Go to the documentation of this file.00001 
00010 
00011 
00012 
00013 
00014 #ifndef ECL_DEVICES_SOCKET_SERVER_POS_HPP_
00015 #define ECL_DEVICES_SOCKET_SERVER_POS_HPP_
00016 
00017 
00018 
00019 
00020 
00021 #include <ecl/config/ecl.hpp>
00022 #ifndef ECL_IS_MAC
00023 #ifdef ECL_IS_POSIX
00024 
00025 
00026 
00027 
00028 
00029 #include <arpa/inet.h> 
00030 #include <sys/ioctl.h> 
00031 #include <errno.h>
00032 #include <sys/socket.h>
00033 
00034 #include "detail/socket_error_handler_pos.hpp"
00035 #include "detail/socket_exception_handler_pos.hpp"
00036 #include "traits.hpp"
00037 
00038 
00039 
00040 
00041 
00042 namespace ecl {
00043 
00044 
00045 
00046 
00060 class SocketServer {
00061 public:
00062         
00063 
00064 
00065         SocketServer() : is_open(false) {}; 
00076         SocketServer(const unsigned int &port_number) ecl_throw_decl(StandardException);
00077         virtual ~SocketServer() { close(); }; 
00079         
00080 
00081 
00092         bool open( const unsigned int& port_number ) ecl_throw_decl(StandardException);
00110         void close() { is_open = false; ::close(socket_fd); }
00111 
00112         bool open() const { return is_open; }
00113 
00114         
00115 
00116 
00125         long write(const char &c) ecl_debug_throw_decl(StandardException) { return write(&c,1); }
00126 
00135         long write(const char *s, unsigned long n) ecl_debug_throw_decl(StandardException);
00136 
00143         void flush() {}
00144 
00145         
00146 
00147 
00155         long remaining();
00174     long read(char &c) ecl_debug_throw_decl(StandardException) { return read(&c,1); }
00184     long read(char *s, const unsigned long &n) ecl_debug_throw_decl(StandardException);
00195     long peek(char*s, const unsigned long &n) ecl_debug_throw_decl(StandardException);
00196 
00197     
00198 
00199 
00208     int listen() ecl_throw_decl(StandardException);
00209 
00213         const Error& error() const { return error_handler; }
00214 
00215 private:
00216     int port;
00217     int socket_fd;
00218     int client_socket_fd;
00219     bool is_open;
00220     Error error_handler;
00221 };
00222 
00223 
00224 
00225 
00231 template <>
00232 class is_sink<SocketServer> : public True {};
00233 
00239 template <>
00240 class is_source<SocketServer> : public True {};
00241 
00247 template <>
00248 class is_sourcesink<SocketServer> : public True {};
00249 
00250 } 
00251 
00252 #endif  
00253 #endif  
00254 
00255 #endif