Beispiel #1
0
static void process_recv(struct mux_client *client)
{
	int res;
	int did_read = 0;
	if(client->ib_size < sizeof(struct usbmuxd_header)) {
		res = recv(client->fd, client->ib_buf + client->ib_size, sizeof(struct usbmuxd_header) - client->ib_size, 0);
		if(res <= 0) {
			if(res < 0)
				usbmuxd_log(LL_ERROR, "Receive from client fd %d failed: %s", client->fd, strerror(errno));
			else
				usbmuxd_log(LL_INFO, "Client %d connection closed", client->fd);
			client_close(client);
			return;
		}
		client->ib_size += res;
		if(client->ib_size < sizeof(struct usbmuxd_header))
			return;
		did_read = 1;
	}
	struct usbmuxd_header *hdr = (void*)client->ib_buf;
	if(hdr->length > client->ib_capacity) {
		usbmuxd_log(LL_INFO, "Client %d message is too long (%d bytes)", client->fd, hdr->length);
		client_close(client);
		return;
	}
	if(hdr->length < sizeof(struct usbmuxd_header)) {
		usbmuxd_log(LL_ERROR, "Client %d message is too short (%d bytes)", client->fd, hdr->length);
		client_close(client);
		return;
	}
	if(client->ib_size < hdr->length) {
		if(did_read)
			return; //maybe we would block, so defer to next loop
		res = recv(client->fd, client->ib_buf + client->ib_size, hdr->length - client->ib_size, 0);
		if(res < 0) {
			usbmuxd_log(LL_ERROR, "Receive from client fd %d failed: %s", client->fd, strerror(errno));
			client_close(client);
			return;
		} else if(res == 0) {
			usbmuxd_log(LL_INFO, "Client %d connection closed", client->fd);
			client_close(client);
			return;
		}
		client->ib_size += res;
		if(client->ib_size < hdr->length)
			return;
	}
	client_command(client, hdr);
	client->ib_size = 0;
}
Beispiel #2
0
void		unlogged_loop(t_client *client)
{
    int		ret;

    ft_strcpy(client->prompt, client->tmp_nick);
    ft_strcat(client->prompt, "> ");
    while (!client->is_connected && !client->exit)
    {
        ft_print(client->prompt, 1);
        ret = read(0, client->buff, BUFFSIZE);
        client->buff[ret] = 0;
        client_command(client);
    }
    main_loop(client);
}
Beispiel #3
0
void	loop_clients(t_serveur *serveur, fd_set *read_set, fd_set *write_set)
{
  int		sent;
  t_client	*cur;

  sent = 0;
  cur = serveur->clients;
  while (cur)
    {
      if (FD_ISSET(cur->fd, read_set) && ++sent && 
	  client_command(serveur, cur))
	cur = serveur->clients;
      if (cur && FD_ISSET(cur->fd, write_set))
	sent += send_data(cur);
      if (cur)
	cur = cur->next;
    }
  if (!sent)
    usleep(100);
}
Beispiel #4
0
static void cmd_execute_real(int c, int caller, char *name, int type) {
    cmd_stack_push();
    s->caller = caller;
    parse_cmd(name, -1);

    cmd_t *cmd = NULL;
    int cmds = 0;
    while ((cmd = cmd_find(cmd, c, type, qfalse)) != NULL) {
        cmds++;

        int start = c;
        int end = c;
        qboolean switch_screen = qfalse;
        int old_type = type;
        if (cmd_type_compatible(cmd->type, type))
            type = cmd->type;
        if ((type == CT_BROADCAST || type == CT_CVAR) && c < 0) {
            start = 0;
            end = CLIENTS - 1;
        } else if (type == CT_BROADCAST_ALL) {
            start = -1;
            end = CLIENTS - 1;
        } else if (type == CT_FIND_FREE && c < 0) {
            int i;
            qboolean found = qfalse;
            for (i = 0; i < CLIENTS && !found; i++) {
                if (!client_active(i)) {
                    start = i;
                    end = i;
                    found = qtrue;
                    switch_screen = qtrue;
                    break;
                }
            }
            if (!found) {
                ui_output(c, "No free client found.\n");
                cmd_stack_pop();
                return;
            }
        }
        for (s->client = start; s->client <= end; s->client++) {
            if (type == CT_SERVER)
                client_command(s->client, "%s", cmd_args(0));
            else
                cmd->f();
            if (switch_screen)
                set_screen(s->client + 1);
        }
        type = old_type;
    }
    if (cmds == 0) {
        if (cmd_type_compatible(type, CT_PUBLIC)) {
            if (cmd_argv(0)[0])
                client_say(c, "Unknown command: \"%s\"", cmd_argv(0));
        } else if (!cmd_type_compatible(type, CT_EVENT)) {
            ui_output(c, "Unknown command: \"%s\"\n", cmd_argv(0));
        }
        cmd_stack_pop();
        return;
    }
    cmd_stack_pop();
}