Skip to content
Snippets Groups Projects
Commit c3355e85 authored by Jake Drahos's avatar Jake Drahos
Browse files

Began adding client buffers

parent 380386f7
No related branches found
No related tags found
No related merge requests found
......@@ -45,6 +45,7 @@ int safe_fd_set(int , fd_set* , int* );
int safe_fd_clr(int , fd_set* , int* );
static void cb(struct ucart_vrpn_TrackerData *);
static int new_client(int fd);
/* Thread-safe wrappers */
pthread_mutex_t quadSocketMutex;
......@@ -58,6 +59,12 @@ static int backendSocket;
struct ucart_vrpn_tracker * tracker = NULL;
const char *logHeader = "";//"#\n#\tDefault log header\n#\tEverything after '#'`s will be printed as is in the processed logs.\n#\n\0";
#define MAX_CLIENTS 32
#define CLIENT_BUFFER_SIZE 1024
static char client_buffers[MAX_CLIENTS][CLIENT_BUFFER_SIZE];
static int client_fds[MAX_CLIENTS];
static size_t num_clients = 0;
pthread_mutex_t quadResponseMutex, cliInputMutex ;
unsigned char *respBuf, *commandBuf;
int newQuadResponse = 0, newCliInput = 0;
......@@ -131,6 +138,13 @@ int main(int argc, char **argv)
/* Add to socket set */
safe_fd_set(backendSocket, &rfds, &max_fd);
/* Initialize client buffers */
for (int i = 0; i < MAX_CLIENTS; i++) {
client_fds[i] = -1;
client_buffers[i][0] = '\n';
}
signal(SIGINT, killHandler);
if (pthread_mutex_lock(&quadSocketMutex)) {
......@@ -222,6 +236,9 @@ int main(int argc, char **argv)
if (new_fd < 0) {
warn("accept");
} else {
if (new_client(fd)) {
safe_fd_set(fd, &rfds, &max_fd);
}
}
}
}
......@@ -406,3 +423,19 @@ static ssize_t writeQuad(const char * buf, size_t count) {
return retval;
}
static int new_client(int fd)
{
if (num_clients >= MAX_CLIENTS) {
close(fd);
return 0;
}
num_clients++;
int new_slot;
for (size_t i = 0; i < MAX_CLIENTS; i++) {
if
}
return 1;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment