Example #1
0
int				ft_get_data(t_hall **hall)
{
	char	*note;
	char	*line;
	int		ret;

	ret = 0;
	note = NULL;
	line = NULL;
	while ((ret = ft_gnl(0, &line)) > 0 && ft_strchr(line, '-') == 0)
	{
		if ((ret = get_hall(hall, &line, &note)) < 0)
			return (ret);
		ft_putstr_double(line, '\n');
		ft_clean_str(&line);
	}
	if (ret < 1)
	{
		if (ret == 0)
			ret = -2;
		return (ret);
	}
	if (note)
		ft_clean_str(&note);
	if ((ret = get_connect(hall, &line)) < 0)
		return (ret);
	return (0);
}
Example #2
0
int main(int argc, char *argv[])
{
    int sockfd, portno, n, fileSize, readSize;
    FILE *file =  fopen("recieved.file","w");
    char buffer[LENGTH];
    printf("start\n");
    portno = atoi(argv[2]);
    sockfd = get_connect(argv[1],portno);
    printf("connected %d",sizeof(argv[3]));
    puts(argv[3]);
    bzero(buffer,LENGTH);

    send(sockfd, argv[3], strlen(argv[3]), 0);
    recv(sockfd, buffer, LENGTH, 0);
    fileSize = atoi(buffer);
    readSize = 0;
    bzero(buffer,LENGTH);
    while (readSize< fileSize) {
        int r = recv(sockfd, buffer, LENGTH, 0);
        readSize += r;
        fwrite(buffer, 1, r, file);
    }
    printf("read size%d\n filesize %d\n",readSize,fileSize);
    return 0;
}
Example #3
0
int
readerInit(void)
{
	if ((wilyfd = get_connect()) < 0) {
		DPRINT("Could not connect to wily");
		return 1;
	}
	mq_init(wilyq, wilyfd);
	return 0;
}
Example #4
0
void connect_goagent(GtkWidget *widget,DATA *data)
{
	/*如果off为开,则当前已经启动*/
	if(data->off)
	{
		message_box(widget,_("Connected Now\n"));
		return;
	}

	if(!is_python_and_goagent_path(data->python_path,data->proxy_py_path))
		return;

	get_connect(data);
	data->off=1;
}
Example #5
0
File: e.c Project: knusbaum/Wily
/* Open fifos to wily.
 */
void
connect_wily(char *file, char *addr)
{
	char	envbuf[300];

	msg_init(&m);

	towily = fromwily = get_connect(file);

	if(towily<0) {
		perror("connect failed\n");
		exit(1);
	}
	DPRINT("in %d, out %d\n", fromwily, towily);

	wm_read(towily, true, 0, 0, addr);
}
Example #6
0
int main(int argc, char *argv[]){
    MYSQL *connect;
    SQL_ROW_DATA row_data;
    MYSQL_CONNECT_CONF conConf = {
        "xxx.xxx.xxx.xxx",
        "user",
        "pwd",
        "db",
        3306,
        NULL,
        0,
        "utf8"
    };
    
    connect = get_connect(conConf);
    row_data = execute_sql(connect, "SELECT *  FROM tb LIMIT 1000 ");
    if(row_data.row_num > 0){
        printf("-----------has rows-----------\n");

        // 输出第一条
        /*
        if( (row_data.rows[0].cols[3].name) && (row_data.rows[0].cols[3].data) ){
            fprintf(stderr, "[*] \t%s = %s\n", row_data.rows[0].cols[3].name, row_data.rows[0].cols[3].data);
        }
        */

        // 全部输出
        print_rows(row_data);

    }else{
        printf("---------------no rows-------------\n");
    }
    free_data_rows(row_data);
    mysql_close(connect);

    return 0;
}
Example #7
0
int main(int argc, char * argv[]) 
{
    int ix, iy, c;
    concurrency = 10;
    request_nums = 1000;
    round_nums = 1;
    conn_type = 0; // 1 - long ; 0 - short
    char * host = NULL;
    int port = -1;

    while ( (c = getopt(argc, argv, "c:n:r:t:h:p:")) != -1) {
	switch (c) {
	    case 'c':
		concurrency = atoi (optarg);
		break;
	    case 'n':
		request_nums = atoi (optarg);
		break;
	    case 'r':
		round_nums = atoi (optarg);
		break;
	    case 't':
	        conn_type = atoi (optarg);
		break;
	    case 'h':
		host = strdup (optarg);
		break;
	    case 'p':
		port = atoi (optarg);
		break;
	    default:
		fprintf (stderr, "usage: bench -c -n -r -t\n");
		exit(-1);
	}
    }

    if (host == NULL) 
	host = strdup (host_def);

    if (port == -1) 
	port = port_def;

    // calc the run_nums in one round
    run_nums = request_nums / concurrency;
    if (run_nums < 1) {
	fprintf (stderr, "requset is less than concurrency\n");
	exit (-1);
    }

    // create the sockets
    fds = (int*)malloc(sizeof(int) * concurrency);
    if (fds == NULL) {
	fprintf (stderr, "malloc for fds failed\n");
	exit (-1);
    }
    
    // connect 
    int fd_tmp;
    int concurrency_tmp = concurrency;
    int connect_fail = 0;
    for (ix = 0, iy = 0; ix < concurrency; ix++) {
	fd_tmp = get_connect (host, port);
	if (fd_tmp == -1) {
	    concurrency_tmp -= 1;
	    connect_fail += 1;
	    continue;
	}
	fds[iy++] = fd_tmp;
    }

    // judge
    if (connect_fail == concurrency) {
	fprintf (stderr, "All Connect Failed\n");
	exit (-1);
    }

    concurrency = concurrency_tmp;
    fprintf (stdout, "connect fail : %d\n", connect_fail);

    // create events
    events = (struct event*)malloc(sizeof(struct event) * concurrency);
    if (events == NULL) {
	fprintf (stderr, "Malloc For events Failed\n");
	exit (-1);
    }

    event_init();

    struct timeval ts, te, ta;
    int r_num = 0;
    gettimeofday (&ts, NULL);
    int round_nums_tmp = round_nums;
    while ( (round_nums_tmp--) > 0) {
	r_num += 1;
	run_once(run_nums);
	fprintf (stdout, "%d round finish\n", r_num);
    }
    gettimeofday (&te, NULL);

    lisatimersub (&te, &ts, &ta);


    /* 
       Output 
     */
    fprintf (stdout, "\n\n");
    fprintf (stdout, "Service Name : %s\n", host);
    fprintf (stdout, "Service Port : %d\n", port);
    fprintf (stdout, "\n");

    fprintf (stdout, "Concurrency Level : \t\t%10d\n", concurrency);
    fprintf (stdout, "Requests Nums : \t\t%10d\n", request_nums * round_nums);
    fprintf (stdout, "Round Nums : \t\t\t%10d\n", round_nums);
    fprintf (stdout, "\n");

    double spend_time = (double)ta.tv_sec + (double)(ta.tv_usec) / 1000000;
    fprintf (stdout, "Time taken for tests : \t%20.10g seconds\n", spend_time);
    fprintf (stdout, "Requests per seconds : \t%20.10g [#/sec]\n", \
	                   (double)(request_nums * round_nums) / spend_time);

    return 0;
}