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

C++ recv_all函数代码示例

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

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



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

示例1: receive_input

/**
 * Receive input buffer, convert to Stream object
 *
 * @return SUCCESS on success, else, -1 on error
 */
ssize_t receive_input(void) {
    ssize_t res;
    Stream tmp;
    // recv Input type and size
    res = recv_all((char *)&tmp, sizeof(tmp));
    if (res != sizeof(tmp)) {
        _terminate(ERRNO_RECV);
    }

    // check for invalid INPUT_TYPE
    if (memcmp(INPUT_TYPE_PLAIN, (const char *)tmp.type, sizeof(INPUT_TYPE_PLAIN)) &&
        memcmp(INPUT_TYPE_SERIALIZED, (const char *)tmp.type, sizeof(INPUT_TYPE_SERIALIZED))) {
        return -1;
    }

    in = malloc(sizeof(tmp) + tmp.size);
    MALLOC_OK(in);

    in->size = tmp.size;
    cgc_memcpy(in->type, tmp.type, sizeof(INPUT_TYPE_SERIALIZED));

    res = recv_all(in->content, in->size);
    if (res != in->size) {
        _terminate(ERRNO_RECV);
    }

    return SUCCESS;
}
开发者ID:trailofbits,项目名称:cb-multios,代码行数:33,代码来源:service.c


示例2: client_recv_frame

/* post a frame to the wire */
int client_recv_frame(SOCKET MySock, void * buffer, int maxlength) 
{
	int nret;
	unsigned short len;

	/* read a 2 byte short indicating size of frame to read */
	nret = recv_all(MySock, (char *)&len, sizeof(unsigned short));
	len  = ntohs(len);

	/* do the standard error checking */
	if (nret == SOCKET_ERROR) 
	{
		printf("Size receive corrupt\n");
	}

	/* sanity check for the length value */
	if (len > maxlength) 
	{
		printf("Read len is too large\n");
		closesocket(MySock);
		WSACleanup();
		exit(1);
	}

	/* read the actual frame into our buffer */
	//printf("Will read: %d (was %d) from wire\n", len, htons(len));
	nret = recv_all(MySock, (char *)buffer, len);

	return nret;
}
开发者ID:archivaldo,项目名称:VPN_Pivoting,代码行数:31,代码来源:client.c


示例3: get_info_spectate

static bool get_info_spectate(netplay_t *handle)
{
   if (!send_nickname(handle, handle->fd))
   {
      RARCH_ERR("Failed to send nickname to host.\n");
      return false;
   }

   if (!get_nickname(handle, handle->fd))
   {
      RARCH_ERR("Failed to receive nickname from host.\n");
      return false;
   }

   char msg[512];
   snprintf(msg, sizeof(msg), "Connected to \"%s\"", handle->other_nick);
   msg_queue_push(g_extern.msg_queue, msg, 1, 180);
   RARCH_LOG("%s\n", msg);

   uint32_t header[4];

   if (!recv_all(handle->fd, header, sizeof(header)))
   {
      RARCH_ERR("Cannot get header from host.\n");
      return false;
   }

   size_t save_state_size = pretro_serialize_size();
   if (!bsv_parse_header(header, implementation_magic_value()))
   {
      RARCH_ERR("Received invalid BSV header from host.\n");
      return false;
   }

   void *buf = malloc(save_state_size);
   if (!buf)
      return false;

   size_t size = save_state_size;

   if (!recv_all(handle->fd, buf, size))
   {
      RARCH_ERR("Failed to receive save state from host.\n");
      free(buf);
      return false;
   }

   bool ret = true;
   if (save_state_size)
      ret = pretro_unserialize(buf, save_state_size);

   free(buf);
   return ret;
}
开发者ID:AbelFlos,项目名称:RetroArch,代码行数:54,代码来源:netplay.c


示例4: netplay_get_cmd

static bool netplay_get_cmd(netplay_t *handle)
{
   uint32_t cmd;
   if (!recv_all(handle->fd, &cmd, sizeof(cmd)))
      return false;

   cmd = ntohl(cmd);

   size_t cmd_size = cmd & 0xffff;
   cmd = cmd >> 16;

   switch (cmd)
   {
      case NETPLAY_CMD_FLIP_PLAYERS:
      {
         if (cmd_size != sizeof(uint32_t))
         {
            RARCH_ERR("CMD_FLIP_PLAYERS has unexpected command size.\n");
            return netplay_cmd_nak(handle);
         }

         uint32_t flip_frame;
         if (!recv_all(handle->fd, &flip_frame, sizeof(flip_frame)))
         {
            RARCH_ERR("Failed to receive CMD_FLIP_PLAYERS argument.\n");
            return netplay_cmd_nak(handle);
         }

         flip_frame = ntohl(flip_frame);
         if (flip_frame < handle->flip_frame)
         {
            RARCH_ERR("Host asked us to flip players in the past. Not possible ...\n");
            return netplay_cmd_nak(handle);
         }

         handle->flip ^= true;
         handle->flip_frame = flip_frame;

         RARCH_LOG("Netplay players are flipped.\n");
         msg_queue_push(g_extern.msg_queue, "Netplay players are flipped.", 1, 180);

         return netplay_cmd_ack(handle);
      }

      default:
         RARCH_ERR("Unknown netplay command received.\n");
         return netplay_cmd_nak(handle);
   }
}
开发者ID:AbelFlos,项目名称:RetroArch,代码行数:49,代码来源:netplay.c


示例5: main

int main(int argc, char const *argv[])
{	
	char *ip, *port;
	get_input(argc, argv, &ip, &port);
	printf("IP = %s\n", ip);
	printf("Port = %s\n", port);

	int sock;
	sock = create_socket(SOCK_DGRAM, ip);
	

/* PROTOTIPO de como ENVIA mensagens */
	char msg[BUF_SIZE];
	strcat(msg, "GET /index.html HTTP/1.1\r\nHost: ");
	strcat(msg, ip);
	strcat(msg, "\r\n\r\n");
	print_request(msg);

	send_all(sock, msg);

/* PROTOTIPO de como RECEBE mensagens */
	// int recv(int sockfd, void *buf, int len, int flags);
	char *buff;
	size_t by_recv;
	by_recv = recv_all(sock, &buff, BUF_SIZE);

	print_response(buff);
	return 0;
}
开发者ID:LuizPelegrini,项目名称:SocketProgramming,代码行数:29,代码来源:udp-client.c


示例6: transaction_recv_refund

// recv refund details
// success: SUCCESS
// failure: ERRNO_MP_ALLOC, ERRNO_MP_RECV
int transaction_recv_refund(packet_data_refund_t ** pdr) {
    // create memory for refund data
    ALLOC(sizeof(packet_data_refund_t), 0, (void **)pdr);
    if(sizeof(packet_data_refund_t) != recv_all((char *)*pdr, sizeof(packet_data_refund_t))) {return ERRNO_MP_RECV;}

    return SUCCESS;
}
开发者ID:arashmahdian,项目名称:samples,代码行数:10,代码来源:mp.c


示例7: transaction_recv_history

// recv history details
// success: SUCCESS
// failure: ERRNO_MP_ALLOC, ERRNO_MP_RECV
int transaction_recv_history(packet_data_history_t ** pdh) {
    // create memory for history data
    ALLOC(sizeof(packet_data_history_t), 0, (void **)pdh);
    if(sizeof(packet_data_history_t) != recv_all((char *)*pdh, sizeof(packet_data_history_t))) {return ERRNO_MP_RECV;}

    return SUCCESS;
}
开发者ID:arashmahdian,项目名称:samples,代码行数:10,代码来源:mp.c


示例8: transaction_recv_recharge

// recv recharge details
// success: SUCCESS
// failure: ERRNO_MP_ALLOC, ERRNO_MP_RECV
int transaction_recv_recharge(packet_data_recharge_t ** pdr) {
    // create memory for recharge data + vendor
    ALLOC(sizeof(packet_data_recharge_t), 0, (void **)pdr);
    // read recharge data and vendor data (except vendor_location)
    if(10 != recv_all((char *)*pdr, 10)) {return ERRNO_MP_RECV;}

    uint32_t vls = (*pdr)->v.vendor_location_sz;
    if(vls == 0) {return ERRNO_MP_RECV;}

    // create memory for vendor_location char array
    ALLOC(vls, 0, (void **)&((*pdr)->v.vendor_location));
    // read vendor_location (size is in previous read)
    if(vls != recv_all((char *)(*pdr)->v.vendor_location, vls)) {return ERRNO_MP_RECV;}

    return SUCCESS;
}
开发者ID:arashmahdian,项目名称:samples,代码行数:19,代码来源:mp.c


示例9: transaction_recv_issue

// recv issue details
// success: SUCCESS
// failure: ERRNO_MP_ALLOC, ERRNO_MP_RECV
int transaction_recv_issue(packet_data_issue_t ** pdi) {
    // create memory for issue data
    ALLOC(sizeof(packet_data_issue_t), 0, (void **)pdi);
    if(sizeof(packet_data_issue_t) != recv_all((char *)*pdi, sizeof(packet_data_issue_t))) {return ERRNO_MP_RECV;}

    return SUCCESS;
}
开发者ID:arashmahdian,项目名称:samples,代码行数:10,代码来源:mp.c


示例10: run_pp_server

static
void run_pp_server(psdapl_con_info_t *ci)
{
	char *buf = malloc(arg_maxmsize);
	int msgsize;

	while (1) {
		msgsize = recv_all(ci, buf);

		if (DEBUG_MESSAGES) {
			static int allcount = 0;
			allcount ++;
			printf("received: msgsize:%u %s\n", msgsize, buf + sizeof(unsigned));
			sprintf(buf + sizeof(unsigned), "ServerRet#%d", allcount);
			printf("Send:                %s\n", buf + sizeof(unsigned));
		}

		send_all(ci, buf, msgsize);
		if (msgsize <= 0) break;
	}
	if (msgsize == 0) {
		printf("receive EOF\n");
	} else {
		printf("receive error : %s\n", strerror(-msgsize));
	}
}
开发者ID:JonBau,项目名称:pscom,代码行数:26,代码来源:dapl_pp.c


示例11: transaction_recv_purchase

// recv purchase details
// success: SUCCESS
// failure: ERRNO_MP_ALLOC, ERRNO_MP_RECV
int transaction_recv_purchase(packet_data_purchase_t ** pdp) {
    // create memory for purchase data + vendor
    ALLOC(sizeof(packet_data_purchase_t), 0, (void **)pdp);
    // cgc_read purchase data and vendor data (except vendor_location)
    if(14 != recv_all((char *)*pdp, 14)) {return ERRNO_MP_RECV;}

    uint32_t vls = (*pdp)->v.vendor_location_sz;
    if(vls == 0) {return ERRNO_MP_RECV;}

    // create memory for vendor_location char array
    ALLOC(vls, 0, (void **)&((*pdp)->v.vendor_location));
    // cgc_read vendor_location (size is in previous cgc_read)
    if(vls != recv_all((char *)(*pdp)->v.vendor_location, vls)) {return ERRNO_MP_RECV;}

    return SUCCESS;
}
开发者ID:trailofbits,项目名称:cb-multios,代码行数:19,代码来源:mp.c


示例12: run_pp_c

static
int run_pp_c(psdapl_con_info_t *ci, unsigned msgsize, unsigned loops)
{
	unsigned cnt;
	if (msgsize < sizeof(unsigned)) msgsize = sizeof(unsigned);

	char *buf = malloc(msgsize);
	*((unsigned *)buf) = msgsize;

	for (cnt = 0; cnt < loops; cnt++) {
		if (DEBUG_MESSAGES) {
			sprintf(buf + sizeof(unsigned), "C2S#%d", cnt);
			printf("Send:     %s\n", buf + sizeof(unsigned));
		}
		send_all(ci, buf, msgsize);
		recv_all(ci, buf);

		if (DEBUG_MESSAGES) {
			printf("received: %s\n", buf + sizeof(unsigned));
		}
	}

	free(buf);
	return 0;
}
开发者ID:JonBau,项目名称:pscom,代码行数:25,代码来源:dapl_pp.c


示例13: main

int
main(int argc, char **argv)
{
	int					sendfd, recvfd;
	const int			on = 1;
	socklen_t			salen;
	struct sockaddr		*sasend, *sarecv;

	if (argc != 3)
		err_quit("usage: sendrecv <IP-multicast-address> <port#>");

	sendfd = Udp_client(argv[1], argv[2], (void **) &sasend, &salen);

	recvfd = Socket(sasend->sa_family, SOCK_DGRAM, 0);

	Setsockopt(recvfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));

	sarecv = Malloc(salen);
	memcpy(sarecv, sasend, salen);
	Bind(recvfd, sarecv, salen);

	Mcast_join(recvfd, sasend, salen, NULL, 0);
	Mcast_set_loop(sendfd, 0);

	if (Fork() == 0)
		recv_all(recvfd, salen);		/* child -> receives */

	send_all(sendfd, sasend, salen);	/* parent -> sends */
}
开发者ID:337240552,项目名称:linux-programming,代码行数:29,代码来源:main.c


示例14: bg_traffic_thread

static void bg_traffic_thread(SInfo *info)
{
    static const int data_len = 10;
    char sbuffer[data_len + 1] = "dummydata_";
    char rbuffer[data_len + 1];
    int scount, rtotal = 0;
    info->setSenderThreadId(ThisThread::get_id());

    for (;;) {
        if (!info->available()) {
            (void)handle_nsapi_size_or_error(__func__, rtotal);
            break;
        }
        sbuffer[data_len - 1] = 'A' + (rand() % 26);
        scount = info->socket().send(sbuffer, data_len);
        rtotal = recv_all(rbuffer, data_len, info);

        if (scount != rtotal || (strcmp(sbuffer, rbuffer) != 0)) {
            info->setUnavailable();

            tr_err("Background received data does not match to sent data");
            tr_err("Background sent: \"%s\"", sbuffer);
            tr_err("Background received: \"%s\"", rbuffer);
        }
        wait_ms(10);
    }
}
开发者ID:MarceloSalazar,项目名称:mbed-os,代码行数:27,代码来源:cmd_socket.cpp


示例15: netplay_get_response

static bool netplay_get_response(netplay_t *handle)
{
   uint32_t response;
   if (!recv_all(handle->fd, &response, sizeof(response)))
      return false;

   return ntohl(response) == NETPLAY_CMD_ACK;
}
开发者ID:AbelFlos,项目名称:RetroArch,代码行数:8,代码来源:netplay.c


示例16: get_info

static bool get_info(netplay_t *handle)
{
   uint32_t header[3];

   if (!recv_all(handle->fd, header, sizeof(header)))
   {
      RARCH_ERR("Failed to receive header from client.\n");
      return false;
   }

   if (g_extern.cart_crc != ntohl(header[0]))
   {
      RARCH_ERR("Cart CRC32s differ. Cannot use different games.\n");
      return false;
   }

   if (implementation_magic_value() != ntohl(header[1]))
   {
      RARCH_ERR("Implementations differ, make sure you're using exact same libretro implementations and RetroArch version.\n");
      return false;
   }

   if (pretro_get_memory_size(RETRO_MEMORY_SAVE_RAM) != ntohl(header[2]))
   {
      RARCH_ERR("Cartridge SRAM sizes do not correspond.\n");
      return false;
   }

   if (!get_nickname(handle, handle->fd))
   {
      RARCH_ERR("Failed to get nickname from client.\n");
      return false;
   }

   // Send SRAM data to our Player 2.
   const void *sram = pretro_get_memory_data(RETRO_MEMORY_SAVE_RAM);
   unsigned sram_size = pretro_get_memory_size(RETRO_MEMORY_SAVE_RAM);
   if (!send_all(handle->fd, sram, sram_size))
   {
      RARCH_ERR("Failed to send SRAM data to client.\n");
      return false;
   }

   if (!send_nickname(handle, handle->fd))
   {
      RARCH_ERR("Failed to send nickname to client.\n");
      return false;
   }

#ifndef HAVE_SOCKET_LEGACY
   log_connection(&handle->other_addr, 0, handle->other_nick);
#endif

   return true;
}
开发者ID:AbelFlos,项目名称:RetroArch,代码行数:55,代码来源:netplay.c


示例17: phone_recvplay

void phone_recvplay(void *vs){
  int* ps = (int *)vs;
  int s = *ps;
  int i;
  FILE *fp_play;
  if ( (fp_play=popen("play -t raw -b 16 -c 1 -e s -r 44100 - 2> /dev/null ","w")) ==NULL) {
    die("popen:play");
  }
  int cut_low=300, cut_high=5000;
  int send_len = (cut_high-cut_low)*N/SAMPLING_FREQEUENCY;
  double * recv_data = malloc(sizeof(double)*send_len*2);
  sample_t * play_data = malloc(sizeof(sample_t)*N);
  sample_t * pre_data = malloc(sizeof(sample_t)*N/2);
  complex double * X = calloc(sizeof(complex double), N);
  complex double * Y = calloc(sizeof(complex double), N);
  complex double * Z = calloc(sizeof(complex double), N);
  complex double * W = calloc(sizeof(complex double), N);
  memset(pre_data,0,N);
  while(1){
    memset(W,0.0+0.0*I,N*sizeof(complex double));
    memset(Z,0.0+0.0*I,N*sizeof(complex double));
    // memset(rec_data,0,sizeof(long)*send_len*2);
    if(recv_all(s,(char *)recv_data,sizeof(double)*send_len*2)==-1){
      die("recv");
    }
    for(i=0; i<send_len; i++){
      W[cut_low*N/SAMPLING_FREQEUENCY+i]=(double)recv_data[2*i]+(double)recv_data[2*i+1]*I;
    }
    // /* IFFT -> Z */
    ifft(W, Z, N);

    // // 標本の配列に変換
    complex_to_sample(Z, play_data, N);
        // オーバーラップを戻す
    for(i=0;i<N/2;i++){
      play_data[i] += pre_data[i];
    }
    memcpy(pre_data,play_data+N/2,N/2);
    // 無音状態だったらスキップ
    int num_low=0;
    for(i=0;i<N;i++){
      if(-10<play_data[i] && play_data[i]<10)
        num_low++;
    }
    if(num_low>80*N/100)
      continue;
    // /* 標準出力へ出力 */
    // write(1,play_data,N/2);
    fwrite(play_data,sizeof(sample_t),N/2,fp_play);
    memset(play_data,0,sizeof(sample_t)*N);
    
  }
}
开发者ID:mazamachi,项目名称:g3_phone,代码行数:53,代码来源:satish_phone_pthread.c


示例18: isisds_recv_open

/*
 * server
 * client minor ver <= server minor ver
 */
int isisds_recv_open(SOCKET s, ISISDSAccessMode *access_type) {
  isisds_open_t op;
  if ((recv_all(s, (char *)&op, sizeof(op), 0)) != sizeof(op)) {
    return -1;
  }
  if (op.len != sizeof(op)) {
    return -1;
  }
  if ((op.ver_major != ISISDS_MAJOR_VER) || (op.ver_minor > ISISDS_MINOR_VER)) {
    return -1;
  }
  *access_type = (ISISDSAccessMode)op.access_type;
  return isisds_send_command(s, "OK", NULL, ISISDSUnknown, NULL, 0);
}
开发者ID:mkoennecke,项目名称:mantid,代码行数:18,代码来源:isisds_command.cpp


示例19: process_mkdir_cmd

static int process_mkdir_cmd(client_t *client, netiso_mkdir_cmd *cmd)
{
	netiso_mkdir_result result;
	char *dirpath;
	uint16_t dp_len;
	int ret;
		
	dp_len = BE16(cmd->dp_len);
	dirpath = (char *)malloc(dp_len+1);
	if (!dirpath)
	{
		DPRINTF("CRITICAL: memory allocation error\n");
		return -1;
	}
	
	dirpath[dp_len] = 0;
	ret = recv_all(client->s, (void *)dirpath, dp_len);
	if (ret != dp_len)
	{
		DPRINTF("recv failed, getting dirname for mkdir: %d %d\n", ret, get_network_error());
		free(dirpath);
		return -1;
	}
	
	dirpath = translate_path(dirpath, 1, 1, NULL);
	if (!dirpath)
	{
		DPRINTF("Path cannot be translated. Connection with this client will be aborted.\n");
		return -1;
	}
	
	DPRINTF("mkdir %s\n", dirpath);

#ifdef WIN32
	result.mkdir_result = BE32(mkdir(dirpath));
#else
	result.mkdir_result = BE32(mkdir(dirpath, 0777));
#endif
	free(dirpath);
		
	ret = send(client->s, (char *)&result, sizeof(result), 0);
	if (ret != sizeof(result))
	{
		DPRINTF("open dir, send result error: %d %d\n", ret, get_network_error());		
		return -1;
	}
	
	return 0;
}
开发者ID:Alexandersss,项目名称:COBRA-7-3,代码行数:49,代码来源:main.cpp


示例20: process_write_file_cmd

static int process_write_file_cmd(client_t *client, netiso_write_file_cmd *cmd)
{
	uint32_t remaining;
	int32_t bytes_written;
	netiso_write_file_result result;
	
	remaining = BE32(cmd->num_bytes);
	
	if (!client->wo_file)
	{
		bytes_written = -1;
		goto send_result;
	}
	
	if (remaining > BUFFER_SIZE)
	{
		return -1;
	}
	
	//DPRINTF("Remaining: %d\n", remaining);
	
	if (remaining > 0)
	{
		int ret = recv_all(client->s, (void *)client->buf, remaining);
		if (ret != remaining)
		{		
			DPRINTF("recv failed on write file: %d %d\n", ret, get_network_error());
			return -1;
		}
	}
	
	bytes_written = client->wo_file->write(client->buf, remaining);
	if (bytes_written < 0)
	{
		bytes_written = -1;		
	}
		
send_result:

	result.bytes_written = (int32_t)BE32(bytes_written);

	if (send(client->s, (char *)&result, sizeof(result), 0) != 4)
	{
		DPRINTF("send failed on send result (read file)\n");
		return -1;
	}

	return 0;
}
开发者ID:Alexandersss,项目名称:COBRA-7-3,代码行数:49,代码来源:main.cpp



注:本文中的recv_all函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ recv_data函数代码示例发布时间:2022-05-30
下一篇:
C++ recvString函数代码示例发布时间: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