Ejemplo n.º 1
0
int main (int argc, char **argv)
{
  gsk_init_without_threads (&argc, &argv);

  g_printerr ("TCP/IP server/client... ");
  addr = gsk_socket_address_ipv4_localhost (10306);
  create_server (addr);
  client_count = 0;
  create_client (addr);
  while (!done_test)
    gsk_main_loop_run (gsk_main_loop_default(), -1, NULL);
  g_object_unref (listener);
  listener = NULL;
  g_object_unref (addr);
  addr = NULL;
  g_printerr (" done.\n");

  client_count = 0;
  done_test = FALSE;

  g_printerr ("Local-socket server/client... ");
#define TEST_LOCAL_SOCKET_FNAME	"./test-socket-sc"
  addr = gsk_socket_address_local_new (TEST_LOCAL_SOCKET_FNAME);
  create_server (addr);
  client_count = 0;
  create_client (addr);
  while (!done_test)
    gsk_main_loop_run (gsk_main_loop_default(), -1, NULL);
  g_object_unref (listener);
  g_object_unref (addr);
  g_printerr (" done.\n");

  return 0;
}
Ejemplo n.º 2
0
/*
static struct sigaction sa={
   .sa_handler = SIG_IGN
};
*/
int server(int port, int maxevents)
{
 
  // sigaction(SIGINT, &sa, 0);
  // sigaction(SIGTERM, &sa, 0);  
   
   int srv_fd = -1;
   int epoll_fd = -1;
	reactor* r = 0;
	event_handler* seh = 0;
   
   if((srv_fd=create_server(port,"127.0.0.1")) == -1){
      return -1;
   }
   if((epoll_fd = create_epoll(srv_fd, maxevents)) == -1){
      return -1;
   }
   r = create_reactor(epoll_fd, maxevents);
	seh = create_acceptor(srv_fd, r);
	r->add_eh(r, seh);
   r->event_loop(r);
   
   destroy_reactor(r);
   os_close(srv_fd);
   os_close(epoll_fd);
	return 0;
}
Ejemplo n.º 3
0
PortServer * create_port_server(Channel * c, PortAttribute * attrs, PortConnectCallback connect_callback, PortDisconnectCallback disconnect_callback, PortRecvCallback recv_callback, void * callback_data) {
    PortServer * server;
    assert (c != NULL);
    assert (attrs != NULL);

    if (c == NULL || attrs == NULL) {
        free_port_redirection_attrs(attrs);
        errno = EINVAL;
        return NULL;
    }
    ini_portforwarding();
    server = create_server(c, attrs);
    if (server == NULL) {
        free_port_redirection_attrs(attrs);
        return NULL;
    }
    else {
        server->connect_callback = connect_callback;
        server->disconnect_callback = disconnect_callback;
        server->recv_callback = recv_callback;
        server->callback_data = callback_data;
        if (server->auto_connect) {
            /* If auto connect mode is set, immediately try to connect to the
             * port.  */
            if (server->auto_connect_period == 0) server->auto_connect_period = 3;
            port_connection_open(server, server->is_udp ? server->sock : -1);
        }
        return server;
    }
}
Ejemplo n.º 4
0
int main()
{
    int listenfd = create_server(2000), connfd, i, pid, ret;
    char line[1000];
    pthread_t tid;
    struct request *r; 

    for (; ;) {
        if ((connfd = accept(listenfd, (struct sockaddr *)NULL, NULL))<0) {
            perror("accept error : ");
            return -1;
        }
        getline(line, connfd);
        if ((ret = validate_request(line, connfd))>0) {
	    r = (struct request *)malloc(sizeof(struct request));
            r->request_t = ret;
            strcpy(r->req, line);
	    r->connfd = connfd;
	    printf("creating thread\n");
            ret = pthread_create(&tid, NULL, handle_request, (void *)r);
	}
        else {
	    close(connfd);
	}
    }
    close(listenfd);
    return 0;
}
Ejemplo n.º 5
0
int			main(int argc, char *argv[])
{
	int					sock;
	int					cs;
	unsigned int		cslen;
	struct sockaddr_in	csin;
	pid_t				pid;

	signal(SIGCHLD, SIG_IGN);
	if (argc != 2)
		usage(argv[0]);
	sock = create_server(ft_atoi(argv[1]));
	while ((cs = accept(sock, (struct sockaddr *)&csin, &cslen)) > 0)
	{
		if ((pid = fork()) == -1)
			return (-1);
		if (pid == 0)
		{
			soon(cs);
			exit(0);
			return (0);
		}
	}
	close(cs);
	close(sock);
	return (0);
}
Ejemplo n.º 6
0
int main(int argc, char* argv[])
{
	int ret;
	// create server
	ret = create_server();
	if(ret != 0)
	{
		printf("create server error\n");
		return -1;
	}

	// send broad cast
	ret = send_broadcast();
	if(ret != 0)
	{
		printf("send broadcast error\n");
		return -2;
	}

	// accept client
	ret = accept_client();
	if(ret != 0)
	{
		printf("accept_client error\n");
		return -3;
	}

	return 0;
}
Ejemplo n.º 7
0
void start_server(const char *ip, unsigned short port)
{
    //signal(SIGPIPE, SIG_IGN);
    signal(SIGPIPE, sig_handler);
    
    create_sock_list();
    start_timer();

    int err = 0;

    // create a TCP socket, bind and listen
    server_sock = socket(AF_INET, SOCK_STREAM, 0);
    fcntl(server_sock, F_SETFL, O_NONBLOCK);

    struct sockaddr_in addr;
    memset(&addr, 0 , sizeof(addr));
    addr.sin_family = AF_INET;
    //addr.sin_addr.s_addr = htons(INADDR_ANY);
    addr.sin_addr.s_addr = inet_addr(ip);
    addr.sin_port = htons(port);

    err = bind(server_sock, (struct sockaddr *) &addr, sizeof(addr));
    if(err)
    {
	   printf("bind error: %m\n"); 
    }

    listen(server_sock, 10);

    
    g_server = create_server(server_sock);
 

    return 0;
}
Ejemplo n.º 8
0
int main(int argc , char *argv[])
{
  int socket_desc;
  int * clients = malloc(sizeof(int) * 4);
  char buffer[32] = {0};
  fd_set readfs;
  
  init_soft_war();
  my_actopt(g_tab, 6, argc, argv);
  build_map();
  show_info_server();
  if (soft_war.type == 0)
    {
      socket_desc = create_server(soft_war.port);
      clients = accept_for_clients(socket_desc);
      put_clients_on_map();
      while (1)
	 {
	   select_for_soft_war(clients, &readfs, buffer);
	 }
    }
  else
    {
      play(argc, argv);
    }
  return (0);
}
Ejemplo n.º 9
0
int main(int argc, char **argv)
{
	signal(SIGINT, sigstop);
	signal(SIGQUIT, sigstop);
	signal(SIGTERM, sigstop);

	if ((fd_iav = open("/dev/iav", O_RDWR, 0)) < 0) {
		perror("open /dev/iav");
		return -1;
	}

	if (init_param(argc, argv) < 0) {
		usage();
		return -1;
	}

	parse_default_configs();

	if (create_server() < 0) {
		APP_ERROR("create_server");
		return -1;
	}
	main_handle();

	#if 0
	while (1) {
		main_loop();
	}
	#endif
	while (1) {
		sleep(1);
	}

	return 0;
}
Ejemplo n.º 10
0
int main(int argc, char *argv[]) {
    int server, port = PORT, opt_idx = 0, c;

    static struct option long_options[] = {
        { "debug", no_argument, &debug, 1 },
        { "port", required_argument, 0, 'p' }
    };

    while ((c = getopt_long(argc, argv, "p:", long_options, &opt_idx)) != -1) {
        switch (c) {
            case 'p': port = atoi(optarg); break;
            case '?':                      break;
        }
    }

    if ((server = create_server(port)) == -1) {
        return -1;
    }

    if (!debug) {
        daemon(0, 0);
    }

    accept_loop(server, handle_client);

    return 0;
}
Ejemplo n.º 11
0
int main(){
    signal(SIGINT, destroy_server);    
    char server_path[BUFFER];
    CREATE_SERVER_FIFO_NAME(server_path);
    create_server();
    char* client_pid = NULL;
    char hack;
    long pid = 0;
    FILE* server_fd = fopen(server_path, "r+");
    size_t len = 0;
    ssize_t read;

    while((read = getline(&client_pid, &len, server_fd)) != -1){
        fread(&hack, sizeof(char), 1, server_fd);
        pid = strtol(client_pid, NULL, 10);
        if(fork() == 0){
            printf("Creating server for Client %ld\n", pid);
            baby_server_read(pid);
        }
        if(signal(SIGINT, destroy_server) == SIG_ERR){
            printf("Signal didn't work");
        }
    }

    return 0;
}
Ejemplo n.º 12
0
void BuildServer::onItemClicked( QTableWidgetItem *item )
{
    qDebug() << "BuildServer: onItemClicked and emit toBuildTCP()" ;
    IP = tableWidget->item( item->row() , 1 )->text() ;
    connect( this , SIGNAL( toBuildTCP() ) , peopVSpeop , SLOT( create_server() ) ) ;
    emit toBuildTCP() ;   
}
Ejemplo n.º 13
0
Archivo: main.c Proyecto: kelu27/42
void	ft_init(t_serv *e, char *av)
{
	e->counter = 0;
	e->port = ft_atoi(av);
	e->sock = create_server(e->port);
	getcwd(e->home, 1024);
	e->pwd = ft_strdup(e->home);
}
Ejemplo n.º 14
0
void do_sendfile(void)
{
	int in_fd;
	struct stat sb;
	off_t after_pos;
	int wait_status;
	int wait_stat;

	out_fd = create_server();

	if ((in_fd = open(in_file, O_RDONLY)) < 0) {
		tst_brkm(TBROK, cleanup, "open failed: %d", errno);
	 }
	if (stat(in_file, &sb) < 0) {
		tst_brkm(TBROK, cleanup, "stat failed: %d", errno);
	 }

	TEST(sendfile(out_fd, in_fd, NULL, sb.st_size));
	if ((after_pos = lseek(in_fd, 0, SEEK_CUR)) < 0) {
		tst_brkm(TBROK, cleanup,
			 "lseek after invoking sendfile failed: %d", errno);
	 }

	if (STD_FUNCTIONAL_TEST) {
		/* Close the sockets */
		shutdown(sockfd, SHUT_RDWR);
		shutdown(s, SHUT_RDWR);
		if (TEST_RETURN != sb.st_size) {
			tst_resm(TFAIL, "sendfile(2) failed to return "
				 "expected value, expected: %"PRId64", "
				 "got: %ld", (int64_t)sb.st_size, TEST_RETURN);
			kill(child_pid, SIGKILL);
		} else if (after_pos != sb.st_size) {
			tst_resm(TFAIL, "sendfile(2) failed to update "
				 " the file position of in_fd, "
				 "expected file position: %"PRId64", "
				 "actual file position %"PRId64,
				 (int64_t)sb.st_size, (int64_t)after_pos);
			kill(child_pid, SIGKILL);
		} else {
			tst_resm(TPASS, "functionality of sendfile() is "
				 "correct");
			wait_status = waitpid(-1, &wait_stat, 0);
		}
	} else {
		tst_resm(TPASS, "call succeeded");
		/* Close the sockets */
		shutdown(sockfd, SHUT_RDWR);
		shutdown(s, SHUT_RDWR);
		if (TEST_RETURN != sb.st_size) {
			kill(child_pid, SIGKILL);
		} else {
			wait_status = waitpid(-1, &wait_stat, 0);
		}
	}

	close(in_fd);
}
Ejemplo n.º 15
0
int main(int argc, char *argv[]) {
    Server *server = create_server();

    server->port = PORT;
    server->handler = &handler;
    server_start(server);

    return 0;
}
Ejemplo n.º 16
0
int main() {
  int fd[2] = {-1, -1};
  int server = -1, client = -1;
  FILE *fp = NULL;
  FILE *fp2 = NULL;
  fp = fopen("a.txt", "w");
  if (fp == NULL) {
    fprintf(stderr, "fopen(a.txt) failed: %s\n", strerror(errno));
    goto ERR_FOPEN;
  }
  fd[0] = fileno(fp);
  printf("a.txt:%d\n", fd[0]);

  fp2 = fopen("aa.txt", "w");
  if (fp2 == NULL) {
    fprintf(stderr, "fopen(aa.txt) failed: %s\n", strerror(errno));
    goto ERR_FOPEN;
  }
  fd[1] = fileno(fp2);
  printf("aa.txt:%d\n", fd[1]);
  server = create_server();
  if (server < 0) {
    fprintf(stderr, "create_server failed\n");
    goto ERR_CREATE_SERVER;
  }
  while(1) {
    client = accept(server, NULL, NULL);
    fprintf(stderr, "client accept %d\n", client);
    if (client < 0) {
      fprintf(stderr, "accept failed\n");
      goto ERR_ACCEPT;
    }

    if (send_file_descriptor(client, fd) < 0) {
      fprintf(stderr, "send_file_descriptor failed: %s\n", strerror(errno));
      goto ERR_SEND_FILE_DESCRIPTOR;
    }

    if (shutdown(client, SHUT_RDWR) < 0) {
      fprintf(stderr, "shutdown failed: %s\n", strerror(errno));
      goto ERR_SHUTDOWN;
    }
  }

ERR_SHUTDOWN:
ERR_SEND_FILE_DESCRIPTOR:
  close(client);
ERR_ACCEPT:
  close(server);
ERR_CREATE_SERVER:
  fclose(fp);
  fclose(fp2);
ERR_FOPEN:
  return 0;
}
Ejemplo n.º 17
0
void do_sendfile(int prot, int pass_unmapped_buffer)
{
	OFF_T *protected_buffer;
	int in_fd;
	struct stat sb;

	protected_buffer = mmap(NULL,
				sizeof(*protected_buffer),
				prot, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
	if (protected_buffer == MAP_FAILED) {
		tst_brkm(TBROK, cleanup, "mmap failed: %d", errno);
	}

	out_fd = create_server();

	if ((in_fd = open(in_file, O_RDONLY)) < 0) {
		tst_brkm(TBROK, cleanup, "open failed: %d", errno);
	}
	if (stat(in_file, &sb) < 0) {
		tst_brkm(TBROK, cleanup, "stat failed: %d", errno);
	}

	if (pass_unmapped_buffer) {
		if (munmap(protected_buffer, sizeof(*protected_buffer)) < 0) {
			tst_brkm(TBROK, cleanup, "munmap failed: %d", errno);
		}
	}

	TEST(sendfile(out_fd, in_fd, protected_buffer, sb.st_size));

	if (TEST_RETURN != -1) {
		tst_resm(TFAIL, "call succeeded unexpectedly");
	} else {
		TEST_ERROR_LOG(TEST_ERRNO);

		if (TEST_ERRNO != EFAULT) {
			tst_resm(TFAIL, "sendfile returned unexpected "
				 "errno, expected: %d, got: %d",
				 EFAULT, TEST_ERRNO);
		} else {
			tst_resm(TPASS, "sendfile() returned %d : %s",
				 TEST_ERRNO, strerror(TEST_ERRNO));
		}
	}

	shutdown(sockfd, SHUT_RDWR);
	shutdown(s, SHUT_RDWR);
	kill(child_pid, SIGKILL);
	close(in_fd);

	if (!pass_unmapped_buffer) {
		/* Not unmapped yet. So do it now. */
		munmap(protected_buffer, sizeof(*protected_buffer));
	}
}
Ejemplo n.º 18
0
int main()
{ int i;
  int server_socket = create_server();
  client_data * * client_list = malloc(max_users * sizeof(*client_list));
  for (i = 0; i < max_users; i += 1)
    client_list[i] = malloc(sizeof(client_data));
  for (i = 0; i < max_users; i += 1)
  { client_list[i]->initial_one = '0';
    client_list[i]->initial_two = '0';
    client_list[i]->room_socket = 0; }
  manage_clients(server_socket, client_list); }
Ejemplo n.º 19
0
int	main(int ac, char **av)
{
  t_ftp	f;

  f.port = (ac < 2 ? PORT_DEFAULT : av[1]);
  if (create_server(&f) == TRUE)
    while ((f.cs = xaccept(f.s, NULL, NULL)) > 0)
      get_client(&f);
  close(f.s);
  return (TRUE);
}
Ejemplo n.º 20
0
int		main(int argc, char **argv)
{
	int	sock;

	if (argc != 2)
		shell_perror("USAGE: ./serveur [port]");
	sock = create_server(ft_atoi(argv[1]));
	server(sock);
	close(sock);
	return (0);
}
Ejemplo n.º 21
0
/**
 * Creates a new server connection.
 *
 * The method creates a server connection instance
 * but does not put it in listen mode.
 * Anyway it selects and reserves a free channel to listen for
 * incoming connections on after the listen method is called.
 *
 * @param auth    JAVACALL_TRUE if authication is required
 * @param authz   JAVACALL_TRUE if authorization is required
 * @param enc     JAVACALL_TRUE if required to be encrypted
 * @param master  JAVACALL_TRUE if required to be a connection's master
 * @param pHandle pointer to connection handle variable,
 *               new connection handle returned in result.
 * @param cn pointer to variable, where reserved channel is returned in.
 *
 * @retval JAVACALL_OK on success,
 * @retval JAVACALL_FAIL otherwise
 */
javacall_result javacall_bt_rfcomm_create_server(
        javacall_bool auth,
        javacall_bool authz,
        javacall_bool enc,
        javacall_bool master,
        /*OUT*/javacall_handle* pHandle,
        /*OUT*/int* pCn)
{
    return create_server(RFCOMM, 
        -1, -1, auth, authz, enc, master, pHandle, pCn);
}
Ejemplo n.º 22
0
c_netuser::c_netuser(const std::string &username, int port) :
                                                              c_user(username),
                                                              server_port(port),
                                                              client_socket(m_io_service),
                                                              server_socket(m_io_service),
                                                              m_acceptor(m_io_service, ip::tcp::endpoint(ip::tcp::v6(),server_port)),
                                                              m_stop_flag(false)
{
    create_server();
    threads_maker(2);
}
void Config::reset()
{
    /** Make sure the servers exist before checking that connectivity is OK */
    for (int i = 0; i < test_->repl->N; i++)
    {
        if (created_servers_.find(i) == created_servers_.end())
        {
            create_server(i);
            add_server(i);
        }
    }
}
Ejemplo n.º 24
0
int main(int argc, char *argv[])
{
    SOCKET client_socket, server_socket;
    int read_size;
    
    server_socket = create_server();
    client_socket = connect_to_client(server_socket);
    read_size = main_echo_cycle(client_socket);
    check_recv_last_response(read_size);
    cleanup(server_socket, client_socket);
    return 0;
}
Ejemplo n.º 25
0
Archivo: epoll.c Proyecto: shibing/misc
int main(int argc, char *argv[])
{
    int server_fd = create_server("127.0.0.1", atoi(argv[1]));

    int efd = epoll_create(128);

    struct epoll_event e;
    e.events = EPOLLIN;
    e.data.fd = server_fd;
    epoll_ctl(efd, EPOLL_CTL_ADD, server_fd, &e);

    struct epoll_event events[128];

    for ( ;; ) {

        int n = epoll_wait(efd, events, 128, -1);

        if (n == -1) {
            perror("epoll_wait failed");
            close(server_fd);
            close(efd);
            return 1;
        }

        for (int  i = 0; i < n; ++i) {
            int revents = events[i].events;
            int fd = events[i].data.fd;

            if (revents & EPOLLIN) {
                if (fd == server_fd) {
                    struct sockaddr_in addr;
                    int addrlen;
                    int cfd = accept4(server_fd, (struct sockaddr *)&addr, &addrlen, SOCK_NONBLOCK);
                    struct epoll_event e ;
                    e.data.fd = cfd;
                    e.events = EPOLLIN | EPOLLET | EPOLLRDHUP;
                    epoll_ctl(efd, EPOLL_CTL_ADD, cfd, &e);
                } else {
                    if (revents & EPOLLRDHUP) {
                        printf("client :%d closed", fd);
                        close(fd);
                        continue;
                    }
                }
            }

            if (revents & EPOLLOUT) {

            }
        }
    }
}
Ejemplo n.º 26
0
int		main(int ac, char **av, char **env)
{
	t_all	*all;
	int		port;

	if (ac != 2)
		usage(av[0]);
	port = ft_atoi(av[1]);
	all = s_init_all(env);
	all->sv->sock = create_server(port);
	loop(all);
	return (0);
}
Ejemplo n.º 27
0
int main(int argc, const char *argv[])
{

	parse_ini("cfg.ini", ini_parser, NULL);

	int fd = create_server(1001, 1);
	if( fd == -1 ) return 0;
	while(1)
	{
		udp_receive(fd, packet_recvier);	
	}
	return 0;
}
Ejemplo n.º 28
0
int main(int argc, char **argv)
{
        printf("Frozen-Bubble server version 0.001_1 (protocol version %d.%d)\n", proto_major, proto_minor);
        printf("\n");
        printf("Copyright (c) 2004-2008 Guillaume Cottenceau.\n");
        printf("This is free software; see the source for copying conditions.  There is NO\n");
        printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
        printf("\n");

        create_server(argc, argv);
        connections_manager();

        return 0;
}
Ejemplo n.º 29
0
Archivo: ssl.c Proyecto: ustime/test
/**
 * Example SSL server that accepts a client and echos back anything it receives.
 * Test using `curl -I https://127.0.0.1:8081 --insecure`
 */
int main(int arc, char **argv) {
  int fd = create_server(); 
  if (fd < 0) {
    exit(1);
  }

  int cd;
  while ((cd = accept(fd, 0, 0)) != -1) {
    ssl_run(cd);
    close(cd);
  }

  return 0;
}
Ejemplo n.º 30
0
Archivo: main.c Proyecto: Affon/Apache3
int main(void){

  int server_socket = create_server(8080);
  if(server_socket == -1){
    perror("Impossible de creer le serveur");
    return -1;
  }

  while (1) {
    accept_client(server_socket);
  }
  
  return 0;
}