blob: 34cfc936fda99a9f59ff58bf536f0c16aed1cb97 (
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#ifndef NETWORK_H
#define NETWORK_H
#include <glib.h>
#include <sigc++/sigc++.h>
#include <gio/gio.h>
#include <string>
class AbstractSocket
{
public:
AbstractSocket() : socket(NULL) {}
virtual ~AbstractSocket();
bool isOpen() { return socket != NULL; }
size_t bytesAvailable() { return data.length(); }
bool atEnd() { return data.length() == 0; }
size_t read(const char * buf, size_t num);
std::string readAll();
size_t write(const char *data, size_t len);
virtual bool waitForConnected() = 0;
gboolean dataReceived(GSocket *socket, GIOCondition condition);
// signales
sigc::signal<void> readyRead;
sigc::signal<void> aboutToClose;
protected:
std::string data;
GSocket *socket;
};
class LocalSocket : public AbstractSocket
{
public:
bool connectToServer(const std::string & socketname);
bool waitForConnected();
private:
};
class TcpSocket : public AbstractSocket
{
public:
bool connectToHost(const std::string& hostname, int port);
bool waitForConnected();
private:
};
#endif // NETWORK_H
|