norm :25lines
This commit is contained in:
parent
53cd982d55
commit
1c6b660be0
52
client.c
52
client.c
@ -6,62 +6,18 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||||
/* Created: 2024/07/18 16:28:03 by whaffman #+#+# #+#+# #+# #+# | */
|
/* Created: 2024/07/18 16:28:03 by whaffman #+#+# #+#+# #+# #+# | */
|
||||||
/* Updated: 2024/07/27 14:43:17 by whaffman ### ### ### ### / \ */
|
/* Updated: 2024/07/27 18:40:57 by whaffman ### ### ### ### / \ */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#define SLEEP 100
|
#include "libft/libft.h"
|
||||||
|
|
||||||
|
#define SLEEP 300
|
||||||
|
|
||||||
static volatile int g_ack = 0;
|
static volatile int g_ack = 0;
|
||||||
|
|
||||||
size_t ft_strlen(const char *s)
|
|
||||||
{
|
|
||||||
size_t length;
|
|
||||||
|
|
||||||
length = 0;
|
|
||||||
while (*s++)
|
|
||||||
length++;
|
|
||||||
return (length);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_putstr(char *str)
|
|
||||||
{
|
|
||||||
write(1, str, ft_strlen(str));
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_isspace(int c)
|
|
||||||
{
|
|
||||||
return (' ' == c || '\f' == c || '\n' == c
|
|
||||||
|| '\r' == c || '\t' == c || '\v' == c);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_isdigit(char c)
|
|
||||||
{
|
|
||||||
return (c >= '0' && c <= '9');
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_atoi(const char *nptr)
|
|
||||||
{
|
|
||||||
int sign;
|
|
||||||
int res;
|
|
||||||
|
|
||||||
while (ft_isspace(*nptr))
|
|
||||||
nptr++;
|
|
||||||
res = 0;
|
|
||||||
sign = 1;
|
|
||||||
while (*nptr == '-' || *nptr == '+')
|
|
||||||
{
|
|
||||||
if (*nptr == '-')
|
|
||||||
sign *= -1;
|
|
||||||
nptr++;
|
|
||||||
}
|
|
||||||
while (ft_isdigit(*nptr))
|
|
||||||
res = 10 * res + sign * (*nptr++ - '0');
|
|
||||||
return (res);
|
|
||||||
}
|
|
||||||
|
|
||||||
int send_byte(int pid, unsigned char c)
|
int send_byte(int pid, unsigned char c)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|||||||
13
server.c
13
server.c
@ -6,14 +6,14 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||||
/* Created: 2024/07/18 17:24:54 by whaffman #+#+# #+#+# #+# #+# | */
|
/* Created: 2024/07/18 17:24:54 by whaffman #+#+# #+#+# #+# #+# | */
|
||||||
/* Updated: 2024/07/27 15:04:43 by whaffman ### ### ### ### / \ */
|
/* Updated: 2024/07/27 18:23:52 by whaffman ### ### ### ### / \ */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "libft.h"
|
#include "libft/libft.h"
|
||||||
|
|
||||||
void signal_handler(int signum, siginfo_t *info, void *context)
|
void signal_handler(int signum, siginfo_t *info, void *context)
|
||||||
{
|
{
|
||||||
@ -28,10 +28,9 @@ void signal_handler(int signum, siginfo_t *info, void *context)
|
|||||||
c = '\0';
|
c = '\0';
|
||||||
client_pid = info->si_pid;
|
client_pid = info->si_pid;
|
||||||
}
|
}
|
||||||
c = c << 1;
|
|
||||||
if (signum == SIGUSR1)
|
|
||||||
c |= 1;
|
|
||||||
count++;
|
count++;
|
||||||
|
if (signum == SIGUSR1)
|
||||||
|
c |= 1 << (8 - count);
|
||||||
if (count == 8)
|
if (count == 8)
|
||||||
{
|
{
|
||||||
if (c)
|
if (c)
|
||||||
@ -49,7 +48,9 @@ int main(void)
|
|||||||
{
|
{
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
|
|
||||||
printf("MiniTalk Server started on pid: %d\n", getpid());
|
ft_putstr("MiniTalk Server started on pid: ");
|
||||||
|
ft_putnbr(getpid());
|
||||||
|
ft_putstr("\n");
|
||||||
sa.sa_sigaction = signal_handler;
|
sa.sa_sigaction = signal_handler;
|
||||||
sigemptyset(&sa.sa_mask);
|
sigemptyset(&sa.sa_mask);
|
||||||
sa.sa_flags = SA_SIGINFO;
|
sa.sa_flags = SA_SIGINFO;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user