summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2023-03-03 15:03:06 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2023-03-03 15:03:06 -0400
commitfd25a2530d126fb51c80c594244f856b46430335 (patch)
tree48b98e6ee9abdc310f0b76acc2a6050160dbb2a4
parent9634309c46742c13cbd198b223fe5301dab53632 (diff)
TTcpSocket: Make most of the virtuals inline
This is to make the function order match better.
-rw-r--r--context.h120
-rw-r--r--include/pso/TTcpSocket.h171
-rw-r--r--src/pso/TTcpSocket.cpp171
3 files changed, 281 insertions, 181 deletions
diff --git a/context.h b/context.h
index 76183b7..dbd1d26 100644
--- a/context.h
+++ b/context.h
@@ -900,19 +900,125 @@ private:
int m_is_encrypted;
public:
WEAK_FUNC TTcpSocket(TObject *parent = nullptr);
- virtual ~TTcpSocket();
- virtual short open() override;
- virtual short close() override;
- virtual void recv() override;
- virtual short send(u8 *data) override;
- virtual int send(u8 *data, size_t size) override;
+ virtual ~TTcpSocket() {
+ close();
+ };
+
+ virtual void recv() {
+ if (sock_fd() != -1) {
+ packet_buffer().fill(0);
+ set_buffer_cleared(true);
+ (int)tcp_receive(sock_fd(), notify, packet_buffer().size(), packet_buffer().data());
+ }
+ };
+
+ virtual int send(u8 *data, size_t size) {
+ if (sock_fd() != -1) {
+ if (!m_is_encrypted) {
+ m_send_crypt.encrypt(data, size);
+ }
+
+ const s8 flags = sock_flags();
+ if (flags || !get_link_status()) {
+ return -1;
+ } else {
+ if (int status = stat()) {
+ log(get_sock_status_name(status));
+ set_flags(1);
+ return 1;
+ } else {
+ if (send_window() <= size) {
+ set_flags(1);
+ return 1;
+ } else {
+ if (stat_val() < 0) {
+ set_flags(1);
+ return 1;
+ } else {
+ struct send_buffs sb;
+ sb.buff = data;
+ sb.len = size;
+ set_unused(0);
+ int ret = tcp_send(sock_fd(), nullptr, 1, &sb);
+ if (ret >= 1 || ret < -1) {
+ set_flags(1);
+ log(get_sock_status_name(ret));
+ close();
+ return ret;
+ }
+ }
+ }
+ }
+ }
+ } else {
+ return -1;
+ }
+ };
+
+ virtual short send(u8 *data) {
+ if (sock_fd() != -1) {
+ const s8 flags = sock_flags();
+ if (flags || !get_link_status()) {
+ return -1;
+ } else {
+ if (short status = stat()) {
+ log(get_sock_status_name(status));
+ set_flags(1);
+ return 1;
+ } else {
+ if (stat_val() < 0) {
+ set_flags(1);
+ return 1;
+ } else {
+ s8 len = strlen(reinterpret_cast<const char *>(data));
+ struct send_buffs sb;
+ sb.buff = data;
+ sb.len = len;
+ if (send_window() <= len) {
+ set_flags(1);
+ return 1;
+ } else {
+ short ret = tcp_send(sock_fd(), nullptr, 1, &sb);
+ if (ret) {
+ close();
+ }
+ return ret;
+ }
+ }
+ }
+ }
+ } else {
+ return -1;
+ }
+ };
+
+ virtual short open();
+ virtual short close();
short stat();
void some_stub();
int test_connection();
- static void notify(short size, short sock_fd);
+ static void notify(short size, short sock_fd) {
+ char tmp_str[64];
+ TTcpSocket *socket = tcp_socket_table[sock_fd];
+
+ if (socket != nullptr) {
+ if (size > 0) {
+ socket->set_buffer_cleared(false);
+ socket->set_size(size);
+ socket->set_buffer_offset(0);
+ sprintf(tmp_str, "Rcv:%d byte", size);
+ socket->log(tmp_str);
+ if (socket->callback() != nullptr) {
+ socket->callback()(socket);
+ }
+ } else {
+ socket->set_flags(1);
+ }
+ }
+ };
PRIVATE_MEMBER_ACCESSORS(PSOV3EncryptionTCP, send_crypt);
PRIVATE_MEMBER_ACCESSORS(PSOV3EncryptionTCP, recv_crypt);
diff --git a/include/pso/TTcpSocket.h b/include/pso/TTcpSocket.h
index b6faf56..314c423 100644
--- a/include/pso/TTcpSocket.h
+++ b/include/pso/TTcpSocket.h
@@ -8,11 +8,62 @@
#include <pso/PSOV3EncryptionTCP.h>
#include <pso/TArray.h>
#include <pso/TSocket.h>
+#include <pso/TMainTask.h>
#include <pso/TObject.h>
EXTERN_OBJECT_NAME(TTcpSocket);
extern TTcpSocket *tcp_socket_table[16];
+struct at_ip4_opt {
+ u8 ttl;
+ u8 svctype;
+ u8 df_flag;
+};
+
+struct at_ip6_opt {
+ u8 traffic_class;
+ u32 flow_label;
+ u8 hop_limit;
+};
+
+struct at_ip_option {
+ u32 type;
+ union {
+ struct at_ip6_opt ip6;
+ struct at_ip4_opt ip4;
+ } ip46;
+};
+
+struct at_ip_addr {
+ u32 type;
+ union {
+ u8 ip6[16];
+ u32 ip4;
+ } ip46;
+};
+
+struct send_buffs {
+ short len;
+ u8 *buff;
+};
+
+extern void func_80019aa0();
+extern void controller_stuff();
+extern char func_801a5d1c();
+extern void render_tick();
+extern void func_803d96a4();
+extern short tcp_abort(short nh);
+extern short tcp_bind(short nh, struct at_ip_addr *addr, u16 port);
+extern short tcp_connect(short nh, struct at_ip_addr *addr, u16 port, struct at_ip_option *option);
+extern short tcp_create();
+extern short tcp_delete(short nh);
+extern short tcp_get_opt(short nh, short type, u32 *opt);
+extern short tcp_send(short nh, void (*notify)(short size, short sock_fd), char bufnum, struct send_buffs *sb);
+extern short tcp_stat(short nh, short *stat, short *backlog, u32 *sendwin, u32 *recvwin);
+extern short tcp_receive(short nh, void (*notify)(short size, short sock_fd), short len, u8 *buf);
+extern int get_link_status();
+extern char *get_sock_status_name(short code);
+
class TTcpSocket : public TSocket {
private:
PSOV3EncryptionTCP m_send_crypt;
@@ -20,19 +71,125 @@ private:
int m_is_encrypted;
public:
WEAK_FUNC TTcpSocket(TObject *parent = nullptr);
- virtual ~TTcpSocket();
- virtual short open() override;
- virtual short close() override;
- virtual void recv() override;
- virtual short send(u8 *data) override;
- virtual int send(u8 *data, size_t size) override;
+ virtual ~TTcpSocket() {
+ close();
+ };
+
+ virtual void recv() {
+ if (sock_fd() != -1) {
+ packet_buffer().fill(0);
+ set_buffer_cleared(true);
+ (int)tcp_receive(sock_fd(), notify, packet_buffer().size(), packet_buffer().data());
+ }
+ };
+
+ virtual int send(u8 *data, size_t size) {
+ if (sock_fd() != -1) {
+ if (!m_is_encrypted) {
+ m_send_crypt.encrypt(data, size);
+ }
+
+ const s8 flags = sock_flags();
+ if (flags || !get_link_status()) {
+ return -1;
+ } else {
+ if (int status = stat()) {
+ log(get_sock_status_name(status));
+ set_flags(1);
+ return 1;
+ } else {
+ if (send_window() <= size) {
+ set_flags(1);
+ return 1;
+ } else {
+ if (stat_val() < 0) {
+ set_flags(1);
+ return 1;
+ } else {
+ struct send_buffs sb;
+ sb.buff = data;
+ sb.len = size;
+ set_unused(0);
+ int ret = tcp_send(sock_fd(), nullptr, 1, &sb);
+ if (ret >= 1 || ret < -1) {
+ set_flags(1);
+ log(get_sock_status_name(ret));
+ close();
+ return ret;
+ }
+ }
+ }
+ }
+ }
+ } else {
+ return -1;
+ }
+ };
+
+ virtual short send(u8 *data) {
+ if (sock_fd() != -1) {
+ const s8 flags = sock_flags();
+ if (flags || !get_link_status()) {
+ return -1;
+ } else {
+ if (short status = stat()) {
+ log(get_sock_status_name(status));
+ set_flags(1);
+ return 1;
+ } else {
+ if (stat_val() < 0) {
+ set_flags(1);
+ return 1;
+ } else {
+ s8 len = strlen(reinterpret_cast<const char *>(data));
+ struct send_buffs sb;
+ sb.buff = data;
+ sb.len = len;
+ if (send_window() <= len) {
+ set_flags(1);
+ return 1;
+ } else {
+ short ret = tcp_send(sock_fd(), nullptr, 1, &sb);
+ if (ret) {
+ close();
+ }
+ return ret;
+ }
+ }
+ }
+ }
+ } else {
+ return -1;
+ }
+ };
+
+ virtual short open();
+ virtual short close();
short stat();
void some_stub();
int test_connection();
- static void notify(short size, short sock_fd);
+ static void notify(short size, short sock_fd) {
+ char tmp_str[64];
+ TTcpSocket *socket = tcp_socket_table[sock_fd];
+
+ if (socket != nullptr) {
+ if (size > 0) {
+ socket->set_buffer_cleared(false);
+ socket->set_size(size);
+ socket->set_buffer_offset(0);
+ sprintf(tmp_str, "Rcv:%d byte", size);
+ socket->log(tmp_str);
+ if (socket->callback() != nullptr) {
+ socket->callback()(socket);
+ }
+ } else {
+ socket->set_flags(1);
+ }
+ }
+ };
PRIVATE_MEMBER_ACCESSORS(PSOV3EncryptionTCP, send_crypt);
PRIVATE_MEMBER_ACCESSORS(PSOV3EncryptionTCP, recv_crypt);
diff --git a/src/pso/TTcpSocket.cpp b/src/pso/TTcpSocket.cpp
index 7244ad6..d5151a2 100644
--- a/src/pso/TTcpSocket.cpp
+++ b/src/pso/TTcpSocket.cpp
@@ -11,173 +11,6 @@
OBJECT_NAME(TTcpSocket);
TTcpSocket *tcp_socket_table[16] = {nullptr};
-struct at_ip4_opt {
- u8 ttl;
- u8 svctype;
- u8 df_flag;
-};
-
-struct at_ip6_opt {
- u8 traffic_class;
- u32 flow_label;
- u8 hop_limit;
-};
-
-struct at_ip_option {
- u32 type;
- union {
- struct at_ip6_opt ip6;
- struct at_ip4_opt ip4;
- } ip46;
-};
-
-struct at_ip_addr {
- u32 type;
- union {
- u8 ip6[16];
- u32 ip4;
- } ip46;
-};
-
-struct send_buffs {
- short len;
- u8 *buff;
-};
-
-void func_80019aa0();
-void controller_stuff();
-char func_801a5d1c();
-void render_tick();
-void func_803d96a4();
-short tcp_abort(short nh);
-short tcp_bind(short nh, struct at_ip_addr *addr, u16 port);
-short tcp_connect(short nh, struct at_ip_addr *addr, u16 port, struct at_ip_option *option);
-short tcp_create();
-short tcp_delete(short nh);
-short tcp_get_opt(short nh, short type, u32 *opt);
-short tcp_send(short nh, void (*notify)(short size, short sock_fd), char bufnum, struct send_buffs *sb);
-short tcp_stat(short nh, short *stat, short *backlog, u32 *sendwin, u32 *recvwin);
-short tcp_receive(short nh, void (*notify)(short size, short sock_fd), short len, u8 *buf);
-int get_link_status();
-char *get_sock_status_name(short code);
-
-
-WEAK_FUNC TTcpSocket::TTcpSocket(TObject *parent) : TSocket(parent) {
- set_name(TTcpSocket_name);
-}
-
-TTcpSocket::~TTcpSocket() {
- close();
-}
-
-void TTcpSocket::recv() {
- if (sock_fd() != -1) {
- packet_buffer().fill(0);
- set_buffer_cleared(true);
- (int)tcp_receive(sock_fd(), notify, packet_buffer().size(), packet_buffer().data());
- }
-}
-
-void TTcpSocket::notify(short size, short sock_fd) {
- char tmp_str[64];
- TTcpSocket *socket = tcp_socket_table[sock_fd];
-
- if (socket != nullptr) {
- if (size > 0) {
- socket->set_buffer_cleared(false);
- socket->set_size(size);
- socket->set_buffer_offset(0);
- sprintf(tmp_str, "Rcv:%d byte", size);
- socket->log(tmp_str);
- if (socket->callback() != nullptr) {
- socket->callback()(socket);
- }
- } else {
- socket->set_flags(1);
- }
- }
-}
-
-int TTcpSocket::send(u8 *data, size_t size) {
- if (sock_fd() != -1) {
- if (!m_is_encrypted) {
- m_send_crypt.encrypt(data, size);
- }
-
- const s8 flags = sock_flags();
- if (flags || !get_link_status()) {
- return -1;
- } else {
- if (int status = stat()) {
- log(get_sock_status_name(status));
- set_flags(1);
- return 1;
- } else {
- if (send_window() <= size) {
- set_flags(1);
- return 1;
- } else {
- if (stat_val() < 0) {
- set_flags(1);
- return 1;
- } else {
- struct send_buffs sb;
- sb.buff = data;
- sb.len = size;
- set_unused(0);
- int ret = tcp_send(sock_fd(), nullptr, 1, &sb);
- if (ret >= 1 || ret < -1) {
- set_flags(1);
- log(get_sock_status_name(ret));
- close();
- return ret;
- }
- }
- }
- }
- }
- } else {
- return -1;
- }
-}
-
-short TTcpSocket::send(u8 *data) {
- if (sock_fd() != -1) {
- const s8 flags = sock_flags();
- if (flags || !get_link_status()) {
- return -1;
- } else {
- if (short status = stat()) {
- log(get_sock_status_name(status));
- set_flags(1);
- return 1;
- } else {
- if (stat_val() < 0) {
- set_flags(1);
- return 1;
- } else {
- s8 len = strlen(reinterpret_cast<const char *>(data));
- struct send_buffs sb;
- sb.buff = data;
- sb.len = len;
- if (send_window() <= len) {
- set_flags(1);
- return 1;
- } else {
- short ret = tcp_send(sock_fd(), nullptr, 1, &sb);
- if (ret) {
- close();
- }
- return ret;
- }
- }
- }
- }
- } else {
- return -1;
- }
-}
-
int TTcpSocket::test_connection() {
for (int i = 0; i < 1800; ++i) {
if (int status = stat()) {
@@ -304,6 +137,10 @@ short TTcpSocket::open() {
}
}
+WEAK_FUNC TTcpSocket::TTcpSocket(TObject *parent) : TSocket(parent) {
+ set_name(TTcpSocket_name);
+}
+
void func_80019aa0() {}
void controller_stuff() {}
char func_801a5d1c() {}