Esempio n. 1
0
static Socket_Type *perform_accept (Socket_Type *s, struct sockaddr *addr, unsigned int *lenp)
{
   socklen_t addr_len;
   Socket_Type *s1;
   int fd1;

   addr_len = *lenp;
   while (-1 == (fd1 = accept (s->fd, addr, &addr_len)))
     {
#ifdef EINTR
	if (errno == EINTR)
	  {
	     if (-1 == SLang_handle_interrupt ())
	       return NULL;
	     continue;
	  }
#endif
	throw_errno_error ("accept", errno);
	return NULL;
     }
   *lenp = (unsigned int) addr_len;
   if (NULL == (s1 = create_socket (fd1, s->domain, s->type, s->protocol)))
     (void) close_socket (fd1);

   return s1;
}
Esempio n. 2
0
int main()
{
    int server_socket;
    int port;
    int epollfd;
    int ret;
    char buf[1024];

    port = 8765;
    server_socket = create_socket(port);

    /* 监听 */
    listen(server_socket, 10);

    struct epoll_event events[100];

    epollfd = epoll_create(1024);

    add_event(epollfd,server_socket,EPOLLIN);

    while(1) {
        //该函数返回已经准备好的描述符事件数目
        ret = epoll_wait(epollfd,events,EPOLLEVENTS,-1);
        //处理接收到的连接
        handle_events(epollfd,events,ret,server_socket,buf);
    }
    return 0;
}
Esempio n. 3
0
int bg_listen_socket_create_unix(const char * name,
                                 int queue_size)
  {
  int ret;

  struct sockaddr_un addr;
  int addr_len;
  ret = create_socket(PF_LOCAL, SOCK_STREAM, 0);
  if(ret < 0)
    {
    bg_log(BG_LOG_ERROR, LOG_DOMAIN, "Cannot create unix server socket");
    return -1;
    }

  addr.sun_family = AF_LOCAL;
  strncpy (addr.sun_path, name, sizeof(addr.sun_path));
  addr.sun_path[sizeof (addr.sun_path) - 1] = '\0';
  addr_len = SUN_LEN(&addr);
  if(bind(ret,(struct sockaddr*)(&addr),addr_len)<0)
    {
    bg_log(BG_LOG_ERROR, LOG_DOMAIN, "Cannot bind UNIX domain socket: %s",
           strerror(errno));
    return -1;
    }
  if(listen(ret, queue_size))
    {
    bg_log(BG_LOG_ERROR, LOG_DOMAIN, "Cannot put socket into listening mode");
    return -1;
    }
  return ret;
  }
Esempio n. 4
0
int main(int argc, char **argv)
{
    int choice;
    int servfd;
    char user[MAXNAMELEN];
    char pass[MAXNAMELEN];
    char content[CONTENTLEN];
    unsigned char buf[CONTENTLEN];
    size_t packetsize, pks;
    int code;
  
    if(argc!=2)
	{
	    fprintf(stderr, "Usage: client.exe servername\n");
	    exit(-1);
	}
    servfd = create_socket(argv[1], DEFAULT_PORT);
    
    if(servfd)
	{
	    Run(servfd);	
	    close(servfd);
	} //End code = 0 register user
    return 0;
}
int msg_init(char *sock_path)
{
	int listen_sock;
	int efd;
	int ret;

	listen_sock = create_socket(sock_path); 
	if (-1 == listen_sock) {
		return -1;
	}

	efd = epoll_create1(0);
	if (efd == -1)
	{
		DEBUG_ERROR("epoll_create");
		close(listen_sock);

		return -1;
	}

	ret = add2epoll(efd, EPOLLIN, listen_sock);
	if (0 == ret)
	{
		g_efd = efd;
		g_listen_fd = listen_sock;
	}
	else
	{
		close(listen_sock);
		close(efd); 
	}


	return ret;
}
Esempio n. 6
0
int bg_socket_connect_unix(const char * name)
  {
  struct sockaddr_un addr;
  int addr_len;
  int ret;
  ret = create_socket(PF_LOCAL, SOCK_STREAM, 0);
  if(ret < 0)
    {
    bg_log(BG_LOG_ERROR, LOG_DOMAIN, "Cannot create unix socket");
    return -1;
    }

  addr.sun_family = AF_LOCAL;
  strncpy (addr.sun_path, name, sizeof(addr.sun_path));
  addr.sun_path[sizeof (addr.sun_path) - 1] = '\0';
  addr_len = SUN_LEN(&addr);
  
  if(connect(ret,(struct sockaddr*)(&addr),addr_len)<0)
    {
    bg_log(BG_LOG_ERROR, LOG_DOMAIN, "Connecting unix socket failed: %s",
           strerror(errno));
    return -1;
    }
  return ret;
  }
