Bon code !
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
Minitalk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
42cursus-cestoliv
Minitalk
Merge requests
!2
Whithout sleep
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Whithout sleep
whithout-sleep
into
main
Overview
0
Commits
4
Pipelines
0
Changes
2
Merged
Olivier Cartier
requested to merge
whithout-sleep
into
main
3 years ago
Overview
0
Commits
4
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
b411cb52
4 commits,
3 years ago
2 files
+
45
−
29
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
src/client.c
+
44
−
28
Options
@@ -6,54 +6,70 @@
/* By: ocartier <ocartier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/12 09:24:25 by ocartier #+# #+# */
/* Updated: 2022/01/25 10:4
5:55
by ocartier ### ########lyon.fr */
/* Updated: 2022/01/25 10:4
9:16
by ocartier ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include
"../include/minitalk.h"
int
g_bit_control
;
void
send_char
(
char
c
,
pid_t
pid
)
int
send_char
(
char
p_c
,
pid_t
p_pid
)
{
int
bit
;
static
int
bit
=
-
1
;
static
char
c
;
static
pid_t
pid
;
bit
=
__CHAR_BIT__
*
sizeof
(
c
)
-
1
;
while
(
bit
>=
0
)
if
(
p_pid
)
{
if
(
kill
(
pid
,
0
)
<
0
)
{
ft_printf
(
"ERROR : cant send sig to pid : %d
\n
"
,
pid
);
exit
(
EXIT_FAILURE
);
}
g_bit_control
=
0
;
if
(
c
&
(
1
<<
bit
))
kill
(
pid
,
SIGUSR1
);
else
kill
(
pid
,
SIGUSR2
);
bit
--
;
while
(
g_bit_control
!=
1
)
usleep
(
10
);
c
=
p_c
;
pid
=
p_pid
;
}
if
(
bit
<
0
)
bit
=
__CHAR_BIT__
*
sizeof
(
c
)
-
1
;
if
(
kill
(
pid
,
0
)
<
0
)
{
ft_printf
(
"ERROR : cant send sig to pid : %d
\n
"
,
pid
);
exit
(
EXIT_FAILURE
);
}
if
(
c
&
(
1
<<
bit
))
kill
(
pid
,
SIGUSR1
);
else
kill
(
pid
,
SIGUSR2
);
bit
--
;
return
(
bit
);
}
void
send_str
(
char
*
str
,
pid_t
pid
)
void
send_str
(
char
*
p_
str
,
pid_t
p_
pid
)
{
int
cur
;
static
int
cur
=
0
;
static
char
*
str
;
static
pid_t
pid
;
static
int
bit
=
-
1
;
cur
=
0
;
while
(
str
[
cur
])
if
(
p_pid
)
{
str
=
p_str
;
pid
=
p_pid
;
}
if
(
bit
<
0
)
{
if
(
str
[
cur
])
{
bit
=
send_char
(
str
[
cur
],
pid
);
cur
++
;
}
else
bit
=
send_char
(
0
,
pid
);
}
else
{
send_char
(
str
[
cur
],
pid
);
cur
++
;
bit
=
send_char
(
0
,
0
);
}
send_char
(
0
,
pid
);
}
void
sig_usr
(
int
sig
)
{
if
(
sig
==
SIGUSR1
)
g_bit_control
=
1
;
send_str
(
""
,
0
)
;
else
if
(
sig
==
SIGUSR2
)
exit
(
EXIT_SUCCESS
);
}
Loading