• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ send_data函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中send_data函数的典型用法代码示例。如果您正苦于以下问题:C++ send_data函数的具体用法?C++ send_data怎么用?C++ send_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了send_data函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: server_look

void server_look(int conn_fd, char * local_path)
{

	char server_path[SIZE];
	char  filename[SIZE];
	char file_path[SIZE];
	char len[SIZE];
	char tmp[SIZE] = {"\n\n\t\t.\n\n\t\t.."};
	struct dirent * ptr;
	struct stat buf;
	DIR  * dir;
	int fd;
	char name[SIZE][SIZE];
	int i = 0;
	int num;
	char log[SIZE];
	char log_path[SIZE];

	strcpy(log_path, local_path);
	memset(log, '\0', sizeof(log));
	strcpy(log, "浏览服务器目录:");
	strcat(log, log_path);
	sys_log(log);
	stat (local_path, &buf);
	if (S_ISREG(buf.st_mode))
	{
		;
	}
	chdir(local_path);
	getcwd(file_path, sizeof(file_path));
	file_path[strlen(file_path)] = '/';
	file_path[strlen(file_path) + 1] = '\0';
	dir = opendir(file_path);
	while ((ptr = readdir(dir)) != NULL)
	{
		if (strcmp(ptr->d_name, ".") && strcmp(ptr->d_name, ".."))
		{
			strcat(tmp, "\n\n\t\t");
			strcat(tmp, ptr->d_name);
			strcpy(name[i++], ptr->d_name);
		}
	}
	strcat(tmp, "\n请选择要保存的位置\n..返回上层目录\n");
	send(conn_fd, tmp, SIZE, 0);
	recv(conn_fd, filename, SIZE, 0);
	if (strcmp(filename, "1") == 0)
	{
		recv(conn_fd, filename, SIZE, 0);
		mkdir(filename, 0777);
		chdir(filename);
		sys_log("进入新建文件夹目录");
		server_look(conn_fd, filename);
	}
	else if (strcmp (filename, "2") == 0)
	{
loop:
		num = i - 1;
		recv(conn_fd, filename, SIZE, 0);
		for (; num >= 0; num--)
		{
			if (strcmp(filename, name[num]) == 0)
			{
				send_data(conn_fd, "n\n");
				goto loop;
			}
		}
		send_data(conn_fd, "y\n");
		recv(conn_fd, len, SIZE, 0);
		server_recv(conn_fd, filename, len);

	}	
	else if (strncmp(filename, "..", 2) == 0)
	{
		server_look(conn_fd, "..");
	}
	else 
	{
		server_look(conn_fd, filename);
	}
}
开发者ID:Gaoyuan0710,项目名称:MyFtp,代码行数:80,代码来源:server.c


示例2: vec2elemental

int vec2elemental(const std::vector<double> &vec, El::DistMatrix<El::Complex<double>,El::VC,El::STAR> &Y){

	int data_dof=2;
	int SCAL_EXP = 1;

	int nlocal,gsize; //local elements, start p_id, global size
	double *pt_array; // will hold local array
	int r,q,rq; //Grid sizes
	int nbigs; //Number of large sends (i.e. send 1 extra data point)
	int pstart; // p_id of nstart
	int rank = El::mpi::WorldRank(); //p_id
	int send_size; // base send size
	bool print = rank == -1; 


	// Get Grid and associated params
	const El::Grid* g = &(Y.Grid());
	r = g->Height();
	q = g->Width();
	MPI_Comm comm = (g->Comm()).comm;

	// Get sizes, array in petsc 
	nlocal = vec.size()/data_dof;
	int nstart = 0;
	MPI_Exscan(&nlocal,&nstart,1,MPI_INT,MPI_SUM,comm);
	//VecGetOwnershipRange(pt_vec,&nstart,NULL);

	//Find processor that nstart belongs to, number of larger sends
	rq = r * q;
	pstart = nstart % rq; //int div
	nbigs = nlocal % rq;
	send_size = nlocal/rq;
	
	if(print){
		std::cout << "r: " << r << " q: " << q <<std::endl;
		std::cout << "nstart: " << nstart << std::endl;
		std::cout << "ps: " << pstart << std::endl;
		std::cout << "nbigs: " << nbigs << std::endl;
		std::cout << "send_size: " << send_size << std::endl;
	}

	// Make send_lengths
	std::vector<int> send_lengths(rq);
	std::fill(send_lengths.begin(),send_lengths.end(),send_size);
	if(nbigs >0){
		for(int j=0;j<nbigs;j++){
			send_lengths[(pstart + j) % rq] += 1;
		}
	}

	// Make send_disps
	std::vector<int> send_disps = exscan(send_lengths);

	std::vector<El::Complex<double>> indata(nlocal);
	// copy the data from an ffm tree to into a local vec of complex data for sending #pragma omp parallel for
	El::Complex<double> val;
	for(int i=0;i<nlocal;i++){
		El::SetRealPart(val,vec[2*i+0]);
		El::SetImagPart(val,vec[2*i+1]);
		indata[i] = val;
	}


	// Make send_dataA, i.e. reorder the data
	std::vector<El::Complex<double>> send_data(nlocal);
	for(int proc=0;proc<rq;proc++){
		int offset = send_disps[proc];
		int base_idx = (proc - pstart + rq) % rq; 
		for(int j=0; j<send_lengths[proc]; j++){
			int idx = base_idx + (j * rq);
			send_data[offset + j] = indata[idx];
		}
	}

	// Do all2all to get recv_lengths
	std::vector<int> recv_lengths(rq);
	MPI_Alltoall(&send_lengths[0], 1, MPI_INT, &recv_lengths[0], 1, MPI_INT,comm);

	// Scan to get recv_disps
	std::vector<int> recv_disps = exscan(recv_lengths);

	// Do all2allv to get data on correct processor
	El::Complex<double> * recv_data = Y.Buffer();
	//MPI_Alltoallv(&send_data[0],&send_lengths[0],&send_disps[0],MPI_DOUBLE, \
	//		&recv_data[0],&recv_lengths[0],&recv_disps[0],MPI_DOUBLE,comm);
	El::mpi::AllToAll(&send_data[0], &send_lengths[0], &send_disps[0], recv_data,&recv_lengths[0],&recv_disps[0],comm);

	if(print){
		std::cout << "Send data: " <<std::endl << send_data <<std::endl;
		std::cout << "Send lengths: " <<std::endl << send_lengths <<std::endl;
		std::cout << "Send disps: " <<std::endl << send_disps <<std::endl;
		std::cout << "Recv data: " <<std::endl << recv_data <<std::endl;
		std::cout << "Recv lengths: " <<std::endl << recv_lengths <<std::endl;
		std::cout << "Recv disps: " <<std::endl << recv_disps <<std::endl;
	}

	return 0;
}
开发者ID:kwkelly,项目名称:invmed_rewrite,代码行数:98,代码来源:convert_elemental.cpp