Esempio n. 7
0
int qnet_tcp_listen(int port, const char *bindaddr) {
  UNUSED(bindaddr);

  int                 fd;
  struct sockaddr_in  sa;

  if ((fd = create_socket()) < 0) {
    return -1;
  }

  if (set_nonblocking(fd) < 0) {
    return -1;
  }

  memset(&sa,0,sizeof(sa));
  sa.sin_family = AF_INET;
  sa.sin_port = htons(port);
  sa.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bindaddr && inet_aton(bindaddr, &sa.sin_addr) == 0) {
    qerror("invalid bind address");
    close(fd);
    return -1;
  }
  if (net_listen(fd,(struct sockaddr*)&sa, sizeof(sa)) < 0) {
    close(fd);
    return -1;
  }

  return fd;
}
Esempio n. 8
0
/*
 * pjsip_fake_udp_transport_start()
 *
 * Create a FAKE_UDP socket in the specified address and start a transport.
 */
PJ_DEF(pj_status_t) pjsip_fake_udp_transport_start( pjsip_endpoint *endpt,
					       const pj_sockaddr_in *local_a,
					       const pjsip_host_port *a_name,
					       unsigned async_cnt,
					       pjsip_transport **p_transport)
{
    pj_sock_t sock;
    pj_status_t status;
    char addr_buf[PJ_INET6_ADDRSTRLEN];
    pjsip_host_port bound_name;

    PJ_ASSERT_RETURN(endpt && async_cnt, PJ_EINVAL);

    status = create_socket(pj_AF_INET(), local_a, sizeof(pj_sockaddr_in),
			   &sock);
    if (status != PJ_SUCCESS)
	return status;

    if (a_name == NULL) {
	/* Address name is not specified.
	 * Build a name based on bound address.
	 */
	status = get_published_name(sock, addr_buf, sizeof(addr_buf),
				    &bound_name);
	if (status != PJ_SUCCESS) {
	    pj_sock_close(sock);
	    return status;
	}

	a_name = &bound_name;
    }

    return pjsip_fake_udp_transport_attach( endpt, sock, a_name, async_cnt,
				       p_transport );
}
Esempio n. 9
0
int nonblock_connect_to(const char * ip,int port, struct sockaddr_in* addr)
{
	int res;

	int fd = create_socket();
	if (fd < 0) 
    {
		return -1;
	}

	int flags = fcntl(fd,F_GETFL,0);
    fcntl(fd, F_SETFL, flags | O_NONBLOCK);
	   
	make_address(addr, ip, port);

	res = connect(fd, (const struct sockaddr*)addr, (socklen_t)sizeof(struct sockaddr));
	if ( res < 0) 
    {
        if(errno == EINPROGRESS)
        {
            return fd;
        }

        close_socket(fd);
        return -1;
    }
	return fd;
}
Esempio n. 10
0
int main(int  argc,
	 char **argv)
{
   SOCKET              listen_sock;
   struct sockaddr_un  addr;
   union conv_sockaddr u_sock_addr;
   int                 len, nb_str;
   char                **print_me;
   listen_sock = create_socket();
   strcpy(addr.sun_path, get_path());
   addr.sun_family = AF_LOCAL;
   u_sock_addr.un = &addr;
   if (connect(listen_sock, u_sock_addr.ad, sizeof(addr)) == -1)
   {
      printf("Client not connected.\n");
      return (-1);
   }
   if ((nb_str =parse_arg(argc, argv, &print_me)) == 0)
      return (close_server(listen_sock));
   for (; nb_str > 0; nb_str--)
   {
      len = strlen(print_me[nb_str - 1]);
      write(listen_sock, &len, sizeof(len));
      write(listen_sock, print_me[nb_str - 1], len);
   }
   close(listen_sock);
   free(print_me);
   return (0);
}
Esempio n. 11
0
int main() {
        init_epoll();
        create_socket();
        setup_signals();

        while (running) {
                struct epoll_event event;
                int ret = epoll_wait(epoll_fd, &event, 1, -1);
                if (ret == 0)
                        continue;

                if (ret < 0) {
                        if (errno == EINTR)
                                continue;

		        syslog(LOG_ERR, "epoll_wait: %s\n", strerror(errno));
                        exit(1);
                }

                if (event.data.ptr == &listen_event)
                        handle_accept(event.events);
                else
                        handle_data(event.data.ptr);
        }

        cleanup();
}
Esempio n. 12
0
void
ipc_init(recieve_callback callback_func)
{
	assert(!initialized);
	callback = callback_func;

#ifdef _WIN32
	int result;
	WSADATA wsaData;

	result = WSAStartup(MAKEWORD(2, 2), &wsaData);
	if(result != 0)
	{
		LOG_ERROR_MSG("Can't initialize Windows sockets");
		return;
	}
#endif

	if(create_socket() != 0)
	{
#ifdef _WIN32
		WSACleanup();
#endif
		initialized = -1;
		return;
	}

	/* FIXME: used to call try_become_a_server() here, but it always succeeds (see
	 *        FIXME comment there), which breaks our logic. */

	atexit(&clean_at_exit);
	initialized = 1;
}
Esempio n. 13
0
static int l2tp_connect(char **arguments)
{
    create_socket(AF_INET, SOCK_DGRAM, arguments[0], arguments[1]);

    while (!local_tunnel) {
        local_tunnel = random();
    }

    log_print(DEBUG, "Sending SCCRQ (local_tunnel = %d)", local_tunnel);
    state = SCCRQ;
    set_message(0, SCCRQ);
    add_attribute_u16(PROTOCOL_VERSION, htons(0x0100));
    add_attribute_raw(HOST_NAME, "anonymous", 9);
    add_attribute_u32(FRAMING_CAPABILITIES, htonl(3));
    add_attribute_u16(ASSIGNED_TUNNEL, local_tunnel);
    add_attribute_u16(WINDOW_SIZE, htons(1));

    if (arguments[2][0]) {
        int fd = open(RANDOM_DEVICE, O_RDONLY);
        if (fd == -1 || read(fd, challenge, CHALLENGE_SIZE) != CHALLENGE_SIZE) {
            log_print(FATAL, "Cannot read %s", RANDOM_DEVICE);
            exit(SYSTEM_ERROR);
        }
        close(fd);

        add_attribute_raw(CHALLENGE, challenge, CHALLENGE_SIZE);
        secret = arguments[2];
        secret_length = strlen(arguments[2]);
    }

    send_packet();
    return TIMEOUT_INTERVAL;
}
Esempio n. 14
0
int netsocket_setup(int argc, char **argv)
{
	cJSON *json;
	struct netsocket_config cfg;
	int error;

	error = read_json(argc, argv, &json);
	if (error)
		return error;

	error = json_to_config(json, &cfg);
	if (error)
		goto end;

	error = create_socket(&cfg);
	if (error)
		goto end;

	error = adjust_mcast_opts(&cfg);
	if (error) {
		close(sk);
		freeaddrinfo(addr_candidates);
		goto end;
	}
	/* Fall through. */

end:
	cJSON_Delete(json);
	return error;
}
Esempio n. 15
0
int
tcp_server_start(struct tundev_context *ctx, uv_loop_t *loop) {
    int rc;

    uv_tcp_init(loop, &ctx->inet_tcp.tcp);

    ctx->inet_tcp_fd = create_socket(SOCK_STREAM, 1);
    if ((rc = uv_tcp_open(&ctx->inet_tcp.tcp, ctx->inet_tcp_fd))) {
        logger_stderr("tcp open error: %s", uv_strerror(rc));
        exit(1);
    }

    uv_tcp_bind(&ctx->inet_tcp.tcp, &ctx->tun->addr, 0);
    if (rc) {
        logger_stderr("tcp bind error: %s", uv_strerror(rc));
        exit(1);
    }

    ctx->inet_tcp.tcp.data = ctx;
    rc = uv_listen(&ctx->inet_tcp.stream, 128, accept_cb);
    if (rc) {
        logger_stderr("tcp listen error: %s", uv_strerror(rc));
        exit(1);
    }
    return rc;
}
struct bt_hci *bt_hci_new_raw_device(uint16_t index)
{
	struct bt_hci *hci;
	struct hci_filter flt;
	int fd;

	fd = create_socket(index, HCI_CHANNEL_RAW);
	if (fd < 0)
		return NULL;

	memset(&flt, 0, sizeof(flt));
	flt.type_mask = 1 << BT_H4_EVT_PKT;
	flt.event_mask[0] = 0xffffffff;
	flt.event_mask[1] = 0xffffffff;

	if (setsockopt(fd, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) {
		close(fd);
		return NULL;
	}

	hci = create_hci(fd);
	if (!hci) {
		close(fd);
		return NULL;
	}

	hci->is_stream = false;

	bt_hci_set_close_on_unref(hci, true);

	return hci;
}
Esempio n. 17
0
int main(int argc, const char *argv[])
{
    const char* host = argv[1];                  // 目标主机
    char send_buff[SEND_BUF_SIZE];               // 发送缓冲区
    char recv_buf[RECV_BUFF_SIZE];               // 接收缓冲区
    size_t to_send_size = 0;                     // 要发送数据大小 
    int client_fd;                               // 客户端socket
    struct addrinfo *addr;                       // 存放getaddrinfo返回数据

    if (argc != 2) {
        printf("Usage:%s [host]\n", argv[0]);
        return 1;
    }


    addr = get_addr(host, "80");
    client_fd = create_socket(addr);
    connect_host(client_fd, addr);
    freeaddrinfo(addr);

    to_send_size = get_send_data(send_buff, SEND_BUF_SIZE, host);
    send_data(client_fd, send_buff, to_send_size);

    recv_data(client_fd, recv_buf, RECV_BUFF_SIZE);

    close(client_fd);
    return 0;
}
Esempio n. 18
0
int
udp_start(struct tundev_context *ctx, uv_loop_t *loop) {
    int rc;

    ctx->network_buffer = malloc(ctx->tun->mtu + PRIMITIVE_BYTES);

    uv_udp_init(loop, &ctx->inet_udp);

    ctx->inet_udp_fd = create_socket(SOCK_DGRAM, mode == xTUN_SERVER ? 1 : 0);
    if ((rc = uv_udp_open(&ctx->inet_udp, ctx->inet_udp_fd))) {
        logger_log(LOG_ERR, "udp open error: %s", uv_strerror(rc));
        exit(1);
    }

#ifdef ANDROID
        rc = protect_socket(ctx->inet_udp_fd);
        logger_log(rc ? LOG_INFO : LOG_ERR, "Protect socket %s",
                   rc ? "successful" : "failed");
#endif

    if (mode == xTUN_SERVER) {
        rc = uv_udp_bind(&ctx->inet_udp, &ctx->tun->addr, UV_UDP_REUSEADDR);
        if (rc) {
            logger_stderr("udp bind error: %s", uv_strerror(rc));
            exit(1);
        }
    }

    return uv_udp_recv_start(&ctx->inet_udp, inet_alloc_cb, inet_recv_cb);
}
Esempio n. 19
0
int main(int argc, char **argv)
{
	struct sigaction actions;

	parse_options(&argc, &argv);

	if (asprintf(&libmemtrace, "%s/libmemtrace.so", lib_path) == -1)
		fatal("asprintf (%s)", strerror(errno));

	create_shmem();

	main_pid = app_start((char **)(argv + 1));

	atexit(cleanup);

	signal(SIGINT, sigint_handler);

	sigemptyset(&actions.sa_mask);
	actions.sa_flags = SA_RESTART;
	actions.sa_handler = sigchld_handler;

	if (sigaction(SIGCHLD, &actions, NULL)) {
		perror("sigaction(SIGCHLD)");
		return 1;
	}

	create_socket();
	create_comm();
	init_server();

	server_run();

	return EXIT_SUCCESS;
}
Esempio n. 20
0
/* *** MAIN *** */
int main(int argc, char* argv[]) {

    Parameters  par;      // in parameters to the operation
    DataMessage rec_msg;  // received message from client

    // create socket and get message from client
    socket_fd = create_socket();
    rec_msg   = rec_message(socket_fd);
    
    // print out received message
    printf("Operation: %s\n",rec_msg.operation);
    printf("Data 1:    %d\n",rec_msg.a);
    printf("Data 2:    %d\n",rec_msg.b);
    printf("------------------------------------\n");

    // initialize container with all functions
    Container func[] = {
                         {Add,"add",22},
                         {Sub,"sub",33},
                         {Mul,"mul",44},
                         {Div,"div",55}
                       };


    // get size of func[]
    int zise = sizeof(func)/sizeof(func[0]);

    int r    = 0;         // return value from string compare, = 0 if hit
    int flag = 0;         // flag indicating valid function selected
    int function_idx = 0; // index for the decoded function

    // compare received string (1st field in DataMessage) with string in Container (2nd field)
    for (int i=0; i<zise; i++) {
        r = strncmp(rec_msg.operation,func[i].xfpstr,3);

        // if entered string equals string in Container then print out
        if (r == 0) {
            printf("Called function: %s - with index: %d\n",func[i].xfpstr,i);
            function_idx = i;
            flag = 1;
        }
    }

    // check if valid function name was sent
    if (flag == 0) {
        printf("Error, invalid function call!\n");
        exit(0);
    }

    // call selected function with its parameters via function pointer
    par.indata1 = rec_msg.a;
    par.indata2 = rec_msg.b;
    strcpy(par.comment,"Test1");
    printf("r1 = %f\n",(*func[function_idx].xfp)(par));
    printf("Spare info (func[]): %d\n",func[function_idx].z);
    printf("------------------------------------\n");

    return 0;
}
/** Open the varp unicast socket.
 *
 * @param addr address 
 * @param port port
 * @param val return parameter for the socket
 * @return 0 on success, error code otherwise
 */
int varp_ucast_open(uint32_t addr, u16 port, int *val){
    int err = 0;
    int flags = (VSOCK_BIND | VSOCK_REUSE);
    dprintf(">\n");
    err = create_socket(SOCK_DGRAM, addr, port, flags, val);
    dprintf("< err=%d val=%d\n", err, *val);
    return err;
}
Esempio n. 22
0
client_win_pipe::client_win_pipe( boost::asio::io_service &ios,
                                  vtrc_client *client,
                                  protocol_signals *callbacks )
    :common::transport_win_pipe(create_socket(ios))
    ,impl_(new impl(ios, client, callbacks ))
{
    impl_->set_parent( this );
}
static void
assert_create_socket_fails(void)
{
  gint sock;

  assert_false(create_socket(&sock), "transport_mapper_open_socket() suceeded unexpectedly");
  assert_gint(sock, -1, "failed create_socket returned a non-extremal value on failure");
}
static void
assert_create_socket_succeeds(void)
{
  gint sock;

  assert_true(create_socket(&sock), "transport_mapper_open_socket() failed unexpectedly");
  close(sock);
}
Esempio n. 25
0
int zmq::ctx_t::terminate ()
{
    // Connect up any pending inproc connections, otherwise we will hang
    pending_connections_t copy = pending_connections;
    for (pending_connections_t::iterator p = copy.begin (); p != copy.end (); ++p) {
        zmq::socket_base_t *s = create_socket (ZMQ_PAIR);
        s->bind (p->first.c_str ());
        s->close ();
    }

    slot_sync.lock ();
    if (!starting) {

#ifdef HAVE_FORK
        if (pid != getpid ()) {
            // we are a forked child process. Close all file descriptors
            // inherited from the parent.
            for (sockets_t::size_type i = 0; i != sockets.size (); i++)
                sockets [i]->get_mailbox ()->forked ();

            term_mailbox.forked ();
        }
#endif

        //  Check whether termination was already underway, but interrupted and now
        //  restarted.
        bool restarted = terminating;
        terminating = true;

        //  First attempt to terminate the context.
        if (!restarted) {
            //  First send stop command to sockets so that any blocking calls
            //  can be interrupted. If there are no sockets we can ask reaper
            //  thread to stop.
            for (sockets_t::size_type i = 0; i != sockets.size (); i++)
                sockets [i]->stop ();
            if (sockets.empty ())
                reaper->stop ();
        }
        slot_sync.unlock();

        //  Wait till reaper thread closes all the sockets.
        command_t cmd;
        int rc = term_mailbox.recv (&cmd, -1);
        if (rc == -1 && errno == EINTR)
            return -1;
        errno_assert (rc == 0);
        zmq_assert (cmd.type == command_t::done);
        slot_sync.lock ();
        zmq_assert (sockets.empty ());
    }
    slot_sync.unlock ();

    //  Deallocate the resources.
    delete this;

    return 0;
}
Esempio n. 26
0
int main(int argc, char *argv[]) {
    int i;

    init();                                 /* Init some variables (like malloc timestamp string, encrypt text string, etc.) */

    check_par(argc, argv);                  /* Check command arguments number */
    open_config(argv);                      /* Open config file and check if it failed */
    open_log(argv);                         /* Open log file and check if it failed */

    get_ipaddr();                           /* Get server IP address */

    create_socket();                        /* Create a socket */
    bind_socket();                          /* Bind the socket */
    listen_socket();                        /* Listen at the socket */

    print_server_info();                    /* Print server information */

    while (TRUE) {                          /* Read until the end of file */
        if (read_flag) {
            if (fscanf(fcfg, "%s", enc_txt) == EOF) {
                finish_flag = 1;
                break;
            } else {
                fscanf(fcfg, "%s", dec_txt);
            }
        }
        read_flag = 0;

        init_select();                      /* Select function */
        if (select_func() == -1) break;

        for (i = 0; i < max_fds + 1; i++) {
            if (FD_ISSET(i, &rfds)) {
                if (i == sockfd) {                              /* If have a new client connect */
                    if (accept_new_cli() == -1) break;          /* Try to accept new client */
                    if (check_connect() == -1) break;           /* Check connect message from client */
                    if (print_client_info() == -1) break;       /* Print the information of client side */
                    store_client_ip();                          /* Store the client ip address */
                    break;
                } else {                                        /* If have new message from client side */
                    client_ip = get_host_by_sockfd(i);          /* Get the client ip address by socket */
                    recv_socket_msg(i, recv_mark);              /* Get the message from socket */
                    handle_client_msg(i);                       /* Handle client message (SUCCESS_MSG, FAILURE_MSG, DISPATCH_MSG, etc.) */
                    break;
                }
            }
            if (main_flag == EXIT_FAILURE) break;
        }
        if (main_flag == EXIT_FAILURE) break;
    }

    remained_cli = ask_clients_quit();                          /* Ask clients quit and count the remain clients number */
    wait_clients_quit();                                        /* Wait for all clients quit */
    quit_server();                                              /* Clean up and quit server, also print the message to log */

    return main_flag;
}
Esempio n. 27
0
SOCKET create_socket_by_service(char *hostname, char *servicename, char *proto,
                                int action) {
  struct servent *sp = getservbyname(servicename, proto);

  if (sp == NULL)
    return INVALID_SOCKET;

  return create_socket(hostname, sp->s_port, proto, action);
}
Esempio n. 28
0
void Server::initialize(char* port) {
	struct sockaddr_in addr;
	addr.sin_family = AF_INET;
	addr.sin_port = htons(atoi(port));
	addr.sin_addr.s_addr = htonl(INADDR_ANY);
	create_socket();
	bind((struct sockaddr *) &addr, sizeof(addr));
	listen(5);
}
Esempio n. 29
0
/* constuctor */
RawSocket::RawSocket(uint32_t dip, uint16_t dp, uint16_t sp)
{
   fd = 0;
   memset(&dst_sin_, 0, sizeof(struct sockaddr_in));
   isOpen = false;

   create_socket();
   open(dip, dp, sp);
}
Esempio n. 30
0
int main(int argc, char** argv)
{
    int fd0 = create_socket(0);
    int fd1 = create_socket(1);

    int ret = send(fd1, "ATTACH", 6, 0);
    printf("send ret is %d. start recv,.....\n", ret);

    struct pollfd *fds = malloc(2 * sizeof(struct pollfd));
    bzero(fds, sizeof(struct pollfd) * 2);

    int poll_cnt = 2;
    fds[0].fd = fd0;
    fds[0].events = POLLIN;
    
    fds[1].fd = fd1;
    fds[1].events = POLLIN;

    while (1)
    {
        int ret = poll(fds, poll_cnt, -1);

        if (ret < 0)
        {
            perror("poll error:");
            continue;
        }

        if (fds[0].revents & POLLIN)
        {
            char buf[256];
            ret = recv(fds[0].fd, buf, sizeof(buf), 0);
            printf("0 receive ret is %d [%s].\n", ret, buf);
        }
        
        if (fds[1].revents & POLLIN)
        {
            char buf[256];
            ret = recv(fds[1].fd, buf, sizeof(buf), 0);
            printf("1 receive ret is %d [%s].\n", ret, buf);
        }

    }
}