result->fd = fd;
strcpy(result->addr, addr);
+ result->flags = 0;
result->rtr_version = -1;
result->session = -1;
result->start = result->buffer;
result->end = result->buffer;
- result->claimed = false;
TAILQ_INIT(&result->requests);
result->reqcount = 0;
- result->eos = false;
-
return result;
}
struct rtr_request;
+#define PSF_POLLIN (1 << 0) /* needs to be claimed? */
+#define PSF_CLAIMED (1 << 1) /* thread currently handling requests? */
+#define PSF_EOS (1 << 2) /* end of (input) stream? */
+
+#define PS_POLLIN(s) ((s)->flags & PSF_POLLIN)
+#define PS_CLAIMED(s) ((s)->flags & PSF_CLAIMED)
+#define PS_EOS(s) ((s)->flags & PSF_EOS)
+
+#define PS_ENABLE(s, f) (s)->flags |= PSF_##f
+#define PS_DISABLE(s, f) (s)->flags &= ~PSF_##f
+
struct pdu_stream { /* It's an *input* stream. */
int fd;
char addr[INET6_ADDRSTRLEN]; /* Printable address of the client. */
+ int flags;
int rtr_version; /* -1: unset; > 0: version number */
int session; /* -1: unset; > 0: session */
unsigned char *start;
unsigned char *end;
- bool claimed;
TAILQ_HEAD(, rtr_request) requests; /* No more than 4 nodes */
unsigned int reqcount;
-
- bool eos; /* end of (input) stream */
};
struct rtr_request {
ARRAYLIST_FOREACH(&clients, _client) {
client = *_client;
- if (!TAILQ_EMPTY(&client->requests) && !client->claimed) {
- client->claimed = true;
+ if (!TAILQ_EMPTY(&client->requests) && !PS_CLAIMED(client)) {
+ PS_ENABLE(client, CLAIMED);
return client;
}
}
mutex_lock(&lock);
}
- client->claimed = false;
+ PS_DISABLE(client, CLAIMED);
}
mutex_unlock(&lock);
/* PR_DEBUG_MSG("pfd:%d client:%d", pfd->fd, client->fd); */
- if (!client->claimed && client->eos) {
+ if (!PS_CLAIMED(client) && PS_EOS(client)) {
pdustream_destroy(client);
clients.array[i] = NULL;
}
pr_op_warn("Can't shut down read end of client socket: %s",
strerror(errno));
pdustream_clear_requests(stream);
- stream->eos = true;
+ PS_ENABLE(stream, EOS);
}
static enum poll_verdict
ARRAYLIST_FOREACH_IDX(&clients, i)
init_pollfd(
&pollfds[servers.len + i],
- clients.array[i]->eos ? -1 : clients.array[i]->fd
+ PS_EOS(clients.array[i]) ? -1 : clients.array[i]->fd
);
error = poll(pollfds, servers.len + clients.len, 1000);