Example #1
0
int					get_client(t_socket *serv, t_socket *cli)
{
	cli->socklen = sizeof(cli->addr);
	cli->fd = accept(serv->fd, (struct sockaddr *)&cli->addr, &(cli->socklen));
	if (cli->fd < 0)
	{
		printf("Error while acept\n");
		return (-1);
	}
	send_int32(cli->fd, MSG_CO_CONFIRM);
	return (0);
}
Example #2
0
int						command_ls(int sockfd, char *command)
{
	int					n;
	char				buf[BUFSIZ + 1];
	char				*tmp;

	if (check_command_usage(command, 0) == NULL)
		return (error_handling(-1, MSG_LS_USAGE, NULL));
	send_int32(sockfd, MSG_LS);
	while ((n = recv(sockfd, &buf, BUFSIZ, 0)) > 0)
	{
		buf[n] = '\0';
		if ((tmp = ft_strchr(buf, EOF)) != NULL)
		{
			*tmp = '\0';
			printf("%s", buf);
			break ;
		}
		else
			printf("%s", buf);
	}
	(void)sockfd;
	return (0);
}
Example #3
0
void send_msg_with_len(int sockfd, const void *buf, size_t count)
{
	send_int32(sockfd, count);
	if (writen(sockfd, buf, count) != count)
		ERR_EXIT("send_msg_with_len");
}