Esempio n. 1
0
void		loop_server(t_server *s, char **argv)
{
  int		i;

  while (42)
    {
      i = 0;
      s->read_fds = s->master;
      signal(SIGINT, handler_ctrl_c);
      if (select(s->fdmax + 1, &(s->read_fds), NULL, NULL, NULL) == -1)
	{
	  perror("Server-select() error !");
	  exit(1);
	}
      printf("Server-select() is OK...\n");
      while (i <= s->fdmax)
	{
	  if (FD_ISSET(i, &(s->read_fds)))
	    {
	      if (i == s->listener)
		accept_server(s, argv);
	      else
		read_write_server(s, i, argv);
	    }
	  i++;
	}
    }
}
int main(int argc,char **argv) {
	if(argc != 2) {
		return 2;
	}
	
	char *socket_path;
	
	socket_path = argv[1];
	
	if(accept_server(socket_path,10)) {
		return 1;
	}
}
Esempio n. 3
0
static int create_sockets_tcp(fd_pair *client_fds, fd_pair *server_fds) {
  int listen_fd = -1;
  int client_fd = -1;
  int server_fd = -1;

  struct sockaddr_in port;
  struct sockaddr *sa_port = (struct sockaddr *)&port;

  port.sin_family = AF_INET;
  port.sin_port = 0;
  port.sin_addr.s_addr = INADDR_ANY;

  listen_fd = create_listening_socket(sa_port, sizeof(port));
  if (listen_fd == -1) {
    gpr_log(GPR_ERROR, "Listen failed");
    goto error;
  }

  client_fd = connect_client(sa_port, sizeof(port));
  if (client_fd == -1) {
    gpr_log(GPR_ERROR, "Connect failed");
    goto error;
  }

  server_fd = accept_server(listen_fd);
  if (server_fd == -1) {
    gpr_log(GPR_ERROR, "Accept failed");
    goto error;
  }

  client_fds->read_fd = client_fd;
  client_fds->write_fd = client_fd;
  server_fds->read_fd = server_fd;
  server_fds->write_fd = server_fd;
  close(listen_fd);
  return 0;

error:
  if (listen_fd != -1) {
    close(listen_fd);
  }
  if (client_fd != -1) {
    close(client_fd);
  }
  if (server_fd != -1) {
    close(server_fd);
  }
  return -1;
}
int main(int argc,char **argv) {
	if(argc != 3) {
		return 2;
	}
	
	char *socket_path;
	struct conjuration_diy_tmp tmp;
	
	socket_path = argv[1];
	tmp.location = open(argv[2],O_RDONLY);
	tmp.counter = 0;
	
	if(tmp.location < 0) {
		return 3;
	}
	
	if(accept_server(socket_path,10,&tmp)) {
		return 1;
	}
}
static gboolean
watch_func (GIOChannel *channel, GIOCondition condition, gpointer data)
{
    MilterTestClient *client = data;
    gboolean keep_callback = TRUE;

    if (condition & G_IO_IN ||
        condition & G_IO_PRI) {
        keep_callback = accept_server(client);
    }

    if (condition & G_IO_ERR ||
        condition & G_IO_HUP ||
        condition & G_IO_NVAL) {
        gchar *message;

        message = milter_utils_inspect_io_condition_error(condition);
        cut_notify("%s", message);
        g_free(message);
        return FALSE;
    }

    return keep_callback;
}