-
Notifications
You must be signed in to change notification settings - Fork 6
/
tcp_source.h
45 lines (36 loc) · 1.07 KB
/
tcp_source.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
42
43
44
#pragma once
//
// Author: Alexander Sholohov <[email protected]>
//
// License: MIT
//
#include <string>
#include <netinet/in.h>
#include "buffer.h"
//---------------------------------------------------------------------------------------
class CTcpSource
{
public:
CTcpSource(size_t bufferSize, std::string const& address, unsigned port);
void connectSync();
bool isConnected() const { return m_isConnected; }
int getSocket() const { return m_socket; }
bool checkConnected();
int calcMaxFd(int incomingMaxFd) const;
void putData(const char* buf, size_t len);
bool isWritePending() const;
void doWrite();
unsigned doRead(char* buf, size_t maxLen);
void fillWrSet(fd_set& set) const;
std::string printableAddress() const;
bool isIdentifierPresent() const { return m_identifierPresent; }
void fillIdentifier( std::vector<char>& data ) const;
private:
int m_socket;
std::string m_address;
unsigned m_port;
bool m_isConnected;
CBuffer m_identifierBuffer;
bool m_identifierPresent;
CBuffer m_buffer;
};