[go: up one dir, main page]

Menu

[4f9184]: / src / ysocket.h  Maximize  Restore  History

Download this file

49 lines (35 with data), 852 Bytes

 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
#ifndef YSOCKET_H_
#define YSOCKET_H_
#include <sys/types.h>
#include <netinet/in.h>
class YSocketListener {
public:
virtual void socketConnected() = 0;
virtual void socketError(int err) = 0;
virtual void socketDataRead(char *buf, int len) = 0;
};
class YSocket {
public:
YSocket();
~YSocket();
int connect(struct sockaddr *server_addr, int addrlen);
int close();
int read(char *buf, int len);
int write(const char *buf, int len);
int handle() { return sockfd; }
void setListener(YSocketListener *l) { fListener = l; }
private:
friend class YApplication;
YSocket *fPrev;
YSocket *fNext;
YSocketListener *fListener;
int sockfd;
bool connecting;
bool reading;
bool registered;
char *rdbuf;
int rdbuflen;
void can_read();
void connected();
};
#endif