Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
EDAF55
C-camera
Commits
21de6559
Commit
21de6559
authored
Oct 03, 2017
by
Sven Gestegård Robertz
Browse files
http_server comments
parent
c1c32b6e
Changes
1
Hide whitespace changes
Inline
Side-by-side
examples/http_server.c
View file @
21de6559
...
...
@@ -73,6 +73,9 @@ static pthread_cond_t global_cond = PTHREAD_COND_INITIALIZER;
#ifdef USE_CAMERA
/* try to open capture interface.
* returns 0 on success
*/
int
try_open_camera
(
struct
global_state
*
state
)
{
state
->
cam
=
camera_open
();
...
...
@@ -158,6 +161,9 @@ int client_send_frame(struct client* client, frame* fr)
return
result
;
}
/* get frame from camera and send to client
* returns zero on success
*/
int
try_get_frame
(
struct
client
*
client
)
{
int
result
=-
1
;
...
...
@@ -276,12 +282,17 @@ void* serve_client(void *ctxt)
return
(
void
*
)
(
intptr_t
)
close
(
client
->
connfd
);
}
/* signal the global condition variable
*/
void
signal_to_bg_task
()
{
pthread_mutex_lock
(
&
global_mutex
);
pthread_cond_broadcast
(
&
global_cond
);
pthread_mutex_unlock
(
&
global_mutex
);
}
/* set flags to signal shutdown and
* signal global condition variable
*/
void
server_quit
(
struct
global_state
*
s
)
{
printf
(
"Quitting
\n
"
);
...
...
@@ -355,10 +366,11 @@ int try_accept(struct global_state* state, struct client* client)
#ifdef INFO
printf
(
"accepted connection
\n
"
);
#endif
// serve clients in separate thread, for
three
reasons
// serve clients in separate thread, for
four
reasons
// 1. Illustrate threading
// 2. Not blocking the user interface while serving client
// 3. Prepare for serving multiple clients concurrently
// 4. The AXIS software requires capture to be run outside the main thread
if
(
pthread_create
(
&
state
->
client_thread
,
0
,
serve_client
,
client
))
{
printf
(
"Error pthread_create()
\n
"
);
perror
(
"creating"
);
...
...
@@ -509,6 +521,9 @@ int create_socket(struct global_state* state)
return
0
;
}
/* bind state->listenfd to port and listen
* returns 0 on success
*/
int
bind_and_listen
(
struct
global_state
*
state
,
int
port
)
{
struct
sockaddr_in
serv_addr
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment