Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tp1-ProgDev-mertens-guilherme
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Mertens De Andrade Guilherme
tp1-ProgDev-mertens-guilherme
Commits
bf7622a5
Commit
bf7622a5
authored
5 months ago
by
Mertens De Andrade Guilherme
Browse files
Options
Downloads
Patches
Plain Diff
client
parent
cc1f87fc
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
client_5.c
+64
-0
64 additions, 0 deletions
client_5.c
with
64 additions
and
0 deletions
client_5.c
0 → 100644
+
64
−
0
View file @
bf7622a5
#include
<iostream>
#include
<csignal>
#include
<cstdlib>
#include
<fcntl.h>
#include
<unistd.h>
#include
<sys/stat.h>
volatile
bool
running
=
true
;
void
handle_signal
(
int
signal_number
)
{
std
::
cout
<<
"Client received signal: "
<<
signal_number
<<
std
::
endl
;
running
=
false
;
}
int
main
()
{
// Signal handling
struct
sigaction
sa
;
sa
.
sa_handler
=
handle_signal
;
sa
.
sa_flags
=
0
;
sigemptyset
(
&
sa
.
sa_mask
);
if
(
sigaction
(
SIGINT
,
&
sa
,
nullptr
)
==
-
1
||
sigaction
(
SIGTERM
,
&
sa
,
nullptr
)
==
-
1
)
{
perror
(
"Failed to set signal handler"
);
exit
(
EXIT_FAILURE
);
}
const
char
*
fifo_path
=
"my_fifo"
;
// Open FIFO for reading
int
fd
=
open
(
fifo_path
,
O_RDONLY
);
if
(
fd
==
-
1
)
{
perror
(
"Client failed to open FIFO for reading"
);
exit
(
EXIT_FAILURE
);
}
int
number
;
while
(
running
)
{
// Read numbers from FIFO
if
(
read
(
fd
,
&
number
,
sizeof
(
number
))
>
0
)
{
std
::
cout
<<
"Client received: "
<<
number
<<
std
::
endl
;
}
else
{
perror
(
"Failed to read from FIFO"
);
running
=
false
;
}
sleep
(
1
);
}
close
(
fd
);
std
::
cout
<<
"Client exiting..."
<<
std
::
endl
;
return
0
;
}
/*
Client received: 49
Client received: 50
Client received: 51
Client received: 52
Client received: 53
Client received: 54
Client received: 55
Client received: 56
Client received: 57
*/
\ No newline at end of file
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