mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-02 09:53:38 +02:00
Connection communication in separate thread
This commit is contained in:
parent
ec3897b29b
commit
92940b6054
4 changed files with 92 additions and 7 deletions
22
connection.h
22
connection.h
|
@ -1,6 +1,9 @@
|
|||
#ifndef BRMLIFE__CONNECTION_H
|
||||
#define BRMLIFE__CONNECTION_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "map.h"
|
||||
|
@ -10,7 +13,11 @@ public:
|
|||
int fd;
|
||||
bool error;
|
||||
|
||||
connection(int fd_) : fd(fd_) {}
|
||||
connection(int fd_)
|
||||
: fd(fd_), error(false)
|
||||
{
|
||||
spawn_thread();
|
||||
}
|
||||
|
||||
~connection()
|
||||
{
|
||||
|
@ -18,6 +25,19 @@ public:
|
|||
}
|
||||
|
||||
void senses(int tick_id, char around[4]);
|
||||
|
||||
void cancel(void);
|
||||
|
||||
private:
|
||||
std::string out_buf;
|
||||
pthread_mutex_t buf_lock;
|
||||
|
||||
pthread_cond_t cancel_cond;
|
||||
pthread_mutex_t cancel_lock;
|
||||
|
||||
void spawn_thread(void);
|
||||
friend void *conn_thread_worker(void *ctx);
|
||||
void thread_loop(void);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue