fix: tcp server not listening to clients
This commit is contained in:
+16
-6
@@ -293,12 +293,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void connect(runnable callback) override {
|
||||
thread = std::make_unique<std::thread>([this, callback]() {
|
||||
connectSocket();
|
||||
if (state == ConnectionState::CONNECTED) {
|
||||
callback();
|
||||
}
|
||||
void startListen() {
|
||||
while (state == ConnectionState::CONNECTED) {
|
||||
int size = recvsocket(descriptor, buffer.data(), buffer.size());
|
||||
if (size == 0) {
|
||||
@@ -324,6 +319,20 @@ public:
|
||||
}
|
||||
logger.info() << "read " << size << " bytes from " << to_string(addr);
|
||||
}
|
||||
}
|
||||
|
||||
void startClient() {
|
||||
state = ConnectionState::CONNECTED;
|
||||
thread = std::make_unique<std::thread>([this]() { startListen();});
|
||||
}
|
||||
|
||||
void connect(runnable callback) override {
|
||||
thread = std::make_unique<std::thread>([this, callback]() {
|
||||
connectSocket();
|
||||
if (state == ConnectionState::CONNECTED) {
|
||||
callback();
|
||||
}
|
||||
startListen();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -459,6 +468,7 @@ public:
|
||||
auto socket = std::make_shared<SocketConnection>(
|
||||
clientDescriptor, address
|
||||
);
|
||||
socket->startClient();
|
||||
u64id_t id = network->addConnection(socket);
|
||||
{
|
||||
std::lock_guard lock(clientsMutex);
|
||||
|
||||
Reference in New Issue
Block a user