示例3: process_rmsreq

// Process RMSREQ command
// This command returns averaged RMS values for a given channel
void process_rmsreq(
  const char  *rq_station,   // station name
  const char  *rq_chan,      // Channel ID
  const char  *rq_loc,       // Location ID
  STDTIME2    rq_tBeginTime, // Start time
  long        rq_iSamples    // Number of data points to transfer
  )
{
 char loglocation[4] ;
 char logchannel[4] ;
 char str_record[8192];
 char log_msg[8192];
 char msgbuf[512];
 char loopDir[MAXCONFIGLINELEN+1];
 char buf_filename[2*MAXCONFIGLINELEN+2];
 static char looperrstr[MAXCONFIGLINELEN+2];
 char *errmsg;
 char *msgptr;
 int prslen ;
 int badval ;
 int          iLoopRecordSize;
 int          indexFirst;
 int          indexLast;
 int          iStart;
 int          iCount;
 int          iLoopSize;
 int          iSample;
 int          iTry;
 int          iEmpty;
 int          iRecord;
 int          iSeek;
 STDTIME2     rq_tEndTime;
 STDTIME2     startTime;
 FILE         *fp_buf;
 seed_header  *pheader;

 // Parse and validate log [location-]channel
 strcpy(loglocation, "  ") ;
 ++cmdcnt ;
 parse_request(' ') ;
 prslen = strlen(prsbuf) ;
 badval = 0 ;
 switch (prslen)
 {
  case 3 :
   memcpy(logchannel, prsbuf, 4);
   break ;
  case 5 :
   if (prsbuf[1] == '-')
    {
     memcpy(loglocation, prsbuf, 1) ;
     loglocation[1] = 0;
     memcpy(logchannel, &prsbuf[2], 4) ;
    }
   else
    badval = 1 ;
   break ;
  case 6 :
   if (prsbuf[2] == '-')
   {
    memcpy(loglocation, prsbuf, 2) ;
    loglocation[2] = 0;
    memcpy(logchannel, &prsbuf[3], 4) ;
   }
   else
    badval = 1 ;
   break ;
  default :
   badval = 1 ;
 }
 if (badval == 1)
 {
  send_data ("Invalid log [location-]channel name\n");
  return ;
 }

fprintf(stderr, 
"DEBUG process RMSREQ %s.%s-%s in %s-%s %d,%d,%02d:%02d:%02d %ld %s-%s\n",
rq_station,rq_loc,rq_chan, loglocation, logchannel,
rq_tBeginTime.year, rq_tBeginTime.day,
rq_tBeginTime.hour, rq_tBeginTime.minute, rq_tBeginTime.second,
rq_iSamples, loglocation, logchannel);

  // Get index of first record for this data request
  startTime = ST_AddToTime2(rq_tBeginTime, 0, -1, 0, 0, 0);
  rq_tEndTime = rq_tBeginTime;
  rq_tEndTime.year = 3000; // give max year as end time
  LoopRecordSize(&iLoopRecordSize);
  errmsg = GetRecordRange(rq_station, logchannel, loglocation,
             startTime, rq_tEndTime,
             &indexFirst, &indexLast, &iCount, &iLoopSize);
  if (errmsg != NULL)
  {
    sprintf(msgbuf, "%s\n", errmsg);
    send_data(msgbuf);
    return;
  }
fprintf(stderr, "indexFirst=%d, indexLast=%d, iCount=%d, iLoopSize=%d\n",
//.........这里部分代码省略.........
开发者ID:jandog8990,项目名称:asl-station-processor,代码行数:101,代码来源:aslreq.c


示例4: typing_func

void* typing_func(void) {

    char message_buffer[LENGHT_MESSAGE];
    char message_buffer_2[LENGHT_MESSAGE];
    char confirm_file[LENGHT_MESSAGE];
    char filename[LENGHT_MESSAGE];
    char ch;
    int buffer_int;
    FILE *fp;

    while (state == 0) {

        //Reset string for get new message
        strcpy(message_buffer, "");
        strcpy(message_buffer_2, "");

        wscanw(global_typing, " %[^\n]s", message_buffer);
        while (strlen(message_buffer) > 200) {
            werase(global_typing);
            draw_new(global_display, "system>> Message cannot more than 200 characters.");
            wscanw(global_typing, " %[^\n]s", message_buffer);
        }

        //Draw_new line to display message
        strcpy(message_buffer_2, "you>> ");
        strcat(message_buffer_2, message_buffer);
        draw_new(global_display, message_buffer_2);


        //Check exit command
        if (strcmp(message_buffer, ":q!") == 0) {
            //set state to stop all function
            state = 1;
        }
        else if (message_buffer[0] == '/') {

            if (split_strcmp(0, 6, "/upload", 0, 6, message_buffer)){

                split_str(8, strlen(message_buffer), message_buffer, filename);
                sprintf(message_buffer, "3system>> Sending file to you: %s", filename);
                send_data(message_buffer);

                sleep(1);

                draw_new(global_display, "system>> Uploading...");

                fp = fopen(filename, "r");
                while( ( ch = fgetc(fp) ) != EOF ){

                    sprintf(message_buffer, "4%c", ch);

                    if(send_data(message_buffer) == 0)
                        draw_new(global_display, "system>> Send failed");

                }
                fclose(fp);

                sleep(1);

                strcpy(message_buffer, "5");
                send_data(message_buffer);
                draw_new(global_display, "system>> Done!");

            }
            else if (split_strcmp(0, 2, "/up", 0, 2, message_buffer)){

                split_str(4, strlen(message_buffer), message_buffer, message_buffer_2);
                buffer_int = atoi(message_buffer_2);
                draw_old_line(global_display, 1, buffer_int);

            }
            else if (split_strcmp(0, 4, "/down", 0, 4, message_buffer)){

                split_str(6, strlen(message_buffer), message_buffer, message_buffer_2);
                buffer_int = atoi(message_buffer_2);
                draw_old_line(global_display, 2, buffer_int);

            }
            else if (split_strcmp(0, 4, "/help", 0, 4, message_buffer)){

                draw_new(global_display, "system>> ### THIS IS HELP! ###");
                draw_new(global_display, "system>> \":q!\" to exit program.");
                draw_new(global_display, "system>> \"/talkto [nickname]\" to choose contact.");
                draw_new(global_display, "system>> \"/untalk\" to remove contact that we are talking.");
                draw_new(global_display, "system>> \"/upload [file]\" to upload file to client that you are talking.");
                draw_new(global_display, "system>> \"/watline\" to show number of latest line");
                draw_new(global_display, "system>> \"/up [amount of line]\" to scroll screen up n lines.");
                draw_new(global_display, "system>> \"/down [amount of line]\" to scroll screen down n lines.");
                draw_new(global_display, "system>> \"/find [word]\" to find number of line that word was display.");
                draw_new(global_display, "system>> \"/contact\" to show all user on server.");

            }
            else if (split_strcmp(0, 4, "/find", 0, 4, message_buffer)){

                split_str(6, strlen(message_buffer) - 1, message_buffer, message_buffer_2);
                search(message_buffer_2, global_display);

            }
            else if (split_strcmp(0, 7, "/watline", 0, 7, message_buffer)){

//.........这里部分代码省略.........
开发者ID:chin8628,项目名称:terminal-s-chat,代码行数:101,代码来源:socket_client.c


示例5: where_to_send

/**
 * Avalia se o pacote deve ser redirecionado ou salvo.
 * @param packet Ponteiro para o pacote.
 * @param usage_type Tipo do cliente que está chamando a função.
 * @return 0 em falha e !0 em sucesso.
 */
int where_to_send(char *packet, usage_type_t usage_type)
{
	struct iphdr *ip;
	struct udphdr *udp;
	struct data_info *data;
	struct in_addr tmp;
	int ret;

	ip = (struct iphdr *)packet;
	udp = get_udp_packet(packet);

	/* Verifica a sanidade do pacote, se estiver com erro, dropa */
	if (!sanity_check(ip)) {
		printf("Packet received with error, dropping.\n");
		cstats.lost_pkts++;
		return 0;
	}

	switch (usage_type) {
		case ROUTER_USAGE:
			/* Router esta fazendo forward do pacote, subtrai ttl */
			ip->ttl -= IPTTLDEC;
			ip->check = 0;
			ip->check = in_cksum((unsigned short *)ip, ip->tot_len);
			cstats.fw_pkts += ip->tot_len;
			printf("Forwarding packet:\n");
			printf("\tPacket ttl %d\n", ip->ttl);
			printf("\tPacket size: %d bytes\n", ip->tot_len);
			tmp.s_addr = ip->saddr;
			printf("\tFrom: %s\n", inet_ntoa(tmp));
			tmp.s_addr = ip->daddr;
			printf("\tTo: %s\n", inet_ntoa(tmp));
			if ((ret = send_data(packet)) < 0) {
				printf("* Error forwarding packet. *\n");
				cstats.lost_pkts++;
			}
			break;
		default:
			data = get_packet_data(packet);
			if (data->fragmented) {
				save_packet_fragment(data);
				if (is_packet_complete(data)) {
					/* Se o pacote for um fragmento e completar o dado, salva e
					 * remove do buffer */
					printf("Fragmented Data complete.\n");
					struct data_info *dinfo = get_defragmented_data(data->id);
					ret = save_data(dinfo);

					cstats.recv_pkts += ip->tot_len;
					printf("Data received:\n");
					printf("\tPacket: %lld bytes\n", dinfo->tot_len);
					tmp.s_addr = ip->saddr;
					printf("\tFrom: %s\n", inet_ntoa(tmp));

					printf("\tFile Name: %s\n", ((char *)dinfo + sizeof(struct data_info)));
					printf("\tFile size: %ld bytes\n", dinfo->data_size);
				} else {
					/* Se o pacote for um fragmento, apenas adiciona ao buffer e
					 * adiciona seus dados à estatística. */
					cstats.recv_pkts += ip->tot_len;
					printf(".");
					ret = 0;
				}
				break;
			}
			/* Se o pacote não for um fragmento, salva e adiciona seus dados à
			 * estatística. */
			ret = save_data(data);
			cstats.recv_pkts += ip->tot_len;
			printf("Data received:\n");
			printf("\tPacket: %d bytes\n", ip->tot_len);
			tmp.s_addr = ip->saddr;
			printf("\tFrom: %s\n", inet_ntoa(tmp));
			printf("\tFile Name: %s\n", ((char *)data + sizeof(struct data_info)));
			printf("\tFile size: %ld bytes\n", data->data_size);

			break;
	}

	return ret;
}
开发者ID:strcp,项目名称:teleproc_1,代码行数:87,代码来源:listener.c


示例6: send_commands

void send_commands()
{
    kvstore_cmd_t cmd;
    kvstore_ack_t ack;
    char buf[100];
    const char *delims = " ";
    char * parsed;
    int len;

    /* FIXME for now. Improve this by using a more
     * appropriate parser */
    char *op, *kv_key, *kv_val;
    //int ret;

    memset(&cmd, 0, sizeof(kvstore_cmd_t));
    memset(&ack, 0, sizeof(kvstore_ack_t));

    do {
        memset(buf, 0, sizeof(buf));

        printf("\n(kv) ");
        fflush(stdout);
        fgets(buf, sizeof(buf), stdin);

        parsed = strdup(buf);
        str_trim(&parsed);
        len = strlen(parsed);

        if (len == 0) {
            continue;
        }

        op = strtok(parsed, delims);

        // get the op
        kvstore_type_t kv_type = get_type(op);
        if (kv_type == KVSTORE_NONE) {
            printf("ERROR: Invalid Operation");
            continue;
        }

        switch (kv_type) {
            case KVSTORE_EXIT: return;
            default: break;
        }

        // get the key and message
        kv_key = strtok(NULL, delims);
        if (kv_key == NULL) {
            printf("ERROR: Invalid Operation");
            continue;
        }

        // if we're just using get
        if (kv_type == KVSTORE_GET) {
            kv_val = "";
        } else {
            kv_val = strtok(NULL, "\0");
        }

        // set the code and message then encrypt
        memset(&cmd, 0, sizeof(cmd));
        cmd.type = kv_type;
        strncpy((char *)&cmd.payload.key, kv_key, KVSTORE_KEY_LEN);
        strncpy((char *)&cmd.payload.val, kv_val, KVSTORE_VAL_LEN);

        cmd.payload.key[strlen(kv_key)] = '\0';
        // copy the IV
        memcpy(cmd.iv, iv, KVSTORE_AESIV_LEN);

        aes_setkey_enc(&aes, enckey, KVSTORE_AESKEY_BITS);
        aes_crypt_cbc(&aes, AES_ENCRYPT, sizeof(cmd.payload), iv,
                (const unsigned char *)&cmd.payload,
                (unsigned char *)&cmd.payload);

        if (send_data(&pfd, &cmd, sizeof(cmd))) {
            goto exit;
        }

        if (kv_type == KVSTORE_SET) {
            // just get the acknowledgement
            // TODO check content
            if (get_ack(&pfd, &ack)) {
                goto exit;
            }
            printf("OK");
        } else if (kv_type == KVSTORE_GET) {
            // get the data
            if(get_resp(&pfd, &cmd)) {
                goto exit;
            }
            aes_setkey_dec(&aes, enckey, KVSTORE_AESKEY_BITS);
            // now decrypt
            aes_crypt_cbc(&aes, AES_DECRYPT, sizeof(cmd.payload), cmd.iv,
                (const unsigned char *)&cmd.payload,
                (unsigned char *)&cmd.payload);
            printf("%s", cmd.payload.val);
        }

        // printf("op: %s, title: %s, data: %s\n", op, kv_key, kv_msg);
//.........这里部分代码省略.........
开发者ID:sporgj,项目名称:janusSGX,代码行数:101,代码来源:kvstore_client.c


示例7: mitsu70x_main_loop

static int mitsu70x_main_loop(void *vctx, int copies) {
	struct mitsu70x_ctx *ctx = vctx;

	struct mitsu70x_state rdbuf, rdbuf2;

	int last_state = -1, state = S_IDLE;
	int ret;

	if (!ctx)
		return CUPS_BACKEND_FAILED;

top:
	if (state != last_state) {
		if (dyesub_debug)
			DEBUG("last_state %d new %d\n", last_state, state);
	}

	ret = mitsu70x_get_state(ctx, &rdbuf);
	if (ret)
		return CUPS_BACKEND_FAILED;

	if (memcmp(&rdbuf, &rdbuf2, sizeof(rdbuf))) {
		memcpy(&rdbuf2, &rdbuf, sizeof(rdbuf));
	} else if (state == last_state) {
		sleep(1);
	}
	last_state = state;

	fflush(stderr);

	switch (state) {
	case S_IDLE:
		INFO("Waiting for printer idle\n");
#if 0 // XXX no idea if this works..
		if (rdbuf.data[9] != 0x00) {
			break;
		}
#endif
		INFO("Sending attention sequence\n");
		if ((ret = send_data(ctx->dev, ctx->endp_down,
				     ctx->databuf, 512)))
			return CUPS_BACKEND_FAILED;

		state = S_SENT_ATTN;
		break;
	case S_SENT_ATTN: {
		struct mitsu70x_status_resp resp;
		ret = mitsu70x_get_status(ctx, &resp);
		if (ret < 0)
			return CUPS_BACKEND_FAILED;

		/* Yes, do it twice.. */

		ret = mitsu70x_get_status(ctx, &resp);
		if (ret < 0)
			return CUPS_BACKEND_FAILED;

		// XXX check resp for sanity?

		state = S_SENT_HDR;
		break;
	}
	case S_SENT_HDR:
		INFO("Sending Page setup sequence\n");
		if ((ret = mitsu70x_do_pagesetup(ctx)))
			return ret;

		INFO("Sending header sequence\n");

		/* K60 may require fixups */
		if (ctx->k60) {
			/* K60 only has a lower deck */
			ctx->databuf[512+32] = 1;

			/* 4x6 prints on 6x8 media need multicut mode */
			if (ctx->databuf[512+16] == 0x07 &&
			    ctx->databuf[512+16+1] == 0x48 &&
			    ctx->databuf[512+16+2] == 0x04 &&
			    ctx->databuf[512+16+3] == 0xc2) {
				ctx->databuf[512+48] = 1;
			}
		}

		if ((ret = send_data(ctx->dev, ctx->endp_down,
				     ctx->databuf + 512, 512)))
			return CUPS_BACKEND_FAILED;

		INFO("Sending data\n");

		if ((ret = send_data(ctx->dev, ctx->endp_down,
				     ctx->databuf + 1024, ctx->datalen - 1024)))
			return CUPS_BACKEND_FAILED;

		state = S_SENT_DATA;
		break;
	case S_SENT_DATA:
		INFO("Waiting for printer to acknowledge completion\n");

		state = S_FINISHED;
		break;
//.........这里部分代码省略.........
开发者ID:koenkooi,项目名称:gutenprint,代码行数:101,代码来源:mitsu70x_print.c


示例8: tftp_send

/*
 * Send a file via the TFTP data session.
 */
void
tftp_send(int peer, uint16_t *block, struct tftp_stats *ts)
{
	struct tftphdr *rp;
	int size, n_data, n_ack, try;
	uint16_t oldblock;
	char sendbuffer[MAXPKTSIZE];
	char recvbuffer[MAXPKTSIZE];

	rp = (struct tftphdr *)recvbuffer;
	*block = 1;
	ts->amount = 0;
	do {
		if (debug&DEBUG_SIMPLE)
			tftp_log(LOG_DEBUG, "Sending block %d", *block);

		size = read_file(sendbuffer, segsize);
		if (size < 0) {
			tftp_log(LOG_ERR, "read_file returned %d", size);
			send_error(peer, errno + 100);
			goto abort;
		}

		for (try = 0; ; try++) {
			n_data = send_data(peer, *block, sendbuffer, size);
			if (n_data > 0) {
				if (try == maxtimeouts) {
					tftp_log(LOG_ERR,
					    "Cannot send DATA packet #%d, "
					    "giving up", *block);
					return;
				}
				tftp_log(LOG_ERR,
				    "Cannot send DATA packet #%d, trying again",
				    *block);
				continue;
			}

			n_ack = receive_packet(peer, recvbuffer,
			    MAXPKTSIZE, NULL, timeoutpacket);
			if (n_ack < 0) {
				if (n_ack == RP_TIMEOUT) {
					if (try == maxtimeouts) {
						tftp_log(LOG_ERR,
						    "Timeout #%d send ACK %d "
						    "giving up", try, *block);
						return;
					}
					tftp_log(LOG_WARNING,
					    "Timeout #%d on ACK %d",
					    try, *block);
					continue;
				}

				/* Either read failure or ERROR packet */
				if (debug&DEBUG_SIMPLE)
					tftp_log(LOG_ERR, "Aborting: %s",
					    rp_strerror(n_ack));
				goto abort;
			}
			if (rp->th_opcode == ACK) {
				ts->blocks++;
				if (rp->th_block == *block) {
					ts->amount += size;
					break;
				}

				/* Re-synchronize with the other side */
				(void) synchnet(peer);
				if (rp->th_block == (*block - 1)) {
					ts->retries++;
					continue;
				}
			}

		}
		oldblock = *block;
		(*block)++;
		if (oldblock > *block) {
			if (options[OPT_ROLLOVER].o_request == NULL) {
				/*
				 * "rollover" option not specified in
				 * tftp client.  Default to rolling block
				 * counter to 0.
				 */
				*block = 0;
			} else {
				*block = atoi(options[OPT_ROLLOVER].o_request);
			}

			ts->rollovers++;
		}
		gettimeofday(&(ts->tstop), NULL);
	} while (size == segsize);
abort:
	return;
}
//.........这里部分代码省略.........
开发者ID:ele7enxxh,项目名称:dtrace-pf,代码行数:101,代码来源:tftp-transfer.c


示例9: group_newpeer

uint32_t group_newpeer(Group_Chat *chat, uint8_t *client_id)
{
    addpeer(chat, client_id);
    return send_data(chat, client_id, crypto_box_PUBLICKEYBYTES, 16); //TODO: better return values?
}
开发者ID:erwinjulius,项目名称:ProjectTox-Core,代码行数:5,代码来源:group_chats.c


示例10: receive_transfer

/*
 * Called by libusb (as triggered by handle_event()) when a transfer comes in.
 * Only channel data comes in asynchronously, and all transfers for this are
 * queued up beforehand, so this just needs to chuck the incoming data onto
 * the libsigrok session bus.
 */
static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer)
{
	struct sr_dev_inst *sdi;
	struct dev_context *devc;

	sdi = transfer->user_data;
	devc = sdi->priv;

	if (devc->dev_state == FLUSH) {
		g_free(transfer->buffer);
		libusb_free_transfer(transfer);
		devc->dev_state = CAPTURE;
		devc->aq_started = g_get_monotonic_time();
		read_channel(sdi, data_amount(sdi));
		return;
	}

	if (devc->dev_state != CAPTURE)
		return;

	if (!devc->sample_buf) {
		devc->sample_buf_size = 10;
		devc->sample_buf = g_try_malloc(devc->sample_buf_size * sizeof(transfer));
		devc->sample_buf_write = 0;
	}

	if (devc->sample_buf_write >= devc->sample_buf_size) {
		devc->sample_buf_size += 10;
		devc->sample_buf = g_try_realloc(devc->sample_buf,
				devc->sample_buf_size * sizeof(transfer));
		if (!devc->sample_buf) {
			sr_err("Sample buffer malloc failed.");
			devc->dev_state = STOPPING;
			return;
		}
	}

	devc->sample_buf[devc->sample_buf_write++] = transfer;
	devc->samp_received += transfer->actual_length / NUM_CHANNELS;

	sr_spew("receive_transfer(): calculated samplerate == %" PRIu64 "ks/s",
		(uint64_t)(transfer->actual_length * 1000 /
		(g_get_monotonic_time() - devc->read_start_ts + 1) /
		NUM_CHANNELS));

	sr_spew("receive_transfer(): status %s received %d bytes.",
		libusb_error_name(transfer->status), transfer->actual_length);

	if (transfer->actual_length == 0)
		/* Nothing to send to the bus. */
		return;

	if (devc->limit_samples && devc->samp_received >= devc->limit_samples) {
		sr_info("Requested number of samples reached, stopping. %"
			PRIu64 " <= %" PRIu64, devc->limit_samples,
			devc->samp_received);
		send_data(sdi, devc->sample_buf, devc->limit_samples);
		sdi->driver->dev_acquisition_stop(sdi);
	} else if (devc->limit_msec && (g_get_monotonic_time() -
			devc->aq_started) / 1000 >= devc->limit_msec) {
		sr_info("Requested time limit reached, stopping. %d <= %d",
			(uint32_t)devc->limit_msec,
			(uint32_t)(g_get_monotonic_time() - devc->aq_started) / 1000);
		send_data(sdi, devc->sample_buf, devc->samp_received);
		g_free(devc->sample_buf);
		devc->sample_buf = NULL;
		sdi->driver->dev_acquisition_stop(sdi);
	} else {
		read_channel(sdi, data_amount(sdi));
	}
}
开发者ID:martinling,项目名称:libsigrok,代码行数:77,代码来源:api.c


示例11: group_sendmessage

uint32_t group_sendmessage(Group_Chat *chat, uint8_t *message, uint32_t length)
{
    return send_data(chat, message, length, 64); //TODO: better return values?
}
开发者ID:erwinjulius,项目名称:ProjectTox-Core,代码行数:4,代码来源:group_chats.c


示例12: nt35510_init

static int32_t nt35510_init(struct lcd_spec *self)
{
	Send_data send_cmd = self->info.mcu->ops->send_cmd;
	Send_data send_data = self->info.mcu->ops->send_data;

	LCD_PRINT("nt35510_init===\n");	

	mdelay(200);

	//Power setting sequence
	send_cmd(0xF000);
	send_data(0x55);
	send_cmd(0xF001);
	send_data(0xAA);	
	send_cmd(0xF002);
	send_data(0x52);
	send_cmd(0xF003);
	send_data(0x08);
	send_cmd(0xF004);
	send_data(0x01);
	
	send_cmd(0xB000);
	send_data(0x09);
	send_cmd(0xB001);
	send_data(0x09);
	send_cmd(0xB002);
	send_data(0x09);
	
	send_cmd(0xB600);
	send_data(0x34);
	send_cmd(0xB601);
	send_data(0x34);	
	send_cmd(0xB602);
	send_data(0x34);
	
	send_cmd(0xB100);
	send_data(0x09);
	send_cmd(0xB101);
	send_data(0x09);	
	send_cmd(0xB102);
	send_data(0x09);
	
	send_cmd(0xB700);
	send_data(0x24);
	send_cmd(0xB701);
	send_data(0x24);	
	send_cmd(0xB702);
	send_data(0x24);
	
	send_cmd(0xB300);
	send_data(0x05);
	send_cmd(0xB301);
	send_data(0x05);	
	send_cmd(0xB302);
	send_data(0x05);
	
	send_cmd(0xB900);
	send_data(0x24);
	send_cmd(0xB901);
	send_data(0x24);	
	send_cmd(0xB902);
	send_data(0x24);
	
	send_cmd(0xBF00);
	send_data(0x01);
	
	send_cmd(0xB500);
	send_data(0x0B);
	send_cmd(0xB501);
	send_data(0x0B);	
	send_cmd(0xB502);
	send_data(0x0B);
	
	send_cmd(0xBA00);
	send_data(0x24);
	send_cmd(0xBA01);
	send_data(0x24);	
	send_cmd(0xBA02);
	send_data(0x24);
	
	send_cmd(0xBC00);
	send_data(0x00);
	send_cmd(0xBC01);
	send_data(0xA3);	
	send_cmd(0xBC02);
	send_data(0x00);
	
	send_cmd(0xBD00);
	send_data(0x00);
	send_cmd(0xBD01);
	send_data(0xA3);	
	send_cmd(0xBD02);
	send_data(0x00);
	
	mdelay(120);

	//Display parameter setting
	send_cmd(0xF000);
	send_data(0x55);
	send_cmd(0xF001);
//.........这里部分代码省略.........
开发者ID:yourfrienddhruv,项目名称:zen_u105_uboot,代码行数:101,代码来源:lcd_nt35510.c


示例13: server_check

void server_check(int conn_fd)
{
	char buf[32];
	char name[32];
	char passwd[32];
	char pathname[SIZE] = {"/home/qiong/userinfo/"};
	int  ret;
	int  flag;
	int  fd;
	char log[SIZE];
	int i;

	send_data(conn_fd, "b\n");
	sleep(1);
	while(1)
	{
		my_recv(conn_fd, buf, sizeof(buf));
		if (buf[0] == 'u')
		{
			send_data(conn_fd, "b\n");
			sleep(1);
			ret = recv(conn_fd, buf, sizeof(buf), 0);
			buf[ret-1] = '\0';
			strcpy(name, buf);
			flag = find_name(buf);
			if (flag == 0)
			{
				send_data(conn_fd, "y\n");
				sleep(1);
			}
			else
			{
				send_data(conn_fd, "n\n");
				sleep(1);
				continue;
			}
			my_recv(conn_fd, buf, sizeof(buf));
			send_data(conn_fd, "b\n");
			sleep(1);
			ret = recv(conn_fd, buf, sizeof(buf), 0);
			buf[ret-1] = '\0';
			strcpy(passwd, buf);
			memset(passwd, '\0', sizeof(passwd));
			flag = check_passwd(name, passwd);
			if (flag == 0)
			{
				send_data(conn_fd, "y\n");
				sleep(1);
				strcat(ip_name, "  用户名:");
				strcat(ip_name, name);
				strcpy(name, "验证成功");
				sys_log(name);
				deal(conn_fd);
			}
			else
			{
				send_data(conn_fd, "n\n");
				sleep(1);
				continue;
			}
		}
	}
}
开发者ID:Gaoyuan0710,项目名称:MyFtp,代码行数:63,代码来源:server.c


示例14: main

/*---------------------------------------------------------------------------
  Main program start here
 *---------------------------------------------------------------------------*/
int main() 
{
  GPIO_InitTypeDef pa0;
  
  RCC_RTC_Configuration();
  LCD_GLASS_Init();
  LCD_GLASS_Configure_GPIO();
  
  init_USART();
  
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
  
  GPIO_StructInit(&pa0);
  pa0.GPIO_Mode = GPIO_Mode_IN;
  pa0.GPIO_Pin = GPIO_Pin_0;
  GPIO_Init(GPIOA,&pa0);

    while(1) {
    if( GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == 1 && state == 0)
    {
      count++;
      sprintf(DataSendToServer,"GET /cpe312/index.php?Name=TESTING_%d HTTP/1.1\r\nHost: markdang.lnw.mn\r\n\r\n",count);
      
      // Test AT startup
      send_data("AT\r\n");
      wait_data("OK");
      
      // Restart module
      send_data("AT+RST\r\n");
      wait_data("ready");

      display("OK RST");
   
      // Set Station & softAP Mode
      send_data("AT+CWMODE_CUR=3\r\n");
      wait_data("OK");
      display("STA+AP");
      
      // Set Station & softAP Mode
      send_data("AT+CWJAP_CUR=\"CPE312\",\"25033333\"\r\n");
      wait_data("OK");
      display("SET AP");
      
      // Set TCP , Address & Port : Check data http://markdang.lnw.mn/cpe312/show_data.php
      send_data("AT+CIPSTART=\"TCP\",\"markdang.lnw.mn\",80\r\n");
      wait_data("CONNECT");
      display("SETTCP");
      
      length = strlen(DataSendToServer);  // find length of data
      sprintf(nbr_DataSendToServer, "AT+CIPSEND=%d\r\n", length); // Set data size
      
      // Send length of data to server
      send_data(nbr_DataSendToServer);
      wait_data(">");
      display("SetLEN");
      
      // Send data to server
      send_data(DataSendToServer);
      wait_data("SEND OK");
      display("SENDOK");
      
      // Close AP
      send_data("AT+CWQAP\r\n");
      wait_data("OK");
      display("Close");
      
      state = 1;
    }
    else if ( GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == 0 && state == 1)
    {
      state = 0;
    }
    display("ready ");
    }
}
开发者ID:titichaya,项目名称:STM32L152_CPE-214-312,代码行数:78,代码来源:main.c


示例15: check_clients

int check_clients(pool *p)
{
    int i, client_sock, cnt, totalsize;
    ssize_t readret;
    char buf[2 * MAX_HEADER];   // in case of super-long request (invalid)
    char header[MAX_HEADER];    // actual request header parsed out from buffer
    char *cur;  // hold the current block of request
    char *temp;
    request *req;

    for (i = 0; (i <= p->maxi) && (p->nready > 0); i++)
    {
        client_sock = p->clientfd[i];
        req = &p->clientreq[i];
        /* if the descriptor is ready, receive it and send it back */
        if ((client_sock > 0) && FD_ISSET(client_sock, &p->ready_set))
        {
            p->nready--;
            readret = 0;
            if ((readret = recv(client_sock, buf, MAX_HEADER, 0)) >= 1)
            {
                /* If client buf has content from previous request,
                 * combine it with the buffer received this time. This is
                 * why we need to allocate more space for the buf. */
                if (strlen(p->clibuf[i]) > 0)
                {
                    temp = malloc(MAX_HEADER);
                    strcpy(temp, buf);
                    sprintf(buf, "%s%s", p->clibuf[i], temp);
                    memset(p->clibuf[i], 0, MAX_HEADER);
                    free(temp);
                }

                cnt = 0;
                totalsize = strlen(buf);

                /* At this point, we should have the complete buffer we
                 * need, then process it. */
                while (cnt < totalsize)
                {
                    /* Parse out each block of the request delimited by
                     * \r\n\r\n according to the RFC spec */
                    cur = strstr(buf, "\r\n\r\n");

                    /* Deal with incomplete request header, save it into
                     * clibuf for the next round */
                    if (cur == NULL)
                    {
                        strcpy(p->clibuf[i], buf);
                        break;
                    }

                    /* Parse out the complete header */
                    strncpy(header, buf, cur - buf);

                    /* Count the bytes we have read */
                    cnt += cur - buf;

                    /* Parse out Content-Length in order to decide if
                     * there is body part attached */
                    temp = malloc(MAX_HEADER);
                    strcpy(temp, header);
                    char *rv = parse_value(temp, "Content-Length");
                    req->content_length = rv == NULL ? 0 : atoi(rv);

                    /* If Content-Length exists, but no body attached,
                     * return 500 error */
                    if (cnt + 4 + req->content_length > totalsize)
                    {
                        temp = formalize_response(500, NULL, 0);
                        send_data(client_sock, temp, strlen(temp));
                        break;
                    }

                    /* Parse out the body section for POST use */
                    strncpy(req->body, cur + 4, req->content_length);
                    strcpy(buf, cur + 4 + req->content_length);
                    cnt += 4 + req->content_length;
                    free(temp);

                    /* At this point, we get everything we want, go to
                     * process it and give the response; However, valid
                     * request should always less than 8192 bytes. Ignore
                     * invalid ones. */
                    if (strlen(header) <= MAX_HEADER
                            && process_request(client_sock, header, req) != 0)
                    {
                        if (close_socket(client_sock))
                            return 1;
                        FD_CLR(client_sock, &p->read_set);
                        p->clientfd[i] = -1;
                    }
                }
                memset(buf, 0, MAX_HEADER);
            }
            if (readret == 0)
            {
                /* receiving is done, so close the client socket */
                if (close_socket(client_sock))
                    return 1;
//.........这里部分代码省略.........
开发者ID:SunnyQ,项目名称:cmu,代码行数:101,代码来源:lisod.c


示例16: Inspirace


//.........这里部分代码省略.........
							cout << current_time() + client_ip + " File is too large to send. Operation aborted\n";
							
							clean_sources(f, sockfd);
							return EXIT_FAILURE;
						}
					}
					else
					{// mezi parametry nebyla velikost bloku, uvazuje se standardni
						file_buf = new char[STANDARD_BLOCK + 1];
						file_buf_size = STANDARD_BLOCK + 1;
					}
				}
				else
				{// bez parametru, posilani prvnich dat

					if(f->get_file_size() > MAX_BLOCK_COUNT * STANDARD_BLOCK)
					{// Soubor je prilis velky na prenos pres tftp
						err_msg = "File is too large to send";
						send_error(sockfd, client_addr, err_msg, ERROR_IL);
						cout << current_time() + client_ip + " File is too large to send. Operation aborted\n";
						
						clean_sources(f, sockfd);
						return 1;
					}

					// Alokace bufferu pro nacitani souboru - standardni velikost
					file_buf = new char[STANDARD_BLOCK + 1];

					reading_data = true;

					cout << current_time() + client_ip + " Sending DATA\n";

					// poslou se prvni data
					data_len = send_data(sockfd, client_addr, 1, STANDARD_BLOCK, f, file_buf);
					data_counter += data_len;

					if(data_len < STANDARD_BLOCK)
					{// Prvni blok je zaroven i posledni, tim konci cinnost
						reading_data = false;
					}
				}

				break;
			}

			case WRQ:
			{// Zadost o zapis

				get_filename(buf); // ulozim jmeno souboru

				// Zjistim mod prenosu

				mode = transfer_mode(buf);

				if(mode == UNKNOWN_MODE)
				{// neznamy mod
					err_msg = "Unknown transfer mode";
					send_error(sockfd, client_addr, err_msg, ERROR_IL);
					break;
				}
				else if(mode == NETASCII)
				{
					cout << current_time() << client_ip << " Requested WRITE of " << filename << " [netascii]" << endl;
				}
				else if(mode == OCTET)
				{
开发者ID:johnik55,项目名称:TFTPv2-server,代码行数:67,代码来源:server.cpp


示例17: main

int main (int argc, const char* argv[]) {

    // Check if the user has not given enough parameters
    if (argc != 3) {
        printf("Invalid command. Usage: \"%s [address] [port]\"\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    // Init structs and other variables
    struct addrinfo* results;
    int sockfd, nbytes;
    char buf[MAXDATASIZE];

    // Try to get addrinfo, exiting on error
    printf("Getting address information...\n");
    results = get_address_info(argv[1], argv[2]);
    if (!results) {
        fprintf(stderr, "Implement assignment 1!\n");
	exit(EXIT_FAILURE);
    }

    // Get IP addresses
    printf("Printing IP addresses for %s...\n", argv[1]);
    char* addr = print_addresses(results);
    if (!addr) {
        fprintf(stderr, "Implement assignment 2!\n");
        exit(EXIT_FAILURE);
    }
    printf("%s", addr);
    free(addr);

    // Bind and connect socket
    printf("Connecting to server...\n");
    sockfd = create_and_connect(results);
    if (!sockfd) {
        fprintf(stderr, "Implement assignment 3!\n");
        close(sockfd);
        exit(EXIT_FAILURE);
    }

    // We don't need this struct anymore
    freeaddrinfo(results);

    // Receive data
    printf("Receiving data...\n");
    nbytes = receive_data(sockfd, buf);
    if (!nbytes) {
        fprintf(stderr, "Implement assignment 4!\n");
        exit(EXIT_FAILURE);
    }
    buf[nbytes] = '\0';
    printf("Received: %s\n", buf);

    // Send data
    printf("Sending data...\n");
    nbytes = send_data(sockfd, buf);
    if (!nbytes) {
        fprintf(stderr, "Implement assignment 5!\n");
        exit(EXIT_FAILURE);
    }
    buf[nbytes] = '\0';
    printf("Sent: %s\n", buf);

    // Receive confirmation
    if ((nbytes = recv(sockfd, buf, MAXDATASIZE-1, 0)) == -1) {
        perror("recv error");
        exit(EXIT_FAILURE);
    }
    buf[nbytes] = '\0';
    printf("Received: %s\n", buf);

    // Close the socket after the sending and receiving is done
    close(sockfd);

    return 0;
}
开发者ID:rainiemi,项目名称:Tietokoneverkot_eka_harjoitustyo,代码行数:76,代码来源:client_template.c


示例18: hx8369_init

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ send_data_cmd函数代码示例发布时间:2022-05-30
下一篇:
C++ send_command_packet函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap