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

C++ recvall函数代码示例

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

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



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

示例1: while

void* SC_TcpConnectionPort::Run()
{
	OSC_Packet *packet = 0;
	// wait for login message
	int32 size;
	int32 msglen;

	while (true) {
		if (!packet) {
			packet = (OSC_Packet*)malloc(sizeof(OSC_Packet));
		}
		size = recvall(mSocket, &msglen, sizeof(int32));
		if (size < 0) goto leave;

		// sk: msglen is in network byte order
		msglen = ntohl(msglen);

		char *data = (char*)malloc(msglen);
		size = recvall(mSocket, data, msglen);
		if (size < msglen) goto leave;

		packet->mReplyAddr.mReplyFunc = tcp_reply_func;
		packet->mSize = msglen;
		packet->mData = data;
		packet->mReplyAddr.mSocket = mSocket;
		ProcessOSCPacket(packet);
		packet = 0;
	}
leave:
    delete this; // ohh this could cause a crash if a reply tries to access it..
    return 0;
}
开发者ID:iani,项目名称:SC_SourceCode_Study,代码行数:32,代码来源:SC_ComPort.cpp


示例2: recvFromVICC

static ssize_t recvFromVICC(struct vicc_ctx *ctx, unsigned char **buffer)
{
    ssize_t r;
    uint16_t size;
    unsigned char *p = NULL;

    if (!buffer || !ctx) {
        errno = EINVAL;
        return -1;
    }

    /* receive size of message on 2 bytes */
    r = recvall(ctx->client_sock, &size, sizeof size);
    if (r < sizeof size)
        return r;

    size = ntohs(size);

    p = realloc(*buffer, size);
    if (p == NULL) {
        errno = ENOMEM;
        return -1;
    }
    *buffer = p;

    /* receive message */
    return recvall(ctx->client_sock, *buffer, size);
}
开发者ID:12019,项目名称:vsmartcard,代码行数:28,代码来源:vpcd.c


示例3: recibirString

char* recibirString(int socket){
	int tamanioString;
	if(recvall(socket,&tamanioString,sizeof(int))<1) return NULL;
	char* string;
	string =malloc(sizeof(char)*tamanioString);
	if(recvall(socket,string,tamanioString)<1) return NULL;
	return string;
}
开发者ID:rmejiadelagala-utn,项目名称:TP1C2015MapReduce,代码行数:8,代码来源:envioDeMensajes.c


示例4: IMA_tcp_recv

int
IMA_tcp_recv (int s, char *cmd)
{
  int len;
  int lenbuf;
  char buf[bufsize];
  FILE *fp;
  int i;

  fp = fopen (cmd, "w");
  lenbuf = bufsize;
  while (lenbuf == bufsize)
    {
      /* Receive the length of buffer. */
      len = sizeof (int);
      if (recvall (s, (char *) &lenbuf, &len) == -1)
        {
          perror ("recv");
          exit (1);
        }
      if (lenbuf == 999)
        {
          break;
        }
      /* printf ("Received: %d\n", lenbuf); */
      if (recvall (s, buf, &lenbuf) == -1)
        {
          perror ("recv");
          exit (1);
        }
      for (i = 0; i < lenbuf; i++)
        {
          fputc (buf[i], fp);
        }
    }
  if (lenbuf < bufsize)
    {
      len = sizeof (int);
      if (recvall (s, (char *) &lenbuf, &len) == -1)
        {
          perror ("recv");
          exit (1);
        }
      assert (lenbuf == 999);
    }

  fclose (fp);
  fp = NULL;
  printf ("Received: %s\n", cmd);
  return 0;

}
开发者ID:goshng,项目名称:cocoa,代码行数:52,代码来源:server.c


示例5: netlink_recv

struct nlmsghdr * netlink_recv(
    struct proxy_dev *pdev)
{
    struct nlmsghdr *nlh = NULL;
    struct msghdr msgh = {0};
    struct iovec iov = {0};
    size_t bufflen = sizeof(*nlh);
    void *buffer = malloc(bufflen);

    /* netlink header is our payload */
    iov.iov_base = buffer;
    iov.iov_len = bufflen;
    msgh.msg_iov = &iov; /* this normally is an array of */
    msgh.msg_iovlen = 1;
    msgh.msg_flags = MSG_PEEK; /* first we need the full msg size */

    /* the minimum is the size of the nlmsghdr alone */
    bufflen = recvall(pdev->nl_fd, &msgh, bufflen);
    if (bufflen == -1) {
        printf("netlink_recv: failed to read message\n");
        goto err;
    }

    nlh = buffer;
    /*
    debug("type: %d, pid: %d, size: %d",
            nlh->nlmsg_type, nlh->nlmsg_pid, nlh->nlmsg_len);
    */

    /* increase the buffer size if needbe */
    bufflen = nlh->nlmsg_len;
    buffer = realloc(buffer, bufflen);
    iov.iov_base = buffer;
    iov.iov_len = bufflen;
    msgh.msg_flags = 0; /* get rid of MSG_PEEK */

    /* get the rest of message */
    bufflen = recvall(pdev->nl_fd, &msgh, bufflen);
    if (bufflen == -1) {
        printf("netlink_recv: failed to read message\n");
        goto err;
    }

    nlh = buffer;
    return nlh;
err:
    free(buffer);
    return NULL;
}
开发者ID:PonderingGrower,项目名称:netdev,代码行数:49,代码来源:netlink.c


示例6: recv_command_packet

int recv_command_packet(int sockfd, struct command_packet
		*command_packet, int flags){

	/* Awkward buf size, but it is correct */
	unsigned char recv_buf[SEND_BUF_SIZE];
	int n = 0, bytes_recv;

	if((n = recvall(sockfd, recv_buf, COMMAND_PACKET_SIZE, flags)) <
			0){
		fprintf(stderr, "%s: ", __FUNCTION__);
		perror("recv error");
		return ERROR;
	}

	bytes_recv = n;

	/* Server closed connection */
	if(n == 0){
		close(sockfd);
		return bytes_recv;
	}

	/* Unpack response packet header and read the payload */
	if((n = prepare_to_read_command(recv_buf, bytes_recv, command_packet)) < 0){
		fprintf(stderr, "%s: prepare_to_read_comand error\n",
				__FUNCTION__);
		return ERROR;
	}

	return bytes_recv;
}
开发者ID:ghjh31531,项目名称:BPM_acquisition,代码行数:31,代码来源:connection_server.c


示例7: progressRead

//---------------------------------------------------------------------------------
int progressRead(int socket, char *buffer, int size) {
//---------------------------------------------------------------------------------

	int row,column;
	getCursor(&row,&column);
	
	int sizeleft = size, len;
	int chunksize = size/100;
	int target = size - chunksize;

	int percent = 0;

	while(sizeleft) {
		len = recvall(socket,buffer,chunksize,0);
		if (len == 0) break;
		sizeleft -= len;
		buffer += len;
		if (sizeleft <= target) {
			percent++;
			target -= chunksize;
			if (target<0) target = 0;
		}
		setCursor(row,column);
		kprintf("%%%d  ",percent);
		if ( sizeleft < chunksize) chunksize = sizeleft;
	}
	
	setCursor(row,column);
	if (sizeleft) {
		kprintf("\nReceive Error\n");
	} else {
		kprintf("%%100\n");
	}
	return sizeleft;
}
开发者ID:fagensden,项目名称:dslink,代码行数:36,代码来源:main.c


示例8: while

void *newconnection(void *arg)
{
  int sockethandle=(uintptr_t)arg;
  unsigned char command;
  int r;
  //printf("Hello!\n");

  //wait for a command and dispatch it

  r=1;
  while (r>=0)
  {
    r=recvall(sockethandle, &command, 1, MSG_WAITALL);
    if (r==1)
      DispatchCommand(sockethandle, command);
    else
    {
      //printf("Peer has disconnected");
      //if (r==-1)
      //  printf(" due to an error");

      //printf("\n");

      //fflush(stdout);
      close(sockethandle);
    }
  }

  printf("Bye\n");
  return NULL;
}
开发者ID:7568168,项目名称:cheat-engine,代码行数:31,代码来源:server.c


示例9: read_init_packet

/* reads initialization packet (containing IV and timestamp) from server */
int read_init_packet(int sock) {
	int rc;
	init_packet receive_packet;
	int bytes_to_recv;

	/* clear the IV and timestamp */
	bzero(&received_iv, TRANSMITTED_IV_SIZE);
	packet_timestamp = (time_t)0;

	/* get the init packet from the server */
	bytes_to_recv = sizeof(receive_packet);
	rc = recvall(sock, (char *)&receive_packet, &bytes_to_recv, socket_timeout);

	/* recv() error or server disconnect */
	if (rc <= 0) {
		printf("Error: Server closed connection before init packet was received\n");
		return ERROR;
	}

	/* we couldn't read the correct amount of data, so bail out */
	else if (bytes_to_recv != sizeof(receive_packet)) {
		printf("Error: Init packet from server was too short (%d bytes received, %d expected)\n", bytes_to_recv, sizeof(receive_packet));
		return ERROR;
	}

	/* transfer the IV and timestamp */
	memcpy(&received_iv, &receive_packet.iv[0], TRANSMITTED_IV_SIZE);
	packet_timestamp = (time_t)ntohl(receive_packet.timestamp);

	return OK;
}
开发者ID:HristoMohamed,项目名称:icinga-nsca,代码行数:32,代码来源:send_nsca.c


示例10: process_add_port

static int process_add_port(int client) {
    ctl_msg_add_port_t msg;
    msg.code = CTL_MSG_ADD_PORT_CODE;
    int n = recvall(client, ((char *) &msg) + 1, sizeof(ctl_msg_add_port_t) - 1);
    assert(n == sizeof(ctl_msg_add_port_t) - 1);
//int status = bmi_port_interface_add(port_mgr, msg.iface, msg.port_num); //send_status_reply(client, msg.request_id, status);
    return 0;
}
开发者ID:jack-songjian,项目名称:p4factory,代码行数:8,代码来源:main.c


示例11: boithoad_sidToGroup

int boithoad_sidToGroup(char sid_in[], char username_in[]) {

	int socketha;
	int intresponse;
	char username[64];
	char sid[512];
     	int forreturn = 0;

	//ToDo: strscpy
	strncpy(sid,sid_in,sizeof(sid));

        if ((socketha = cconnect("localhost", BADPORT)) == 0) {
		return 0;
	}

        sendpacked(socketha,bad_sidToGroup,BADPROTOCOLVERSION, 0, NULL,"");

	sendall(socketha, sid, sizeof(sid));
	
	//read respons
        if (!recvall(socketha,&intresponse,sizeof(intresponse))) {
                return 0;
        }

	if (intresponse == 1) {
		if (!recvall(socketha,username,sizeof(username))) {
                	return 0;
        	}
		strcpy(username_in, username);
		forreturn = 1;
	}
	else {
		#ifdef DEBUG
			printf("didn't have a group at %s:%d\n",__FILE__,__LINE__);
		#endif
		strcpy(username_in,"");
		forreturn = 0;
	}

	close(socketha);

	return forreturn;

}
开发者ID:FlavioFalcao,项目名称:enterprise-search,代码行数:44,代码来源:boithoadClientLib.c


示例12: recvall

/**
 * Receives a header and a payload on the TCP connection. Blocks until a
 * complete packet is received, the end-of-file is encountered, or an error
 * occurs.
 *
 * @param[in] header   Header.
 * @param[in] headLen  Length of the header in bytes.
 * @param[in] payload  Payload.
 * @param[in] payLen   Length of the payload in bytes.
 * @retval    0        EOF encountered.
 * @return             Number of bytes read. Will be `headLen + payLen`.
 * @throws std::system_error  if an error is encountered reading from the
 *                            socket.
 */
size_t TcpRecv::recvData(void* header, size_t headLen, char* payload,
                         size_t payLen)
{
    size_t nread;

    if (header && headLen) {
        nread = recvall(header, headLen);
        if (nread < headLen)
            return 0; // EOF
    }

    if (payload && payLen) {
        nread = recvall(payload, payLen);
        if (nread < payLen)
            return 0; // EOF
    }

    return (headLen + payLen);
}
开发者ID:UVA-High-Speed-Networks,项目名称:FMTP-LDM7,代码行数:33,代码来源:TcpRecv.cpp


示例13: boithoad_getPassword

int boithoad_getPassword(const char username_in[], char password_in[]) {

	int socketha;
	int intresponse;
	char username[64];
	char password[64];
     	int forreturn = 0;

	//ToDo: strscpy
	strncpy(username,username_in,sizeof(username));

        if ((socketha = cconnect("localhost", BADPORT)) == 0) {
		return 0;
	}

        sendpacked(socketha,bad_getPassword,BADPROTOCOLVERSION, 0, NULL,"");

	sendall(socketha,username, sizeof(username));
	
	//read respons
        if (!recvall(socketha,&intresponse,sizeof(intresponse))) {
                return 0;
        }

	if (intresponse == 1) {
		if (!recvall(socketha,password,sizeof(password))) {
                	return 0;
        	}
		//printf("got \"%s\"\n",password);
		strcpy(password_in,password);
		forreturn = 1;
	}
	else {
		printf("dident have a passord at %s:%d\n",__FILE__,__LINE__);
		strcpy(password_in,"");
		forreturn = 0;
	}

	close(socketha);

	return forreturn;

}
开发者ID:FlavioFalcao,项目名称:enterprise-search,代码行数:43,代码来源:boithoadClientLib.c


示例14: boithoa_getLdapResponsList

//motar en enkel respons liste. Den begynner med en int som sier hov lang den er
int boithoa_getLdapResponsList(int socketha,char **respons_list[],int *nrofresponses) {

	char ldaprecord[MAX_LDAP_ATTR_LEN];
	int intresponse,i,len;

	if (!recvall(socketha,&intresponse,sizeof(intresponse))) {
		return 0;
	}

	#ifdef DEBUG
	printf("nr %i\n",intresponse);
	#endif

	if (((*respons_list) = malloc((sizeof(char *) * (intresponse+1)))) == NULL) {
		perror("boithoa_getLdapResponsList: can't malloc respons array");
		return 0;
	}
        *nrofresponses = 0;

	for (i=0;i<intresponse;i++) {
		if (!recvall(socketha,ldaprecord,sizeof(ldaprecord))) {
			fprintf(stderr,"can't recvall() ldaprecord\n");
			return 0;
		}

		#ifdef DEBUG
		printf("record \"%s\", len %i\n",ldaprecord,strlen(ldaprecord));
		#endif

		len = strnlen(ldaprecord,MAX_LDAP_ATTR_LEN);
                (*respons_list)[*nrofresponses] = malloc(len+1); 

		//ToDO: strscpy
                strncpy((*respons_list)[*nrofresponses], ldaprecord, len+1);

		(*nrofresponses)++;
	}

	(*respons_list)[*nrofresponses] = NULL;

	return 1;
}
开发者ID:FlavioFalcao,项目名称:enterprise-search,代码行数:43,代码来源:boithoadClientLib.c


示例15: recibirStringEn

void recibirStringEn(int socket, char** stringReceptor){

	int tamanioString;

	tamanioString=recibirInt(socket);

	*stringReceptor = malloc(tamanioString);

	recvall(socket,*stringReceptor,tamanioString);

}
开发者ID:rmejiadelagala-utn,项目名称:TP1C2015MapReduce,代码行数:11,代码来源:envioDeMensajes.c


示例16: getshort

Uint16
getshort(TCPsocket sock)
{
   Uint16 cmd;
   Uint16 recvdata = recvall(sock, (unsigned char *) &cmd, sizeof(cmd));

   if (recvdata != sizeof(cmd))
   {
      return 0;
   }
   return SDLNet_Read16(&cmd);
}
开发者ID:pcoutin,项目名称:mazeoftorment,代码行数:12,代码来源:net.c


示例17: getint

Uint32
getint(TCPsocket sock)
{
   Uint32 cmd;
   int recvdata = recvall(sock, (unsigned char *) &cmd, sizeof(cmd));

   if (recvdata != sizeof(cmd))
   {
      return 0;
   }
   return SDLNet_Read32(&cmd);
}
开发者ID:pcoutin,项目名称:mazeoftorment,代码行数:12,代码来源:net.c


示例18: process_del_port

static int process_del_port(int client) {
    ctl_msg_del_port_t msg;
    msg.code = CTL_MSG_DEL_PORT_CODE;
    int n = recvall(client, ((char *) &msg) + 1, sizeof(ctl_msg_del_port_t) - 1);
    assert(n == sizeof(ctl_msg_del_port_t) - 1);
    errno = 0;
    int port_num = strtol(msg.iface, NULL, 10);
    // FIXME: Not sure how to convert interface string to int.
    assert(errno == 0);
    int status = del_port(port_num);
    send_status_reply(client, msg.request_id, status);
    return 0;
}
开发者ID:jack-songjian,项目名称:p4factory,代码行数:13,代码来源:main.c


示例19: sc_aggregator_connection_receive_message

int
sc_aggregator_connection_receive_message(sc_aggregator_connection* conn, sc_log_message** pmsg)
{
    char buf[offsetof(sc_log_message, content)];
    sc_log_message *m0 = (sc_log_message*)buf, *m = NULL;
    int32_t len;
    int n;

    n = recvall(conn->socket, buf, sizeof(buf), 0);
    if (n < 0) {
        close(conn->socket);
	conn->socket = -1;
        perror("recvall");
        return -1;
    } else if (n == 0) {
        az_log(LOG_DEBUG, "closed");
	return -4;
    }

    len = ntohl(m0->content_length);

    m = sc_log_message_new(len);
    if (!m) {
        return -2;
    }

    m->code    = ntohs(m0->code);
    m->channel = ntohs(m0->channel);

    if (m->content_length > 0) {
        if (recvall(conn->socket, m->content, m->content_length, 0) <= 0) {
            return -3;
        }
    }

    *pmsg = m;
    return 0;
}
开发者ID:koura-h,项目名称:compostela,代码行数:38,代码来源:connection.c


示例20: GetString

bool Server::GetString(int ID, std::string & _string)
{
	int bufferlength; //Holds length of the message
	if (!GetInt(ID, bufferlength)) //Get length of buffer and store it in variable: bufferlength
		return false; //If get int fails, return false
	char * buffer = new char[bufferlength + 1]; //Allocate buffer
	buffer[bufferlength] = '\0'; //Set last character of buffer to be a null terminator so we aren't printing memory that we shouldn't be looking at
	if (!recvall(ID, buffer, bufferlength)) //receive message and store the message in buffer array. If buffer fails to be received...
	{
		delete[] buffer; //delete buffer to prevent memory leak
		return false; //return false: Fails to receive string buffer
	}
	_string = buffer; //set string to received buffer message
	delete[] buffer; //Deallocate buffer memory (cleanup to prevent memory leak)
	return true;//Return true if we were successful in retrieving the string
}
开发者ID:GhostatSpirit,项目名称:StockExchangeSimulator,代码行数:16,代码来源:SendGetMethods.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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