summaryrefslogtreecommitdiff
path: root/src/3rd_party-static/MessageBroker/src/server/mb_server.cpp
blob: 25ec7fc9f313dbc3374b12fe6736952ed829170f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
 * \file mb_server.cpp
 * \brief MessageBroker server.
 * \author AKara
 */

#include "mb_server.hpp"

namespace NsMessageBroker {

Server::Server(const std::string& address, uint16_t port) {
  m_sock = -1;
  m_address = address;
  m_port = port;
}

Server::~Server() {
  if (m_sock != -1) {
    Close();
  }
}

int Server::GetSocket() const {
  return m_sock;
}

std::string Server::GetAddress() const {
  return m_address;
}

uint16_t Server::GetPort() const {
  return m_port;
}

bool Server::Bind() {
  m_sock = networking::bind(m_protocol, m_address, m_port, NULL, NULL);

  return (m_sock != -1) ? true : false;
}

void Server::Close() {
  ::close(m_sock);
  m_sock = -1;
}

} /* namespace NsMessageBroker */