aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/CMakeLists.txt1
-rw-r--r--client/main.cpp6
-rw-r--r--client/sock.cpp29
-rw-r--r--client/sock.h21
4 files changed, 56 insertions, 1 deletions
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt
index d77b65b..e4990d7 100644
--- a/client/CMakeLists.txt
+++ b/client/CMakeLists.txt
@@ -11,6 +11,7 @@ include(../proto/include.cmake)
add_executable(main
main.cpp
rl.c
+ sock.cpp
)
target_link_libraries(main
diff --git a/client/main.cpp b/client/main.cpp
index 3d3a68c..6aad0e3 100644
--- a/client/main.cpp
+++ b/client/main.cpp
@@ -3,6 +3,7 @@
#include <cstdint>
#include "rl.h"
+#include "sock.h"
int main(int argc, char** argv) {
if (argc < 2) {
@@ -11,10 +12,13 @@ int main(int argc, char** argv) {
}
// parse arguments
- char* addr_str = argv[1];
+ char* addr = argv[1];
uint16_t port = 9191;
if (argc >= 3) port = atoi(argv[2]);
+ // connect to TCP socket (automatically spawns thread)
+ PBSocket sock(addr, port);
+
// enter main CLI (using GNU readline for comfyness)
return cli_main();
}
diff --git a/client/sock.cpp b/client/sock.cpp
new file mode 100644
index 0000000..703ee24
--- /dev/null
+++ b/client/sock.cpp
@@ -0,0 +1,29 @@
+#include <unistd.h>
+#include <cstdio>
+
+#include <thread>
+
+#include "sock.h"
+#include "rl.h"
+
+PBSocket::PBSocket() {
+ printf("Init PBSocket!\n");
+}
+
+PBSocket::PBSocket(char* addr, uint16_t port) : PBSocket() {
+ connect(addr, port);
+}
+
+void PBSocket::connect(char* addr, uint16_t port) {
+ printf("Connect to %s on port %d\n", addr, port);
+
+ this->_thread = std::thread(&PBSocket::sock_task, this);
+}
+
+void PBSocket::sock_task() {
+ while(1) {
+ sleep(3);
+ rl_printf("Testing asynchronous messages in prompt...\n");
+ }
+}
+
diff --git a/client/sock.h b/client/sock.h
new file mode 100644
index 0000000..e3d7ec8
--- /dev/null
+++ b/client/sock.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <cstdint>
+#include <thread>
+
+class PBSocket {
+public:
+ PBSocket(char* addr, uint16_t port);
+
+ void connect(char* addr, uint16_t port);
+
+private:
+ PBSocket();
+
+ void sock_task();
+
+ std::thread _thread;
+
+};
+
+