summaryrefslogtreecommitdiffstats
path: root/vbench/src/vbench/core/socket.h
blob: 4a281555becee4840e4e348c1e263fab6f1ab221 (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
// 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>

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