summaryrefslogtreecommitdiffstats
path: root/vbench/src/vbench/core/socket.h
blob: 52c27dfc6182636c133667d7153a632d0c970a06 (plain) (blame)
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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "string.h"
#include "stream.h"
#include "simple_buffer.h"
#include <memory>

class FastOS_SocketInterface;

namespace vbench {

class Socket : public Stream
{
private:
    std::unique_ptr<FastOS_SocketInterface> _socket;
    SimpleBuffer                            _input;
    SimpleBuffer                            _output;
    Taint                                   _taint;
    bool                                    _eof;

public:
    Socket(std::unique_ptr<FastOS_SocketInterface> socket);
    Socket(const string host, int port);
    virtual ~Socket();
    virtual bool eof() const { return _eof; }
    virtual Memory obtain(size_t bytes, size_t lowMark);
    virtual Input &evict(size_t bytes);
    virtual WritableMemory reserve(size_t bytes);
    virtual Output &commit(size_t bytes, size_t hiMark);
    virtual const Taint &tainted() const { return _taint; }
};

} // namespace vbench