Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MicroCART
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Distributed Autonomous Networked Control Lab
MicroCART
Commits
c3355e85
Commit
c3355e85
authored
8 years ago
by
Jake Drahos
Browse files
Options
Downloads
Patches
Plain Diff
Began adding client buffers
parent
380386f7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
groundStation/src/microcart_cli.c
+33
-0
33 additions, 0 deletions
groundStation/src/microcart_cli.c
with
33 additions
and
0 deletions
groundStation/src/microcart_cli.c
+
33
−
0
View file @
c3355e85
...
...
@@ -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
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment