Connection communication in separate thread

This commit is contained in:
Petr Baudis 2011-11-27 01:24:52 +01:00
parent ec3897b29b
commit 92940b6054
4 changed files with 92 additions and 7 deletions

View file

@ -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