Welcome to mirror list, hosted at ThFree Co, Russian Federation.

socket.hpp « platform - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ab955523d28eb9664671f16dc929b5f9cd3c09be (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
#pragma once

#include "std/cstdint.hpp"
#include "std/string.hpp"
#include "std/unique_ptr.hpp"

namespace platform
{
class Socket
{
public:
  virtual ~Socket() = default;

  // Open/Close contract:
  // 1. You can call Open+Close pair multiple times for the same Socket instance.
  // 2. There are should be Close call after each Open call.
  // 3. Open+Open: second Open does nothing and returns false.
  // 4. Close+Close: second Close does nothing.
  virtual bool Open(string const & host, uint16_t port) = 0;
  virtual void Close() = 0;

  // Read is blocking, it waits for the 'count' data size.
  virtual bool Read(uint8_t * data, uint32_t count) = 0;
  virtual bool Write(uint8_t const * data, uint32_t count) = 0;

  virtual void SetTimeout(uint32_t milliseconds) = 0;
};

class StubSocket final : public Socket
{
public:
  // Socket overrides:
  bool Open(string const & host, uint16_t port) override { return false; }
  void Close() override {}
  bool Read(uint8_t * data, uint32_t count) override { return false; }
  bool Write(uint8_t const * data, uint32_t count) override { return false; }
  void SetTimeout(uint32_t milliseconds) override {}
};

unique_ptr<Socket> CreateSocket();
}  // namespace platform