-
Notifications
You must be signed in to change notification settings - Fork 5
/
connection.h
41 lines (33 loc) · 985 Bytes
/
connection.h
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
// Copyright (c) 2017 Suneido Software Corp. All rights reserved
// Licensed under GPLv2
#include <cstdint>
#include "serializer.h"
#include "buffer.h"
class SocketConnect;
class gcstring;
class Value;
class Connection : public Serializer {
public:
explicit Connection(SocketConnect* sc_);
void need(int n) override;
void read(char* buf, int n) override;
void write();
virtual void write(const char* buf, int n);
void close();
private:
SocketConnect& sc;
Buffer rdbuf; // can't use sc.rdbuf because of how sc uses it
};
/// A wrapper for a Connection that treats io exceptions as fatal
class ClientConnection : public Connection {
public:
ClientConnection(SocketConnect* sc) : Connection(sc) {
}
void need(int n) override;
using Connection::write;
void write(const char* buf, int n) override;
void read(char* dst, int n) override;
using Serializer::read;
};
const int HELLO_SIZE = 50; // must match jSuneido