Example #1
0
File: live.c Project: vplotton/work
t_bool			live(t_env *env, t_player *player)
{
	t_bool	action;
	t_bool	alive;
	int		i;
	t_cmds	*cmds;

	i = 0;
	alive = TRUE;
	action = TRUE;
	cmds = ft_memalloc(sizeof(t_cmds));
	cmds->need_c = TRUE;
	cmds->nb_cmd = 0;
	while (alive)
	{
		process_ia(env, player, &cmds);
		if ((action = ft_recv(env, player, cmds->order[0])) == TRUE)
			reorder_cmd(&cmds);
		if (action == TRUE || !i)
			ft_send(env->s_sock, &cmds->order[0]);
		else if (action == END)
			break ;
		action = FALSE;
		i++;
	}
	free(cmds);
	return (TRUE);
}
Example #2
0
void					do_it(t_truck *b, int sock)
{
	while ((b->i = read(0, b->line, 2048)) > 0)
	{
		b->line[b->i] = '\0';
		ft_send(sock, 0, b->line, ft_strlen(b->line));
		if ((ft_strnstr(b->line, "quit", 4)) != NULL)
			break ;
		b->r = c_trans(b, sock);
		if (b->r == 0)
		{
			ft_recv(sock, &b->buff);
			printf("%s\n", b->buff);
		}
		ft_strdel(&b->buff);
		ft_bzero(b->line, 2048);
		write(1, "client$$$:", 10);
	}
	return ;
}
Example #3
0
int			s_exec_put(unsigned char *cmd, unsigned char *arg, int r)
{
	unsigned char	*data;
	int				fd;
	unsigned int	size;

	if (check_ftp((char *)cmd, arg, &r, 0) == -1)
		return (-1);
	if (!r)
		return (0);
	if ((fd = open((char *)arg, O_WRONLY | O_CREAT | O_TRUNC, 0700)) == -1)
		return (ft_error("open() error"));
	if (ft_recv(&data, &size) == -1)
		return (-1);
	if (write(fd, data, size) == -1)
		return (ft_error("write() error"));
	free(data);
	if (close(fd) == -1)
		return (ft_error("close() error"));
	if (ft_send((unsigned char *)ft_strdup("OK"), 2) == -1)
		return (-1);
	return (0);
}
Example #4
0
G_MODULE_EXPORT gboolean
timeout(gpointer data)
{
	(void)data;

	if(gstate == STATE_CONNECTED){
		switch(ft_gotaction(&ft)){
			case FT_YES:
				/*
				 * state = STATE_TRANSFER;
				 * cmds();
				 * no need for this - set in the callback straight away
				 */

				if(!ft_connected(&ft)){
					/* connection closed */
					status("Connection closed");
					CLOSE();
					return FALSE; /* timer death */
				}

				if(ft_recv(&ft, callback, queryback, fnameback, inputback)){
					status("Couldn't receive incoming data: %s", ft_lasterr(&ft));
					CLOSE();
				}else{
					/*
					 * status("Received %s", ft_truncname(&ft, 32));
					 * don't do ^ here, it's done in the callback
					 */
					STAY_OPEN();
				}
				return FALSE; /* kill timer */

			case FT_ERR:
				status("ft_poll() error: %s", ft_lasterr(&ft));
				CLOSE();
				return FALSE;

			case FT_NO:
				return TRUE; /* keep looking */
		}
		/* unreachable */
	}else{
		enum ftret ftr = ft_accept(&ft);

		if(cancelled){
			status("Cancelled");
			cancelled = 0;
			return FALSE;
		}else
			switch(ftr){
				case FT_ERR:
					status("Couldn't accept connection: %s", ft_lasterr(&ft));
					return FALSE; /* kill timer */

				case FT_YES:
					status("Got connection from %s", ft_remoteaddr(&ft));
					gstate = STATE_CONNECTED;
					URGENT(1);
					cmds();
					/* fall */
				case FT_NO:
					return TRUE; /* make sure timeout keeps getting called */
			}
		/* unreachable */
	}
	/* unreachable (unless bogus enum value) */
	return TRUE;
}