summaryrefslogtreecommitdiff
path: root/src/pso/TSocket.cpp
blob: 0a0166e73b250a96c1bffc8a94fa9cc8f640deeb (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
56
57
58
59
#include <global_types.h>
#include <string.h>
#include "pso/macros.h"
#include "pso/TArray.h"
#include "pso/TObject.h"
#include "pso/TSocket.h"

u16 bswap_word(u16 val);

int TSocket::is_empty() {
	if (all_parents_unqueued_for_destruction()) {
		return !m_size;
	} else {
		return true;
	}
}

const u8 TSocket::next() {
	const u8 val = m_packet_buffer[m_buffer_offset++];
	if (m_buffer_offset >= m_size) {
		m_buffer_offset = 0;
		m_size = 0;
	}
	return val;
}

void TSocket::set_port(u32 port) {
	m_dst_port = bswap_word(port);
}

void TSocket::set_ip_address(u32 addr) {
	m_dst_addr.addr_bytes.fast_copy_reverse<u32>(addr);
}

int TSocket::resolve_domain(char *domain) {
	/* TODO: Implement, and match this. */
	return 0;
}

TSocket::TSocket(TObject *parent) : TObject(parent) {
	m_dst_addr.addr_bytes.fast_fill_with<u8>(0);
	m_dst_port = 0;
	m_src_port = 0;
	m_sock_fd = -1;
	m_sock_flags = 0;
	m_size = 0;
	m_buffer_offset = 0;
	m_buffer_cleared = true;
	m_callback = nullptr;
}

u16 bswap_word(u16 val) {
	u8 *ptr = reinterpret_cast<u8 *>(&val);
	return ptr[1] + (ptr[0] << 8);
}

TSocket::~TSocket() {

}