summaryrefslogtreecommitdiff
path: root/include/pso/TSocket.h
blob: 9ffaf9fb6687e6ee0d9fcf16cb2b17b6d4025687 (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
#ifndef TSOCKET_H
#define TSOCKET_H

#include <global_types.h>
#include <string.h>
#include <pso/macros.h>
#include <pso/forward.h>
#include <pso/TObject.h>

union ipv4_addr {
	u32 addr;
	u8 addr_bytes[4];
};

extern u16 to_be_uint16_t(u16 val);
extern u16 to_le_uint16_t(u16 val);

class TSocket : public TObject {
public:
	ipv4_addr m_dst_addr;
	u16 m_dst_port;
	u16 m_src_port;
	ipv4_addr m_src_addr;
	s16 m_sock_fd;
	char m_is_invalid_packet;
	char m_buffer_cleared;
	s16 m_size;
	s16 m_buffer_offset;
	u32 m_unused;
	u8 m_unused2[64];
	u8 m_packet_buffer[2048];
	s16 m_stat_val;
	u16 m_unused3;
	u32 m_send_window;
	u32 m_recv_window;
	void (*m_callback)(TSocket *socket);
public:
	TSocket(TObject *parent);
	virtual ~TSocket();

	virtual int open() = 0;
	virtual short close() = 0;
	virtual void recv() = 0;
	virtual short send(u8 *data) = 0;
	virtual short send(u8 *data, size_t size) = 0;

	int resolve_domain(char *domain);
	void set_ip_address(u32 addr);
	void set_port(u32 port);
	const u8 next();
	int is_empty();
};

#endif