mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-03 02:13:35 +02:00
Destroy agent on disconnect; another agent can connect later
This commit is contained in:
parent
cd347a316d
commit
6a3d9b2e4a
3 changed files with 8 additions and 1 deletions
|
@ -12,5 +12,6 @@ connection::senses(int tick_id, char around[4])
|
||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
snprintf(buf, sizeof(buf), "tick %d\naround %c%c%c%c\n\n", tick_id, around[0], around[1], around[2], around[3]);
|
snprintf(buf, sizeof(buf), "tick %d\naround %c%c%c%c\n\n", tick_id, around[0], around[1], around[2], around[3]);
|
||||||
write(fd, buf, strlen(buf));
|
if (write(fd, buf, strlen(buf)) < (ssize_t) strlen(buf))
|
||||||
|
error = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
class connection {
|
class connection {
|
||||||
public:
|
public:
|
||||||
int fd;
|
int fd;
|
||||||
|
bool error;
|
||||||
|
|
||||||
connection(int fd_) : fd(fd_) {}
|
connection(int fd_) : fd(fd_) {}
|
||||||
|
|
||||||
|
|
5
main.cc
5
main.cc
|
@ -47,6 +47,11 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
if (agent) {
|
if (agent) {
|
||||||
agent->on_tick();
|
agent->on_tick();
|
||||||
|
if (agent->conn && agent->conn->error) {
|
||||||
|
delete agent;
|
||||||
|
agent = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
int cfd = accept(lfd, NULL, NULL);
|
int cfd = accept(lfd, NULL, NULL);
|
||||||
if (cfd >= 0) {
|
if (cfd >= 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue