Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MicroCART_17-18
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
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
bbartels
MicroCART_17-18
Commits
6ffc61dc
Unverified
Commit
6ffc61dc
authored
8 years ago
by
Jake Drahos
Browse files
Options
Downloads
Patches
Plain Diff
Finished new client
parent
15b9feb1
No related branches found
Branches containing commit
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
+36
-8
36 additions, 8 deletions
groundStation/src/microcart_cli.c
with
36 additions
and
8 deletions
groundStation/src/microcart_cli.c
+
36
−
8
View file @
6ffc61dc
...
...
@@ -46,6 +46,10 @@ int safe_fd_clr(int , fd_set* , int* );
static
void
cb
(
struct
ucart_vrpn_TrackerData
*
);
static
int
new_client
(
int
fd
);
/* Return index of client, or -1 */
static
ssize_t
get_client_index
(
int
fd
);
/* Returns pointer to client buffer, or -1 */
static
char
*
get_client_buffer
(
int
fd
);
/* Thread-safe wrappers */
pthread_mutex_t
quadSocketMutex
;
...
...
@@ -63,7 +67,6 @@ const char *logHeader = "";//"#\n#\tDefault log header\n#\tEverything after '#'`
#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
;
...
...
@@ -426,16 +429,41 @@ static ssize_t writeQuad(const char * buf, size_t count) {
static
int
new_client
(
int
fd
)
{
if
(
num_clients
>=
MAX_CLIENTS
)
{
close
(
fd
);
ssize_t
new_slot
=
-
1
;
for
(
ssize_t
i
=
0
;
i
<
MAX_CLIENTS
;
i
++
)
{
if
(
client_fds
[
i
]
<
0
)
{
new_slot
=
i
;
break
;
}
}
if
(
new_slot
==
-
1
)
{
warnx
(
"Ran out of room! Consider increasing MAX_CLIENTS!"
);
return
0
;
}
num_clients
++
;
int
new_slot
;
for
(
size_t
i
=
0
;
i
<
MAX_CLIENTS
;
i
++
)
{
if
}
client_fds
[
new_slot
]
=
fd
;
client_buffers
[
new_slot
][
0
]
=
'\0'
;
return
1
;
}
static
ssize_t
get_client_index
(
int
fd
)
{
for
(
ssize_t
i
=
0
;
i
<
MAX_CLIENTS
;
i
++
)
{
if
(
client_fds
[
i
]
==
fd
)
{
return
i
;
}
}
return
-
1
;
}
static
char
*
get_client_buffer
(
int
fd
)
{
ssize_t
slot
=
get_client_index
(
fd
);
if
(
slot
==
-
1
)
{
return
NULL
;
}
else
{
return
client_buffers
[
slot
];
}
}
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