diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/pso/TSocket.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/pso/TSocket.cpp b/src/pso/TSocket.cpp new file mode 100644 index 0000000..f9e954d --- /dev/null +++ b/src/pso/TSocket.cpp @@ -0,0 +1,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(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() { + +} |