Пример #1
0
static inline void data_in(eplsvr_t *ep, int sock)
{
	if (ep->options & EPLSVR_RECV_CALLBACK) {
		int ret;
		ret = ep->cb->data_recv(sock, ep->param);
		if (ret == -1)
			goto err;
		else if (ret == EPLSVR_REMOVE_SOCK_ONLY) {
			epoll_ctl(ep->eplfd, EPOLL_CTL_DEL, sock, NULL);
			ep->cur_clients--;
		}
	} else {
		char buff[ep->buff_size];
		int bytes;

		bytes = recv(sock, buff, sizeof(buff), 0);
		if (bytes <= 0)
			goto err;

		if (ep->cb->data_in) {
			if (ep->cb->data_in(sock, buff, bytes, ep->param) != 0)
				goto err;
		}
	}

	return;

err:
	client_out(ep, sock);
}
Пример #2
0
void				be_client(char *ip, int port)
{
	t_socket		sock;
	fd_set			rdfs;
	char			*ask;
	char			*prompt;

	sock = init_connection(ip, port);
	while (1)
	{
		init_socks(sock, &rdfs);
		if (FD_ISSET(STDIN_FILENO, &rdfs))
			client_in(sock);
		else if (FD_ISSET(sock, &rdfs))
		{
			client_out(sock);
			ask = ft_strdup("/gp\n");
			ft_send(sock, ask);
			free(ask);
			prompt = get_message(sock);
			ft_putstr("\n");
			ft_putstr(prompt);
			free(prompt);
		}
	}
}
Пример #3
0
static void *loop_thread(void *arg)
{
	eplsvr_t *ep = (eplsvr_t *)arg;

	int fds, i;
	struct epoll_event evs[EVENTS];

	while (1) {
		fds = epoll_wait(ep->eplfd, evs, EVENTS, -1);
		if (fds == -1 && errno != EINTR) {
			syslog(LOG_ERR, "epoll_wait(): %s", strerror(errno));
			//continue;
			exit(1);
		}

		for (i = 0; i < fds; i++) {
			if (evs[i].data.fd == ep->lsnfd)  /* client comming */
				client_in(ep);
			else if (evs[i].events & EPOLLIN) /* data comming */
				data_in(ep, evs[i].data.fd);
			else	/* error */
				client_out(ep, evs[i].data.fd);
		}
	}

	return NULL;
}
Пример #4
0
static void	warn(t_client *client, const char *reason)
{
  t_channel	*channel;
  t_client	*dest;
  t_iterator	chan_it;
  t_iterator	client_it;

  iterator_ctor(&chan_it, &client->channels, IT_DATA);
  while ((channel = iterator_current(&chan_it)))
    {
      iterator_next(&chan_it);
      iterator_ctor(&client_it, &channel->clients, IT_DATA);
      while ((dest = iterator_current(&client_it)))
	{
	  iterator_next(&client_it);
	  client_out(dest, ":%s!%s@%s QUIT :%s\r\n", client->nickname,
		     client->name, client->server, reason ? reason : "Quit");
	}
    }
}