Go to the documentation of this file.00001 
00010 
00011 
00012 
00013 
00014 #ifndef ECL_DEVICES_SOCKET_CLIENT_POS_HPP_
00015 #define ECL_DEVICES_SOCKET_CLIENT_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 
00030 #include <arpa/inet.h> 
00031 #include <errno.h>
00032 #include <string>
00033 #include <sys/ioctl.h> 
00034 #include <sys/socket.h>
00035 #include <ecl/exceptions/macros.hpp>
00036 #include <ecl/exceptions/standard_exception.hpp>
00037 #include "socket_connection_status.hpp"
00038 #include "detail/socket_error_handler_pos.hpp"
00039 #include "traits.hpp"
00040 
00041 
00042 
00043 
00044 
00045 namespace ecl {
00046 
00047 
00048 
00049 
00064 class SocketClient {
00065 public:
00066         
00067 
00068 
00069         SocketClient() : is_open(false), error_handler(NoError) {}; 
00081         SocketClient(const std::string &host_name, const unsigned int &port_number = 5555) ecl_throw_decl(StandardException);
00082         virtual ~SocketClient() { close(); } 
00084         
00085 
00086 
00098         bool open( const std::string &hostname, const unsigned int& port_number ) ecl_throw_decl(StandardException);
00099         void close(); 
00101         bool open() const { return is_open; }
00102 
00103         
00104 
00105 
00114         long write(const char &c) ecl_debug_throw_decl(StandardException);
00115 
00124         long write(const char *s, unsigned long n) ecl_debug_throw_decl(StandardException);
00125 
00132         void flush() {}
00133 
00134         
00135 
00136 
00144         long remaining();
00153     long read(char &c) ecl_debug_throw_decl(StandardException);
00173     long read(char *s, const unsigned long &n) ecl_debug_throw_decl(StandardException);
00186     long peek(char*s, const unsigned long &n) ecl_debug_throw_decl(StandardException);
00187 
00191         const Error& error() const { return error_handler; }
00192 
00193 private:
00194     std::string hostname;
00195     int port;
00196     int socket_fd;
00197     bool is_open;
00198     ecl::Error error_handler;
00199 };
00200 
00201 
00202 
00203 
00209 template <>
00210 class is_sink<SocketClient> : public True {};
00211 
00217 template <>
00218 class is_source<SocketClient> : public True {};
00219 
00225 template <>
00226 class is_sourcesink<SocketClient> : public True {};
00227 
00228 } 
00229 
00230 #endif  
00231 #endif  
00232 
00233 #endif