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

C++ recv_data函数代码示例

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

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



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

示例1: socks5_recv_resolve_ptr_reply

/*
 * Receive a Tor resolve ptr reply on the given connection. The hostname value
 * is populated with the returned name from Tor. On error, it's untouched. The
 * memory is allocated so the caller needs to free the memory on success.
 *
 * Return 0 on success else a negative value.
 */
ATTR_HIDDEN
int socks5_recv_resolve_ptr_reply(struct connection *conn, char **_hostname)
{
	int ret;
	ssize_t ret_recv;
	char *hostname = NULL;
	struct {
		struct socks5_reply msg;
		uint8_t len;
	} buffer;

	assert(conn);
	assert(conn >= 0);
	assert(_hostname);

	ret_recv = recv_data(conn->fd, &buffer, sizeof(buffer));
	if (ret_recv < 0) {
		ret = ret_recv;
		goto error;
	}

	if (buffer.msg.ver != SOCKS5_VERSION) {
		ERR("Bad SOCKS5 version reply");
		ret = -ECONNABORTED;
		goto error;
	}

	if (buffer.msg.rep != SOCKS5_REPLY_SUCCESS) {
		ERR("Unable to resolve. Status reply: %d", buffer.msg.rep);
		ret = -ECONNABORTED;
		goto error;
	}

	if (buffer.msg.atyp == SOCKS5_ATYP_DOMAIN) {
		/* Allocate hostname len plus an extra for the null byte. */
		hostname = zmalloc(buffer.len + 1);
		if (!hostname) {
			ret = -ENOMEM;
			goto error;
		}
		ret_recv = recv_data(conn->fd, hostname, buffer.len);
		if (ret_recv < 0) {
			ret = ret_recv;
			goto error;
		}
		hostname[buffer.len] = '\0';
	} else {
		ERR("Bad SOCKS5 atyp reply %d", buffer.msg.atyp);
		ret = -EINVAL;
		goto error;
	}

	*_hostname = hostname;
	DBG("[socks5] Resolve reply received: %s", *_hostname);
	return 0;

error:
	free(hostname);
	return ret;
}
开发者ID:Rafiot,项目名称:torsocks,代码行数:67,代码来源:socks5.c


示例2: ros_msg_recv

int ros_msg_recv(int socket,struct ROSMsg *msg) {
  int error=0,retval;
  ros_msg_init(msg);
  retval=recv_data(socket,msg,sizeof(struct ROSMsg));
  msg->buffer=(uint64)NULL;
  msg->vars=(uint64)NULL;

  if(retval!=sizeof(struct ROSMsg)) {
    printf("msg_recv:  msg error : %d\n",retval);
    error++;
  }

  msg->buffer=(uint64)malloc(msg->bytes);
  retval=recv_data(socket,(void *)msg->buffer,msg->bytes);
  if(retval!=msg->bytes) {
    printf("msg_recv: buffer err: %d\n",retval);
    error++;
  }
  msg->vars=(uint64)malloc(msg->num_vars*sizeof(struct msgvar));
  retval=recv_data(socket,(void *)msg->vars,msg->num_vars*sizeof(struct msgvar));
  if(retval!=msg->num_vars*sizeof(struct msgvar)) {
    printf("msg_recv: var err: %d\n",retval);
    error++;
  }
  if(error>0) return -1;
  return 0;

}
开发者ID:jspaleta,项目名称:SuperDARN_experimental_ROS,代码行数:28,代码来源:utils.c


示例3: memset

/*
 *              HANDLE_MSG()
 * send and recv data
 */
void epoll_server::handle_msg(int sock)
{
    int ret;
    char *recv_buf = new char[65535];
    char *send_buf = new char[65535];

    memset(recv_buf, 0, 65535);
    memset(send_buf, 0, 65535);

    recv_data(sock, recv_buf);

    if (m_clients_list.size() == 1) {
        if ((ret = send(sock, NO_CONNECTION, strlen(NO_CONNECTION), 0)) == -1) {
            cout << "send to myself error: " << strerror(errno)
                 << "(errno: " << errno << ")" << endl;
        }
    }

//    strcpy(send_buf, recv_buf);
//    memset(recv_buf, 0, 65535);
    sprintf(send_buf, CLIENT_NAME, sock);
    ret = strlen(CLIENT_NAME);
    strcpy((send_buf + (ret - 1)), recv_buf);

    list<int>::iterator it;
    for (it = m_clients_list.begin(); it != m_clients_list.end(); ++it) {
        if (*it != sock) {
            send_data(*it, send_buf, strlen(send_buf));
        }
    }

}
开发者ID:myler,项目名称:unix,代码行数:36,代码来源:epoll_server.cpp


示例4: main

int main(int argc,char* argv[])
{
	int port_fd;
	int len;
	char recv_buf[9];
	int i;

	if(argc!=3){
		printf("Usage: %s /dev/ttySn 0(send data)/1(receive data)\n",argv[0]);
		return -1;
	}

	port_fd=open_port(argv[1]);

	if(port_fd==-1){
		printf("Program Exit\n");
		return -1;
	}

	//设置串口通信参数
	struct port_info info;
	info.baud_rate=9600;
	info.data_bits=8;
 	info.flow_ctrl=2;
	info.port_fd=port_fd;
	info.stop_bit=1;
	info.parity=0;

	if(set_port(&info)==-1){
		printf("Program Exit\n");
		return -1;
	}
	
	if(strcmp(argv[2],"0")==0){
		for(i=0;i<10;i++){
			len=send_data(port_fd,"Test Data",9);

			if(len>0)
				printf("%d send data successfully\n",i);
			else 
				printf("send data failed\n");
			
			sleep(2);
		}
		close_port(port_fd);

	}else{
		while(1){
			len=recv_data(port_fd,recv_buf,9);

			if(len>0){
				for(i=0;i<len;i++)
					printf("receive data is %s\n",recv_buf);
			}else
				printf("cannot receive data\n");
			sleep(2);
		}
      }
	return 0;
}
开发者ID:1023xp,项目名称:training,代码行数:60,代码来源:p6.5.c


示例5: grpc_chttp2_transport_start_reading

void grpc_chttp2_transport_start_reading(grpc_transport *transport,
                                         gpr_slice *slices, size_t nslices) {
  grpc_chttp2_transport *t = (grpc_chttp2_transport *)transport;
  REF_TRANSPORT(t, "recv_data"); /* matches unref inside recv_data */
  gpr_slice_buffer_addn(&t->read_buffer, slices, nslices);
  recv_data(t, 1);
}
开发者ID:larsonmpdx,项目名称:grpc,代码行数:7,代码来源:chttp2_transport.c


示例6: ftserve_recv_cmd

/**
 * Wait for command from client and
 * send response
 * Returns response code
 */
int ftserve_recv_cmd(int sock_control, char*cmd, char*arg)
{	
	int rc = 200;
	char buffer[MAXSIZE];
	
	memset(buffer, 0, MAXSIZE);
	memset(cmd, 0, 5);
	memset(arg, 0, MAXSIZE);
		
	// Wait to recieve command
	if ((recv_data(sock_control, buffer, sizeof(buffer)) ) == -1) {
		perror("recv error\n"); 
		return -1;
	}
	
	strncpy(cmd, buffer, 4);
	char *tmp = buffer + 5;
	strcpy(arg, tmp);
	
	if (strcmp(cmd, "QUIT")==0) {
		rc = 221;
	} else if((strcmp(cmd, "USER")==0) || (strcmp(cmd, "PASS")==0) ||
			(strcmp(cmd, "LIST")==0) || (strcmp(cmd, "RETR")==0)) {
		rc = 200;
	} else { //invalid command
		rc = 502;
	}

	send_response(sock_control, rc);	
	return rc;
}
开发者ID:beckysag,项目名称:ftp,代码行数:36,代码来源:ftserve.c


示例7: listenEventBuffer

/**
 * Author: 	 	Joel Denke
 * Description:		Listen for data send by server and save to buffer
 * Return value: 	0 to signal game is ended
 */
int listenEventBuffer()
{
	int i, type, id;

	char * data = malloc(sizeof(char) * MESSAGE_SIZE);
	char * tmp = malloc(sizeof(char) * MESSAGE_SIZE);

	while (1) {
		if (state == gExit) {
			break;
		}

		data = (char*)recv_data(connection, 60);

		printf("Data %s\n", data);

		if (data != NULL) {
			type = atoi((char*)strsep(&data, ","));

			switch (type) {
				case 1:
				case 2:
				case 3:
					printf("Write %s to slot %d\n", data, type);
					SDL_mutexP(b_lock[type-1]);
					writeSlot(cb[type-1], data);
					SDL_mutexV(b_lock[type-1]);
					break;
			}
		}
	}

	return 0;
}
开发者ID:naknut,项目名称:Project-Puzzle,代码行数:39,代码来源:client.c


示例8: recv_data_new

/**
 * データ受信
 *
 * 新たに領域確保し, データを受信する.
 *
 * @param[in] sock ソケット
 * @param[in,out] length データ長
 * @return 受信されたデータポインタ
 * @retval NULL エラー
 */
void *
recv_data_new(const int sock, size_t *length)
{
    size_t len = *length; /* バイト数 */
    int retval = 0;       /* 戻り値 */
    void *rdata = NULL;   /* 受信データ */

    dbglog("start: length=%zu", *length);

    /* メモリ確保 */
    rdata = malloc(len);
    if (!rdata) {
        outlog("malloc: len= %zu", len);
        return NULL;
    }
    (void)memset(rdata, 0, len);

    /* データ受信 */
    retval = recv_data(sock, rdata, &len);
    if (retval < 0) { /* エラー */
        *length = 0;
        return rdata;
    }

    *length = len; /* 受信されたバイト数を設定 */
    return rdata;
}
开发者ID:sluchin,项目名称:calc,代码行数:37,代码来源:net.c


示例9: send_cmd

void http_client::http_request(const char *request)
{
    if (is_connected) {
        send_cmd(request);
        recv_data();
    }
}
开发者ID:flowsha,项目名称:cdma,代码行数:7,代码来源:http_class.c


示例10: socks5_recv_method

/*
 * Receive socks5 method response packet from server.
 *
 * Return 0 on success or else a negative errno value.
 */
ATTR_HIDDEN
int socks5_recv_method(struct connection *conn)
{
	int ret;
	ssize_t ret_recv;
	struct socks5_method_res msg;

	assert(conn);
	assert(conn->fd >= 0);

	ret_recv = recv_data(conn->fd, &msg, sizeof(msg));
	if (ret_recv < 0) {
		ret = ret_recv;
		goto error;
	}

	DBG("Socks5 received method ver: %d, method 0x%02x", msg.ver, msg.method);

	if (msg.ver != SOCKS5_VERSION ||
			msg.method == SOCKS5_NO_ACCPT_METHOD) {
		ret = -ECONNABORTED;
		goto error;
	}

	/* Successfully received. */
	ret = 0;

error:
	return ret;
}
开发者ID:Rafiot,项目名称:torsocks,代码行数:35,代码来源:socks5.c


示例11: main

int main(int argc, const char *argv[])
{
    const char* host = argv[1];                  // 目标主机
    char send_buff[SEND_BUF_SIZE];               // 发送缓冲区
    char recv_buf[RECV_BUFF_SIZE];               // 接收缓冲区
    size_t to_send_size = 0;                     // 要发送数据大小 
    int client_fd;                               // 客户端socket
    struct addrinfo *addr;                       // 存放getaddrinfo返回数据

    if (argc != 2) {
        printf("Usage:%s [host]\n", argv[0]);
        return 1;
    }


    addr = get_addr(host, "80");
    client_fd = create_socket(addr);
    connect_host(client_fd, addr);
    freeaddrinfo(addr);

    to_send_size = get_send_data(send_buff, SEND_BUF_SIZE, host);
    send_data(client_fd, send_buff, to_send_size);

    recv_data(client_fd, recv_buf, RECV_BUFF_SIZE);

    close(client_fd);
    return 0;
}
开发者ID:Taliens,项目名称:codesnip,代码行数:28,代码来源:socket_test.c


示例12: pasv

void pasv(srv_config *sCon, srv_config *spCon){
    printf("pasv\n");
    char pasv_data[512];
    char *buff = "PASV\r\n";
    if (send(sCon->sock, buff, strlen(buff), 0) == INVALID_SOCKET) return 0;
    char *recv_datas = recv_data(sCon->sock);
    printf(recv_datas);
    char *ip_tmp = strstr(recv_datas, "(");
    char ip[512];
    int port;
    char port_buffer[512];
    int pos = Extract(ip_tmp, ip, 1, ',');
    int i;
    for (i=0; i!=3; i++)
        if ((pos = Extract(ip_tmp, ip, pos, ',')) ==-1) exit(-1);
    ip[strlen(ip)-1] = '\0';
    CharReplace(ip, ',', '.');
    if ((pos = Extract(ip_tmp, port_buffer, pos, ',')) ==-1) exit(-1);
    port_buffer[strlen(port_buffer)-1] = '\0';
    port = atoi(port_buffer)*256;
    memset(port_buffer, '\0', strlen(port_buffer));
    if ((pos = Extract(ip_tmp, port_buffer, pos, ')')) ==-1) exit(-1);
    port_buffer[strlen(port_buffer)-1] = '\0';
    port = port+atoi(port_buffer);
    spCon->ip = ip;
    spCon->port = port;
    gen_baseinfo(spCon);
    printf("IP: %s Port: %d\n", spCon->ip, spCon->port);
}
开发者ID:NataliaSlabkiy,项目名称:smallFTP,代码行数:29,代码来源:SrvConfig.c


示例13: main

int main(int argc, char **argv)  
{  
	if (recv_data() < 0)
		return -1;

   return 0;  
}
开发者ID:dulton,项目名称:solotools,代码行数:7,代码来源:xvser_2.c


示例14: recv_tcp

static err_t recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) {
	// printf("kti: recv_tcp for %d called (pcb %p, pbuf %p, len %lu, err %d)\n", (int)arg, pcb, p, p->tot_len, err);
	if (p)
		return recv_data((int)arg, p);
	else
		return peerclosed_tcp((int)arg, pcb);
}
开发者ID:foreverlikeyou9999,项目名称:kos-ports,代码行数:7,代码来源:sockets.c


示例15: i2c_master_tx_rx

int i2c_master_tx_rx(uint8_t addr, uint8_t *tx_data, int tx_len, uint8_t *rx_data, int rx_len)
{
	int i;

	I2C0_SA = addr; // Set the slave addr

	I2C0_CNT = tx_len & 0xFF; // Set the tx data count
	I2C0_CON |= (1 << 9) | (1 << 10); // Set the Master Tx mode
	if (send_start()) I2C_QUIT_OP; // Trigger by sending Start
	for (i = 0; i < tx_len; i++) // Send Data
	{
		if (send_data(tx_data[i])) I2C_QUIT_OP;
	}
	while (!(I2C0_IRQSTATUS & I2C_ST_AR)) // Wait for ready for accessing registers after the tx complete
		;
	I2C0_IRQSTATUS |= I2C_ST_AR;
	I2C0_CNT = rx_len & 0xFF; // Set the rx data count
	I2C0_CON &= ~(1 << 9); // Set the Master Rx mode - note master is already set
	if (send_restart()) I2C_QUIT_OP; // Trigger by sending Start again
	for (i = 0; i < rx_len; i++) // Receive Data
	{
		if (recv_data(&rx_data[i])) I2C_QUIT_OP;
	}
	send_stop(); // Done, so Stop
	return 0;
}
开发者ID:litanparida1991,项目名称:bbb,代码行数:26,代码来源:i2c.c


示例16: tpm_tis_i2c_recv

static int tpm_tis_i2c_recv(struct tpm_chip *chip, u8 *buf, size_t count)
{
	int size = 0;
	int expected, status;

	if (count < TPM_HEADER_SIZE) {
		size = -EIO;
		goto out;
	}

	/* read first 10 bytes, including tag, paramsize, and result */
	size = recv_data(chip, buf, TPM_HEADER_SIZE);
	if (size < TPM_HEADER_SIZE) {
		dev_err(chip->dev, "Unable to read header\n");
		goto out;
	}

	expected = be32_to_cpu(*(__be32 *)(buf + 2));
	if ((size_t) expected > count) {
		size = -EIO;
		goto out;
	}

	size += recv_data(chip, &buf[TPM_HEADER_SIZE],
			  expected - TPM_HEADER_SIZE);
	if (size < expected) {
		dev_err(chip->dev, "Unable to read remainder of result\n");
		size = -ETIME;
		goto out;
	}

	wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c, &status);
	if (status & TPM_STS_DATA_AVAIL) {	/* retry? */
		dev_err(chip->dev, "Error left over data\n");
		size = -EIO;
		goto out;
	}

out:
	tpm_tis_i2c_ready(chip);
	/* The TPM needs some time to clean up here,
	 * so we sleep rather than keeping the bus busy
	 */
	usleep_range(SLEEP_DURATION_RESET_LOW, SLEEP_DURATION_RESET_HI);
	release_locality(chip, chip->vendor.locality, 0);
	return size;
}
开发者ID:AllenDou,项目名称:linux,代码行数:47,代码来源:tpm_i2c_infineon.c


示例17: zmq_assert

void zmq::norm_engine_t::in_event()
{
    // This means a NormEvent is pending, so call NormGetNextEvent() and handle
    NormEvent event;
    if (!NormGetNextEvent(norm_instance, &event))
    {
        // NORM has died before we unplugged?!
        zmq_assert(false);
        return;
    }

    switch(event.type)
    {
        case NORM_TX_QUEUE_VACANCY:
        case NORM_TX_QUEUE_EMPTY:
            if (!norm_tx_ready)
            {
                norm_tx_ready = true;
                send_data();
            }
            break;

        case NORM_RX_OBJECT_NEW:
            //break;
        case NORM_RX_OBJECT_UPDATED:
            recv_data(event.object);
            break;

        case NORM_RX_OBJECT_ABORTED:
        {
            NormRxStreamState* rxState = (NormRxStreamState*)NormObjectGetUserData(event.object);
            if (NULL != rxState)
            {
                // Remove the state from the list it's in
                // This is now unnecessary since deletion takes care of list removal
                // but in the interest of being clear ...
                NormRxStreamState::List* list = rxState->AccessList();
                if (NULL != list) list->Remove(*rxState);
            }
            delete rxState;
            break;
        }
        case NORM_REMOTE_SENDER_INACTIVE:
            // Here we free resources used for this formerly active sender.
            // Note w/ NORM_SYNC_STREAM, if sender reactivates, we may
            //  get some messages delivered twice.  NORM_SYNC_CURRENT would
            // mitigate that but might miss data at startup. Always tradeoffs.
            // Instead of immediately deleting, we could instead initiate a
            // user configurable timeout here to wait some amount of time
            // after this event to declare the remote sender truly dead
            // and delete its state???
            NormNodeDelete(event.sender);
            break;

        default:
            // We ignore some NORM events
            break;
    }
}  // zmq::norm_engine_t::in_event()
开发者ID:Bitiquinho,项目名称:libzmq,代码行数:59,代码来源:norm_engine.cpp


示例18: recv_udp

static void recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port) {
	// printf("kti: recv_udp for %d called\n", (int)arg);

	// This perhaps still needs work... depends on how lwIP implements
	// UDP routing internally. Could cause problems with having multiple UDP
	// connections if it does it wrong though.
	recv_data((int)arg, p);
}
开发者ID:foreverlikeyou9999,项目名称:kos-ports,代码行数:8,代码来源:sockets.c


示例19: hott_sensors_thread_main

int
hott_sensors_thread_main(int argc, char *argv[])
{
	warnx("starting");

	thread_running = true;

	const char *device = DEFAULT_UART;

	/* read commandline arguments */
	for (int i = 0; i < argc && argv[i]; i++) {
		if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--device") == 0) { //device set
			if (argc > i + 1) {
				device = argv[i + 1];

			} else {
				thread_running = false;
				errx(1, "missing parameter to -d\n%s", commandline_usage);
			}
		}
	}

	/* enable UART, writes potentially an empty buffer, but multiplexing is disabled */
	const int uart = open_uart(device);
	if (uart < 0) {
		errx(1, "Failed opening HoTT UART, exiting.");
		thread_running = false;
	}

	init_pub_messages();

	uint8_t buffer[MAX_MESSAGE_BUFFER_SIZE];
	size_t size = 0;
	uint8_t id = 0;
	while (!thread_should_exit) {
		// Currently we only support a General Air Module sensor.
		build_gam_request(&buffer[0], &size);
		send_poll(uart, buffer, size);

		// The sensor will need a little time before it starts sending.
		usleep(5000);

		recv_data(uart, &buffer[0], &size, &id);

		// Determine which moduel sent it and process accordingly.
		if (id == GAM_SENSOR_ID) {
			publish_gam_message(buffer);
		} else {
			warnx("Unknown sensor ID: %d", id);
		}
	}

	warnx("exiting");
	close(uart);
	thread_running = false;

	return 0;
}
开发者ID:3yc,项目名称:PX4Firmware,代码行数:58,代码来源:hott_sensors.cpp


示例20: check_transmission_chunks_recvd

        bool check_transmission_chunks_recvd()
        {
            if(request_ready())
            {
                return recv_data();
            }

            return next(&receiver::check_transmission_chunks_recvd);
        }
开发者ID:eile,项目名称:hpx,代码行数:9,代码来源:receiver.hpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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