| 1 | /************************************************************************* |
|---|---|
| 2 | * libjson-rpc-cpp |
| 3 | ************************************************************************* |
| 4 | * @file tcpsocketserver.cpp |
| 5 | * @date 17.07.2015 |
| 6 | * @author Alexandre Poirot <alexandre.poirot@legrand.fr> |
| 7 | * @license See attached LICENSE.txt |
| 8 | ************************************************************************/ |
| 9 | |
| 10 | #include "tcpsocketserver.h" |
| 11 | #ifdef _WIN32 |
| 12 | #include "windowstcpsocketserver.h" |
| 13 | #else |
| 14 | #include "linuxtcpsocketserver.h" |
| 15 | #endif |
| 16 | #include <string> |
| 17 | |
| 18 | using namespace jsonrpc; |
| 19 | using namespace std; |
| 20 | |
| 21 | TcpSocketServer::TcpSocketServer(const std::string &ipToBind, const unsigned int &port) : AbstractServerConnector() { |
| 22 | #ifdef _WIN32 |
| 23 | this->realSocket = new WindowsTcpSocketServer(ipToBind, port); |
| 24 | #else |
| 25 | this->realSocket = new LinuxTcpSocketServer(ipToBind, port); |
| 26 | #endif |
| 27 | } |
| 28 | |
| 29 | TcpSocketServer::~TcpSocketServer() { delete this->realSocket; } |
| 30 | |
| 31 | bool TcpSocketServer::StartListening() { |
| 32 | if (this->realSocket != NULL) { |
| 33 | this->realSocket->SetHandler(this->GetHandler()); |
| 34 | return this->realSocket->StartListening(); |
| 35 | } else |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | bool TcpSocketServer::StopListening() { |
| 40 | if (this->realSocket != NULL) |
| 41 | return this->realSocket->StopListening(); |
| 42 | else |
| 43 | return false; |
| 44 | } |
| 45 |