some client side improvements, started to use readline(3)
This commit is contained in:
parent
92daf7c8a6
commit
2772d8d0b3
5 changed files with 56 additions and 21 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
||||||
# Updated: 2017/04/03 16:12:06 by jhalford ### ########.fr #
|
# Updated: 2017/04/03 18:19:23 by jhalford ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -24,8 +24,6 @@ LIBFT_DIR = libft/
|
||||||
LIBFT_LIB = $(LIBFT_DIR)libft.a
|
LIBFT_LIB = $(LIBFT_DIR)libft.a
|
||||||
LIBFT_INC = $(LIBFT_DIR)includes/
|
LIBFT_INC = $(LIBFT_DIR)includes/
|
||||||
|
|
||||||
LIBS =
|
|
||||||
|
|
||||||
SRC_DIR = srcs/
|
SRC_DIR = srcs/
|
||||||
INC_DIR = includes/
|
INC_DIR = includes/
|
||||||
OBJ_DIR = objs/
|
OBJ_DIR = objs/
|
||||||
|
|
@ -54,14 +52,14 @@ server: $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) $(SERVER_OBJ)
|
||||||
@$(CC) $(OBJS) -o $@ \
|
@$(CC) $(OBJS) -o $@ \
|
||||||
-I $(INC_DIR) \
|
-I $(INC_DIR) \
|
||||||
-I $(LIBFT_INC) \
|
-I $(LIBFT_INC) \
|
||||||
$(LIBS) $(LIBFT_LIB) $(SERVER_OBJ) $(FLAGS)
|
$(LIBFT_LIB) $(SERVER_OBJ) $(FLAGS)
|
||||||
@printf "\r\033[38;5;117m✓ MAKE $@ \033[0m\033[K\n"
|
@printf "\r\033[38;5;117m✓ MAKE $@ \033[0m\033[K\n"
|
||||||
|
|
||||||
client: $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) $(CLIENT_OBJ)
|
client: $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) $(CLIENT_OBJ)
|
||||||
@$(CC) $(OBJS) -o $@ \
|
@$(CC) $(OBJS) -o $@ \
|
||||||
-I $(INC_DIR) \
|
-I $(INC_DIR) \
|
||||||
-I $(LIBFT_INC) \
|
-I $(LIBFT_INC) \
|
||||||
$(LIBS) $(LIBFT_LIB) $(CLIENT_OBJ) $(FLAGS)
|
-lreadline $(LIBFT_LIB) $(CLIENT_OBJ) $(FLAGS)
|
||||||
@printf "\r\033[38;5;117m✓ MAKE $@ \033[0m\033[K\n"
|
@printf "\r\033[38;5;117m✓ MAKE $@ \033[0m\033[K\n"
|
||||||
|
|
||||||
$(LIBFT_LIB):
|
$(LIBFT_LIB):
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/04/02 19:18:58 by jhalford #+# #+# */
|
/* Created: 2017/04/02 19:18:58 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/04/03 17:12:59 by jhalford ### ########.fr */
|
/* Updated: 2017/04/03 18:42:28 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,13 +16,19 @@
|
||||||
# define FTP_SERVER_USAGE "%s <port>"
|
# define FTP_SERVER_USAGE "%s <port>"
|
||||||
# define FTP_CLIENT_USAGE "%s <addr> <port>"
|
# define FTP_CLIENT_USAGE "%s <addr> <port>"
|
||||||
# define FTP_BUF 1024
|
# define FTP_BUF 1024
|
||||||
|
# define FTP_READ_BUF 1024
|
||||||
# define FTP_REPLY_BUF 1024
|
# define FTP_REPLY_BUF 1024
|
||||||
|
|
||||||
#include "libft.h"
|
# include "libft.h"
|
||||||
#include "sys/socket.h"
|
# include <sys/socket.h>
|
||||||
#include "netdb.h"
|
# include <netdb.h>
|
||||||
#include "netinet/in.h"
|
# include <netinet/in.h>
|
||||||
#include "arpa/inet.h"
|
# include <arpa/inet.h>
|
||||||
|
|
||||||
|
# include <signal.h>
|
||||||
|
|
||||||
|
# include <stdio.h>
|
||||||
|
# include <readline/readline.h>
|
||||||
|
|
||||||
typedef struct s_ftp_reply t_ftp_reply;
|
typedef struct s_ftp_reply t_ftp_reply;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,12 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/04/02 19:18:31 by jhalford #+# #+# */
|
/* Created: 2017/04/02 19:18:31 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/04/03 17:20:42 by jhalford ### ########.fr */
|
/* Updated: 2017/04/03 18:43:40 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_p.h"
|
#include "ft_p.h"
|
||||||
|
|
||||||
#define FTP_CLIENT_USAGE "%s <addr> <port>"
|
|
||||||
|
|
||||||
int create_client(char *addr, int port)
|
int create_client(char *addr, int port)
|
||||||
{
|
{
|
||||||
int sock;
|
int sock;
|
||||||
|
|
@ -31,11 +29,25 @@ int create_client(char *addr, int port)
|
||||||
return (sock);
|
return (sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sigint_nl(int signo)
|
||||||
|
{
|
||||||
|
(void)signo;
|
||||||
|
ft_putchar('\n');
|
||||||
|
signal(SIGINT, SIG_DFL);
|
||||||
|
kill(SIGINT, getpid());
|
||||||
|
}
|
||||||
|
|
||||||
int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
{
|
{
|
||||||
int port;
|
int port;
|
||||||
int sock;
|
int sock;
|
||||||
|
char buf[FTP_READ_BUF];
|
||||||
|
char *input;
|
||||||
|
pid_t pid;
|
||||||
|
pid_t client_pid;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
client_pid = getpid();
|
||||||
if (ac != 3)
|
if (ac != 3)
|
||||||
ft_usage(FTP_CLIENT_USAGE, av[0]);
|
ft_usage(FTP_CLIENT_USAGE, av[0]);
|
||||||
port = ft_atoi(av[2]);
|
port = ft_atoi(av[2]);
|
||||||
|
|
@ -44,10 +56,29 @@ int main(int ac, char **av)
|
||||||
perror(av[0]);
|
perror(av[0]);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
signal(SIGINT, SIG_IGN);
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
ft_readline();
|
if ((pid = fork()) < 0)
|
||||||
write(sock, "bonjour\n", 8);
|
exit(1);
|
||||||
|
if (pid == 0)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sigint_nl);
|
||||||
|
if (!(input = readline("ft_p> ")))
|
||||||
|
exit(1);
|
||||||
|
if (*input)
|
||||||
|
{
|
||||||
|
write(sock, input, ft_strlen(input));
|
||||||
|
read(sock, buf, FTP_READ_BUF);
|
||||||
|
write(1, buf, ft_strlen(buf));
|
||||||
|
}
|
||||||
|
ft_strdel(&input);
|
||||||
|
tcsetpgrp(STDIN, client_pid);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
waitpid(pid, &status, 0);
|
||||||
|
if (WEXITSTATUS(status) == 1)
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
close(sock);
|
close(sock);
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/04/03 16:08:44 by jhalford #+# #+# */
|
/* Created: 2017/04/03 16:08:44 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/04/03 17:20:01 by jhalford ### ########.fr */
|
/* Updated: 2017/04/03 18:24:24 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -29,7 +29,7 @@ int ftp_spawn(int cs)
|
||||||
ft_printf("{yel}{inv}%i {gre} new connection {eoc}\n", getpid());
|
ft_printf("{yel}{inv}%i {gre} new connection {eoc}\n", getpid());
|
||||||
while ((r = read(cs, buf, FTP_BUF)) > 0)
|
while ((r = read(cs, buf, FTP_BUF)) > 0)
|
||||||
{
|
{
|
||||||
buf[r - 1] = 0;
|
buf[r] = 0;
|
||||||
ft_printf("{yel}{inv}%i {eoc} received %i bytes: [%s]\n", getpid(), r, buf);
|
ft_printf("{yel}{inv}%i {eoc} received %i bytes: [%s]\n", getpid(), r, buf);
|
||||||
ft_bzero(&reply, sizeof(reply));
|
ft_bzero(&reply, sizeof(reply));
|
||||||
ftp_cmd(buf, &reply);
|
ftp_cmd(buf, &reply);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/04/03 16:42:58 by jhalford #+# #+# */
|
/* Created: 2017/04/03 16:42:58 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/04/03 17:20:02 by jhalford ### ########.fr */
|
/* Updated: 2017/04/03 18:42:32 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue