Program Listing for File socket_streams.hpp
↰ Return to documentation for file (include/ecl/streams/socket_streams.hpp
)
/*****************************************************************************
** Ifdefs
*****************************************************************************/
#ifndef ECL_STREAMS_SOCKET_STREAMS_HPP_
#define ECL_STREAMS_SOCKET_STREAMS_HPP_
#ifdef ECL_IS_POSIX
/*****************************************************************************
** Includes
*****************************************************************************/
#include <string>
#include <ecl/config/macros.hpp>
#include <ecl/devices/socket.hpp>
#include <ecl/exceptions/standard_exception.hpp>
#include "text_stream.hpp"
#include "macros.hpp"
/*****************************************************************************
** Namespaces
*****************************************************************************/
namespace ecl {
/*****************************************************************************
** Interfaces [SocketClientStream]
*****************************************************************************/
class ecl_streams_PUBLIC SocketClientStream : public TextStream<SocketClient> {
public:
SocketClientStream() {};
SocketClientStream(const std::string &host_name, const unsigned int &port_number) {
ecl_try {
if ( !this->device().open(host_name, port_number) ) {
error = this->device().error();
}
} ecl_catch(StandardException &e) {
ecl_throw(StandardException(LOC,e));
}
}
virtual ~SocketClientStream() {};
};
/*****************************************************************************
** Interfaces [SocketClientStream]
*****************************************************************************/
class ecl_streams_PUBLIC SocketServerStream : public TextStream<SocketServer> {
public:
SocketServerStream() {};
SocketServerStream(const unsigned int &port_number) {
try {
this->device().open(port_number);
} catch(StandardException &e) {
throw StandardException(LOC,e);
}
}
virtual ~SocketServerStream() {};
};
} // namespace ecl
#endif /* ECL_IS_POSIX */
#endif /* ECL_STREAMS_SOCKET_STREAMS_HPP_ */