当前位置: 首页>>代码示例>>C++>>正文


C++ recv_data函数代码示例

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


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


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