client behaves well when server quits

This commit is contained in:
Jack Halford 2017-11-20 13:24:24 +01:00
parent e7643cc6c7
commit 18d8963f1d
7 changed files with 64 additions and 7 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/08 13:43:10 by jhalford #+# #+# */ /* Created: 2017/11/08 13:43:10 by jhalford #+# #+# */
/* Updated: 2017/11/12 14:19:35 by jhalford ### ########.fr */ /* Updated: 2017/11/20 13:20:26 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/09 11:19:41 by jhalford #+# #+# */ /* Created: 2017/11/09 11:19:41 by jhalford #+# #+# */
/* Updated: 2017/11/12 15:01:58 by jhalford ### ########.fr */ /* Updated: 2017/11/20 13:21:04 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/08 19:52:07 by jhalford #+# #+# */ /* Created: 2017/11/08 19:52:07 by jhalford #+# #+# */
/* Updated: 2017/11/20 13:00:14 by jhalford ### ########.fr */ /* Updated: 2017/11/20 13:24:00 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -52,7 +52,6 @@ int ftp_recv(int sock, char **msg)
return (-1); return (-1);
if (ret == 0) if (ret == 0)
return (-1); return (-1);
console_msg(2, "recv size=%i", ret);
buf[ret] = 0; buf[ret] = 0;
if (buf[ret - 1] == '\n' && buf[ret - 2] == '\r') if (buf[ret - 1] == '\n' && buf[ret - 2] == '\r')
{ {

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/08 14:55:15 by jhalford #+# #+# */ /* Created: 2017/11/08 14:55:15 by jhalford #+# #+# */
/* Updated: 2017/11/15 13:11:45 by jhalford ### ########.fr */ /* Updated: 2017/11/20 13:20:44 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -0,0 +1,58 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ftp_crlf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/20 12:45:58 by jhalford #+# #+# */
/* Updated: 2017/11/20 13:23:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftp_client.h"
int ftp_send(int sock, char *msg, ...)
{
int err;
char *crlf_tmp;
char *crlf_msg;
va_list ap;
va_start(ap, msg);
ft_vasprintf(&crlf_tmp, msg, ap);
console_msg(1, "---> %s", crlf_tmp);
crlf_msg = ft_strjoin(crlf_tmp, "\r\n");
if ((err = send(sock, crlf_msg, ft_strlen(crlf_msg), 0)) < 0)
{
return (err);
}
ft_strdel(&crlf_tmp);
ft_strdel(&crlf_msg);
return (ft_atoi(msg));
}
int ftp_msg(t_ftp *ftp, char **msg)
{
int code;
if (ftp_recv(ftp->cmd_sock, msg) < 0)
{
console_msg(0, "server terminated");
exit(0);
}
code = ft_atoi(*msg);
console_msg(0, "<--- %s", *msg);
return (code);
}
int ftp_code(t_ftp *ftp)
{
char *msg;
int code;
if ((code = ftp_msg(ftp, &msg)) < 0)
return (-1);
ft_strdel(&msg);
return (code);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/08 19:52:07 by jhalford #+# #+# */ /* Created: 2017/11/08 19:52:07 by jhalford #+# #+# */
/* Updated: 2017/11/15 13:27:59 by jhalford ### ########.fr */ /* Updated: 2017/11/20 13:21:25 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/08 14:55:15 by jhalford #+# #+# */ /* Created: 2017/11/08 14:55:15 by jhalford #+# #+# */
/* Updated: 2017/11/15 13:11:03 by jhalford ### ########.fr */ /* Updated: 2017/11/20 13:20:29 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */