示例#1
0
文件: socks5.c 项目: Rafiot/torsocks
/*
 * 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;
}
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;

}
示例#3
0
/**
 * 受信
 *
 * @param[in] sockfd ソケット
 * @param[in] rbuf 受信バッファ
 * @retval EX_NG エラー
 */
static int
recv_client(int sockfd, uchar *rbuf)
{
    size_t length = 0; /* バイト数 */
    struct header hd;  /* ヘッダ構造体 */
    int retval = 0;    /* 戻り値 */

    dbglog("start");

    /* ヘッダ受信 */
    length = sizeof(struct header);
    (void)memset(&hd, 0, length);

    retval = recv_data(sockfd, &hd, &length);
    if (retval < 0) {
        cut_notify("recv_data: length=%zu(%d)", length, errno);
        return EX_NG;
    }
    length = (size_t)ntohl((uint32_t)hd.length);

    /* 受信 */
    retval = recv_data(sockfd, rbuf, &length);
    if (retval < 0) {
        cut_notify("recv_data: length=%zu(%d)", length, errno);
        return EX_NG;
    }
    return EX_OK;
}
示例#4
0
int sanlock_read_lockspace(struct sanlk_lockspace *ls, uint32_t flags, uint32_t *io_timeout)
{
	struct sm_header h;
	int rv, fd;

	if (!ls || !ls->host_id_disk.path[0])
		return -EINVAL;

	rv = connect_socket(&fd);
	if (rv < 0)
		return rv;

	rv = send_header(fd, SM_CMD_READ_LOCKSPACE, flags,
			 sizeof(struct sanlk_lockspace),
			 0, 0);
	if (rv < 0)
		goto out;

	rv = send_data(fd, ls, sizeof(struct sanlk_lockspace), 0);
	if (rv < 0) {
		rv = -errno;
		goto out;
	}

	/* receive result, io_timeout and ls struct */

	memset(&h, 0, sizeof(h));

	rv = recv_data(fd, &h, sizeof(h), MSG_WAITALL);
	if (rv < 0) {
		rv = -errno;
		goto out;
	}

	if (rv != sizeof(h)) {
		rv = -1;
		goto out;
	}

	rv = (int)h.data;
	if (rv < 0)
		goto out;

	rv = recv_data(fd, ls, sizeof(struct sanlk_lockspace), MSG_WAITALL);
	if (rv < 0) {
		rv = -errno;
		goto out;
	}

	if (rv != sizeof(struct sanlk_lockspace)) {
		rv = -1;
		goto out;
	}

	*io_timeout = h.data2;
	rv = (int)h.data;
 out:
	close(fd);
	return rv;
}
示例#5
0
/*
 *              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));
        }
    }

}
示例#6
0
文件: p6.5.c 项目: 1023xp/training
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;
}
示例#7
0
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);
}
示例#8
0
文件: ftserve.c 项目: beckysag/ftp
/**
 * 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;
}
示例#9
0
/**
 * 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;
}
示例#10
0
文件: net.c 项目: sluchin/calc
/**
 * データ受信
 *
 * 新たに領域確保し, データを受信する.
 *
 * @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;
}
示例#11
0
void *dds_register_seq(void *arg)
{
  struct DriverMsg msg;
  struct ControlProgram *control_program;
  struct timeval t0,t1;
  int index;

  control_program=arg;
  pthread_mutex_lock(&dds_comm_lock);

  msg.type=DDS_REGISTER_SEQ;
  msg.status=1;
  send_data(ddssock, &msg, sizeof(struct DriverMsg));
  send_data(ddssock, control_program->parameters, sizeof(struct ControlPRM));
  index=control_program->parameters->current_pulseseq_index;
  send_data(ddssock, &index, sizeof(index)); //requested index
  send_data(ddssock,control_program->state->pulseseqs[index], sizeof(struct TSGbuf)); // requested pulseseq
/* JDS : 20121017 : TSGprm is deprecated and should not be used */
/*  send_data(ddssock,control_program->state->pulseseqs[index]->prm, sizeof(struct TSGprm)); // requested pulseseq */
  send_data(ddssock,control_program->state->pulseseqs[index]->rep, 
    sizeof(unsigned char)*control_program->state->pulseseqs[index]->len); // requested pulseseq
  send_data(ddssock,control_program->state->pulseseqs[index]->code, 
    sizeof(unsigned char)*control_program->state->pulseseqs[index]->len); // requested pulseseq
  recv_data(ddssock, &msg, sizeof(struct DriverMsg));
  pthread_mutex_unlock(&dds_comm_lock);
  pthread_exit(NULL);
}
示例#12
0
文件: http_class.c 项目: flowsha/cdma
void http_client::http_request(const char *request)
{
    if (is_connected) {
        send_cmd(request);
        recv_data();
    }
}
示例#13
0
文件: socks5.c 项目: Rafiot/torsocks
/*
 * 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;
}
示例#14
0
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;
}
示例#15
0
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);
}
示例#16
0
int main(int argc, char **argv)  
{  
	if (recv_data() < 0)
		return -1;

   return 0;  
}
示例#17
0
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);
}
示例#18
0
文件: i2c.c 项目: litanparida1991/bbb
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;
}
示例#19
0
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;
}
示例#20
0
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()
示例#21
0
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);
}
示例#22
0
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;
}
示例#23
0
文件: receiver.hpp 项目: eile/hpx
        bool check_transmission_chunks_recvd()
        {
            if(request_ready())
            {
                return recv_data();
            }

            return next(&receiver::check_transmission_chunks_recvd);
        }
示例#24
0
void zmq::norm_engine_t::restart_input()
{
    // TBD - should we check/assert that zmq_input_ready was false???
    zmq_input_ready = true;
    // Process any pending received messages
    if (!msg_ready_list.IsEmpty())
        recv_data(NORM_OBJECT_INVALID);

}  // end zmq::norm_engine_t::restart_input()
示例#25
0
文件: rtsp.c 项目: clkao/msdl
/*
 * receive rtsp message from stream->sock.
 *      header is guraranteed to be complete after this function,
 *      body should not be complete.
 *      get header only, have to get body later after this function.
 *               return status code : success
 *                               -1 : failure
 */
static int rtsp_recv_header_get(struct stream_t *stream, struct rtsp_header_t *rtsp_hdr)
{
    int ret = 0,i = 0,total = 0;
  
    rtsp_hdr->buffer_len = 0;
    rtsp_hdr->buffer = NULL;
    total = 0;
  
    do { /* get rtsp reply */
	rtsp_hdr->buffer_len += BUFSIZE_1K;
	rtsp_hdr->buffer = (char *)xrealloc(rtsp_hdr->buffer,
					    rtsp_hdr->buffer_len + 1);

	i = recv_data(stream,rtsp_hdr->buffer + total,BUFSIZE_1K);
	if(i <= 0) {
	    display(MSDL_ERR,"rtsp_recv_header error: recv_data() returned %d\n",i);
	    goto failed;
	}
	total += i;
    
	rtsp_hdr->buffer[total] = '\0'; /* for rtsp_is_entire_header */
    } while(!rtsp_is_entire_header(rtsp_hdr));
    
    /* rtsp_hdr->buffer_size is length in buffer, not the malloc()ed size.  */
    rtsp_hdr->buffer_len = total;
    rtsp_hdr->buffer[total] = '\0';
  

    ret = rtsp_response_parse(rtsp_hdr);
    if(ret < 0) {
	display(MSDL_ERR,"response RTSP header parse failed\n");
	goto failed;
    }

    /* push body back !!! */
    if(rtsp_hdr->body_len) {
	stream_data_push_back(stream,rtsp_hdr->body,rtsp_hdr->body_len);
    }
  
    /* rtsp_hdr->buffer *ONLY* contains header, no body follows */
    memset(rtsp_hdr->body,0,rtsp_hdr->body_len);

    /* dbg */
    display(MSDL_DBG,"rtsp header===========\n"
	    "%s\n"
	    "==(%d bytes)====================\n",
	    rtsp_hdr->buffer,strlen(rtsp_hdr->buffer));
  
 
   /* success */
    return rtsp_hdr->status_code;
  
  failed:
    if(rtsp_hdr->buffer) free(rtsp_hdr->buffer);
    rtsp_hdr->buffer = NULL;
    return -1;
}
示例#26
0
int tpm_tis_recv(struct tpm_chip* tpm, uint8_t* 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 */
   if((size =
	    recv_data(tpm, buf, TPM_HEADER_SIZE)) < TPM_HEADER_SIZE) {
      printk("Error reading tpm cmd header\n");
      goto out;
   }

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

   if((size += recv_data(tpm, & buf[TPM_HEADER_SIZE],
	       expected - TPM_HEADER_SIZE)) < expected) {
      printk("Unable to read rest of tpm command size=%d expected=%d\n", size, expected);
      size = -ETIME;
      goto out;
   }

   wait_for_stat(tpm, TPM_STS_VALID, tpm->timeout_c, &tpm->int_queue);
   status = tpm_tis_status(tpm);
   if(status & TPM_STS_DATA_AVAIL) {
      printk("Error: left over data\n");
      size = -EIO;
      goto out;
   }

out:
   tpm_tis_ready(tpm);
   release_locality(tpm, tpm->locality, 0);
   return size;
}
示例#27
0
int KSG_Service_Handler::handle_input(ACE_HANDLE fd /* = ACE_INVALID_HANDLE */)
{
	int ret;
	ACE_INET_Addr peer_addr;
	peer_.set_handle(fd);

	this->peer().get_remote_addr(peer_addr);
	//if(processing_)
	//{
	//	ACE_DEBUG((LM_INFO,"业务处理中,又接收到对方请求数据包!ip[%s]",peer_addr.get_host_addr()));
	//}
	//this->processing_ = 1;
	ret = recv_data(curr_blk_);

	if(ret == -1)
	{
		ACE_DEBUG((LM_TRACE,"从汇多设备接收数据错误!"));
		if(curr_blk_)
		{
			curr_blk_->release();
			curr_blk_ = NULL;
		}
		return -1;
	}
	else if(0 == ret)
	{
		// 继续读取
		//this->reactor()->register_handler(this,ACE_Event_Handler::READ_MASK);
		
		ACE_DEBUG((LM_TRACE,"继续读取后继数据ip[%s]",peer_addr.get_host_addr()));
		return 0;
	}
	else
	{
		if(curr_blk_==NULL)
		{
			return 0;
		}
		// 写入队列中,等待处理
		// 更新请求时间
		this->request_time_ = ACE_OS::gettimeofday();
		
		if(this->scheduler()->push_handle(this,curr_blk_) == -1)
		{
			// 写入处理队列失败,返回错误
			ACE_DEBUG((LM_ERROR,"写入请求队列失败"));
			curr_blk_->release();
			curr_blk_ = NULL;
			return -1;
		}
		curr_blk_ = NULL;
		return 0;
	}
}
static void *get_command(int s, struct OseGW_TransportHdr *hdr)
{
        void *buf;

        if (recv_data(s, hdr, sizeof(*hdr)) == -1)
                return NULL;

        hdr->payload_type = ntohl(hdr->payload_type);
        hdr->payload_len = ntohl(hdr->payload_len);

        buf = malloc(hdr->payload_len);
        if (buf == NULL)
                return NULL;

        if (recv_data(s, buf, hdr->payload_len) == -1) {
                free(buf);
                return NULL;
        }
        return buf;
}
示例#29
0
文件: client.cpp 项目: tinnfu/ftp
int client::pwd()
{
    int res = 0;
    char path[BUFFSIZE] = {0};

    if( m_guider.is_at_local() )
    {
        cout << (NULL != m_guider.pwd(path, BUFFSIZE) ?
                path : " ")
            << endl;
    }
    else
    {
        //reply(PT_PWD);
        
        m_buff.clear();
        
        // Add the pack type.
        m_buff.push_front(PT_PWD);

        // Add the checkcode.
        m_buff.push_back(PT_PWD);

        if(-1 == send_data())
        {
            return -1; // Send error.
        }

        // Receive path information.
        if( -1 == recv_data() )
        {
            ;// Error
        }

        if( is_pack_type(PT_DATA,
            m_analyser.get_pack_type()) )
        {
            // Delete the pack type.
            m_buff.pop_front();

            get_buff(path, BUFFSIZE);

            cout << path << endl;
        }
        else
        {
            ; // Uninterested package.
        }

    }

    return res;
}
示例#30
0
int
monitor_bind(int s, struct sockaddr *name, socklen_t namelen)
{
	enum monitor_command cmd;
	int ret, serrno;

	cmd = CMD_BIND;
	send_data(fd_monitor, &cmd, sizeof(cmd));

	send_fd(fd_monitor, s);
	send_data(fd_monitor, &namelen, sizeof(namelen));
	send_data(fd_monitor, name, namelen);

	recv_data(fd_monitor, &ret, sizeof(ret));
	if (ret == -1) {
		recv_data(fd_monitor, &serrno, sizeof(serrno));
		errno = serrno;
	}

	return (ret);
}