Ejemplo n.º 1
0
STATE send_data(uint8_t *packet, int32_t *packet_len, int32_t data_file, int32_t buf_size, int32_t *seq_num)
{
    uint8_t buf[MAX_LEN];
    int32_t len_read = 0;

    len_read = read(data_file, buf, buf_size);
    
    switch(len_read)
    {
        case -1:
            perror("send_data, read error");
            return DONE;
            break;
        case 0:
            (*packet_len) = send_buf(buf, 1, &server, END_OF_FILE, *seq_num, packet);
            printf("File Transfer Complete\n");
            return DONE;
            break;
        default:
            (*packet_len) = send_buf(buf, len_read, &server, DATA, *seq_num, packet);
            (*seq_num)++;
            return WAIT_ON_ACK;
            break;
    }
}
Ejemplo n.º 2
0
void child_main(int fd_client)
{
    int recv_len;
    recv_buf(fd_client,(char*)&recv_len,4);//length
    char filename[128]="";
    recv_buf(fd_client,filename,recv_len);
    printf("file :%s\n",filename);
    int fpsend = open(filename,O_RDONLY);
    if(fpsend == -1)
    {
        char nofile[128]="no file\n";
        int lenit = strlen(nofile);
        send(fd_client,(char*)&lenit,4,0);
        send_buf(fd_client,nofile,lenit);
        return;
    }
    char msg[1024];
    int sendlen;
    while(memset(msg,0,1023),sendlen = read(fpsend,msg,1024)!=0)
    {
        send(fd_client,(char *)&sendlen,4,0);
        send_buf(fd_client,msg,sendlen);
    }
    //send 0 to client?
}
Ejemplo n.º 3
0
void downFile(int fd_client, char *name)
{
	send(fd_client, "file", 8, 0);
	send(fd_client, name, 256, 0);
	int send_len;
	char msg[1024];
	char file_name[256] = "0";
	char dir[256] = "0";
	getcwd(dir, sizeof(dir));
	sprintf(file_name,"%s/%s",dir, name);
	name[strlen(file_name) -1] = '\0';
	int fd_file = open(file_name, O_RDONLY);
	if(fd_file == -1){
		perror("fd_file fail!\n");
		exit(1);
	}
	while(memset(&msg, 0, 1024), (send_len = read(fd_file, msg, 1024) ) != 0){
		if(send_len == -1){
			perror("read\n");
			exit(1);
		}
		send_buf(fd_client, (char*)&send_len, 4);
		send_buf(fd_client, msg, send_len);
	}
	send_len = 0;
	send_buf(fd_client, (char*)&send_len, 4);
	close(fd_file);

}
void ClientNetSocket::send()
{
    ASSERT(_peer != INVALID_SOCKET);
    try {
        if (_send_message) {
            _send_pos += send_buf(_send_message->data() + _send_pos,
                                  _send_message->size() - _send_pos);

            if (_send_pos != _send_message->size()) {
                return;
            } else {
                send_message_done();
            }
        }

        while (!_send_messages.empty()) {
            _send_message = _send_messages.front();
            _send_messages.pop_front();
            _send_pos = send_buf(_send_message->data(), _send_message->size());
            if (_send_pos != _send_message->size()) {
                return;
            } else {
                send_message_done();
            }
        }
    } catch (ClientNetSocket::SendException&) {
        close_and_tell();
    }
}
Ejemplo n.º 5
0
void StompStreamSocket::send_line(char* line)
{
    if (line != NULL) {
        printf("<-- SEND: %s\n", line);
        send_buf(line, strlen(line));
    }

    send_buf("\n", 1);
}
Ejemplo n.º 6
0
uint8_t SPI_SRAM_23K256_Init(struct ftdi_context *ftdi)
{
    char buf[16];

    // 23K256 Write Status to Disable HOLD

    // enable Chip Select signal
    buf[0] = SET_BITS_LOW;
    buf[1] = 0x00; // 0x00 = 0b00000000 ==> CS=Low
    buf[2] = 0x0B; // 0x0B = 0b00001011 ==> SK,DO,CS=Output

    // MPSSE command to clock data out on +ve edge, in on -ve edge
    buf[3] = 0x34;
    buf[4] = 0x01; // sending two bytes, command and data
    buf[5] = 0x00;
    buf[6] = 0x01; // Write Status byte to
    buf[7] = 0x01; // 0x01 ==> Byte Mode with Hold Pin Disabled

    // disable Chip Select signal
    buf[8] = SET_BITS_LOW;
    buf[9] = 0x08; // 0x08 = 0b00001000 ==> CS=High
    buf[10]= 0x0B; // 0x0B = 0b00001011 ==> SK,DO,CS=Output
    send_buf(ftdi, buf, 11);
    recv_buf(ftdi, buf, 1); // only one byte is read back

    sleep(0.1);

    // 23K256 Read STATUS

    // enable Chip Select signal
    buf[0] = SET_BITS_LOW;
    buf[1] = 0x00; // 0x08 = 0b00000000 ==> CS=Low
    buf[2] = 0x0B; // 0x0B = 0b00001011 ==> SK,DO,CS=Output

    // MPSSE command to clock data out on +ve edge, in on -ve edge
    buf[3] = 0x34;
    buf[4] = 0x01; // sending two bytes, command and data
    buf[5] = 0x00;
    buf[6] = 0x05; // read Status byte
    buf[7] = 0xFF; // force clocking in order to read byte by sending a byte

    // disable Chip Select signal
    buf[8] = SET_BITS_LOW;
    buf[9] = 0x08; // 0x08 = 0b00001000 ==> CS=High
    buf[10]= 0x0B; // 0x0B = 0b00001011 ==> SK,DO,CS=Output
    send_buf(ftdi, buf, 11);
    recv_buf(ftdi, buf, 3);

    if (DEBUG_LEVEL) {
        printf("Status Byte = 0x%02X\n\n", (uint8_t)buf[2]);
    }

    return (uint8_t)buf[2];
}
Ejemplo n.º 7
0
int send_message(int fd, struct metadata_update *msg, int tmo)
{
	__s32 len = msg->len;
	int rv;

	rv = send_buf(fd, &start_magic, 4, tmo);
	rv = rv ?: send_buf(fd, &len, 4, tmo);
	if (len > 0)
		rv = rv ?: send_buf(fd, msg->buf, msg->len, tmo);
	rv = send_buf(fd, &end_magic, 4, tmo);

	return rv;
}
Ejemplo n.º 8
0
static int send_optional_header(struct ploop_copy_handle *copy_h)
{
	int ret;
	struct ploop_pvd_header *vh;
	size_t block_size;
	struct ploop_pvd_ext_block_check *hc;
	struct ploop_pvd_ext_block_element_header *h;
	__u8 *block = NULL, *data;

	vh = (struct ploop_pvd_header *)copy_h->idelta.hdr0;
	block_size = vh->m_Sectors * SECTOR_SIZE;
	if (p_memalign((void **)&block, 4096, block_size))
		return SYSEXIT_MALLOC;

	hc = (struct ploop_pvd_ext_block_check *)block;
	h = (struct ploop_pvd_ext_block_element_header *)(hc + 1);
	data = (__u8 *)(h + 1);
	h->magic = EXT_MAGIC_DIRTY_BITMAP;

	ret = save_dirty_bitmap(copy_h->devfd, &copy_h->idelta,
			copy_h->eof_offset, data, &h->size,
			NULL, cbt_writer, copy_h);
	if (ret) {
		if (ret == SYSEXIT_NOCBT)
			ret = 0;
		goto out;
	}

	vh->m_DiskInUse = SIGNATURE_DISK_CLOSED_V21;
	vh->m_FormatExtensionOffset = (copy_h->eof_offset + SECTOR_SIZE - 1) / SECTOR_SIZE;
	if (send_buf(copy_h, vh, sizeof(*vh), 0)) {
		ploop_err(errno, "Can't write header");
		ret = SYSEXIT_WRITE;
		goto out;
	}
	ploop_log(3, "Send extension header offset=%llu size=%d",
			vh->m_FormatExtensionOffset * SECTOR_SIZE, h->size);
	hc->m_Magic = FORMAT_EXTENSION_MAGIC;
	MD5((const unsigned char *)(hc + 1), block_size - sizeof(*hc), hc->m_Md5);

	if (send_buf(copy_h, block, block_size, vh->m_FormatExtensionOffset * SECTOR_SIZE)) {
		ploop_err(errno, "Can't write optional header");
		ret = SYSEXIT_WRITE;
		goto out;
	}

out:
	free(block);

	return ret;
}
Ejemplo n.º 9
0
int
SendMailFile (FILE *in)
{
    char szBuffer[513];
    int _read_resp = 1;

    while (!feof (in))
    {
        int buf_len;
        if (!fgets (szBuffer, sizeof (szBuffer), in))
            continue;
        buf_len = strlen (szBuffer);
        while (buf_len > 0 && isspace (szBuffer[buf_len - 1]))
        {
            szBuffer[buf_len - 1] = 0;
            buf_len--;
        }
        fprintf (stdout, "%s\n", szBuffer);
        if (0 == strnicmp (szBuffer, "DATA", 4))
        {
            if (0 > send_buf ("%s\r\n", szBuffer))
                goto error;
            if (0 > read_resp (stdout))
                goto error;

            _read_resp = 0;
        }
        else if (0 == strcmp (szBuffer, "."))
        {
            if (0 > send_buf ("%s\r\n", szBuffer))
                goto error;
            if (0 > read_resp (stdout))
                goto error;
            _read_resp = 1;
        }
        else
        {
            if (0 > send_buf ("%s\r\n", szBuffer))
                goto error;
            if (_read_resp)
                if (0 > read_resp (stdout))
                    goto error;
        };
    };
    return TRUE;
error:
    return FALSE;
}
Ejemplo n.º 10
0
static void *sender_thread(void *data)
{
	struct ploop_copy_handle *h = data;
	struct sender_data *sd = &h->sd;
	int done;

	pthread_mutex_lock(&sd->mutex);
	ploop_dbg(3, "start sender_thread");
	pthread_barrier_wait(&sd->barrier);
	do {
		pthread_cond_wait(&sd->cond, &sd->mutex);

		wakeup(&sd->wait_mutex, &sd->wait_cond);

		sd->ret = send_buf(h, sd->buf, sd->len, sd->pos);
		if (sd->ret)
			sd->err_no = errno;
		done = (sd->len == 0 && sd->pos == 0);
	} while (!done);

	pthread_mutex_unlock(&sd->mutex);

	ploop_log(3, "send_thread exited ret=%d", sd->ret);
	return NULL;
}
Ejemplo n.º 11
0
void SPI_SRAM_23K256_Write_Byte(struct ftdi_context *ftdi, uint16_t address, uint8_t data)
{
    char buf[16];
    uint8_t bytesToTransfer = 4;

    // enable Chip Select signal
    buf[0] = SET_BITS_LOW;
    buf[1] = 0x00; // 0x00 = 0b00000000 ==> CS=Low
    buf[2] = 0x0B; // 0x0B = 0b00001011 ==> SK,DO,CS=Output

    // MPSSE command to clock data out on +ve edge, in on -ve edge
    buf[3] = 0x34;
    buf[4] = (bytesToTransfer - 1); // will be transferring 4 bytes so length=3
    buf[5] = 0x00;
    buf[6] = 0x02; // write
    buf[7] = (uint8_t)(address >> 8); // address high byte
    buf[8] = (uint8_t)(address); // address low byte
    buf[9] = data; // force clocking in order to read byte by sending a byte

    // disable Chip Select signal
    buf[10]= SET_BITS_LOW;
    buf[11]= 0x08; // 0x08 = 0b00001000 ==> CS=High
    buf[12]= 0x0B; // 0x0B = 0b00001011 ==> SK,DO,CS=Output
    send_buf(ftdi, buf, 13);
    recv_buf(ftdi, buf, bytesToTransfer); // same as number that will be transferred

    if (DEBUG_LEVEL) {
        printf("Byte written to address 0x%04X = 0x%02X\n\n", address, data);
    }
}
Ejemplo n.º 12
0
STATE filename(char *fname, int32_t buf_size)
{
    uint8_t packet[MAX_LEN];
    uint8_t buf[MAX_LEN];
    uint8_t flag = 0;
    int32_t seq_num = 0;
    int32_t fname_len = strlen(fname) + 1;
    int32_t recv_check = 0;

    memcpy(buf, &buf_size, 4);
    memcpy(&buf[4], fname, fname_len);

    send_buf(buf, fname_len + 4, &server, FNAME, 0, packet);

    if (select_call(server.sk_num, 1, 0, NOT_NULL) == 1) {
        recv_check = recv_buf(packet, 1000, server.sk_num, &server, &flag, &seq_num);

        /* check for bit flip ... if so, send the file name again */
        if (recv_check == CRC_ERROR)
            return FILENAME;

        if (flag == FNAME_BAD)
        {
            printf("File %s already exists and is write-protected\n", fname);
            return DONE;
        }

        return FILE_OK;
    }
    return FILENAME;
}
/*******************************************************************************
* Function Name  : send
* Description    : Send the protocol package via the socket.
* Input          : socket - the socket connection
*                  pack - the protocol package to be sent
* Output         : None
* Return         : If no error occurs, send returns the total number of bytes sent, 
*                  which can be less than the number requested to be sent in the len parameter. 
*                  Otherwise, a value of SOCKET_ERROR is returned
*******************************************************************************/
int Protocol::send(SOCKET socket, const ProtocolPackage& pack){
	//calculate the length of body
	unsigned int body_len = (unsigned char)pack.header.length[0] | (unsigned char)pack.header.length[1] << 8;
	//calculate the length of entire package
	int len = ProtocolHeader::SIZE + body_len + strlen(ProtocolPackage::EOP);
	//allocate the memory
	boost::shared_ptr<char> send_buf(new char[len], boost::checked_array_deleter<char>());
	char* pSendBuf = send_buf.get();
	//assign the header
	pSendBuf[0] = pack.header.mode;
	pSendBuf[1] = pack.header.type;
	pSendBuf[2] = pack.header.seq;
	pSendBuf[3] = pack.header.reserved;
	pSendBuf[4] = pack.header.pin[0];
	pSendBuf[5] = pack.header.pin[1];
	pSendBuf[6] = pack.header.pin[2];
	pSendBuf[7] = pack.header.pin[3];
	pSendBuf[8] = pack.header.pin[4];
	pSendBuf[9] = pack.header.pin[5];
	pSendBuf[10] = pack.header.length[0];
	pSendBuf[11] = pack.header.length[1];
	//assign the body
	for(unsigned int i = 0; i < body_len; i++){
		pSendBuf[ProtocolHeader::SIZE + i] = pack.body[i];
	}
	//assign the EOP
	for(unsigned int i = 0; i < strlen(ProtocolPackage::EOP); i++){
		pSendBuf[ProtocolHeader::SIZE + body_len + i] = *(ProtocolPackage::EOP + i);
	}
	//send the printer login buffer
	return ::send(socket, pSendBuf, len, 0);
}
Ejemplo n.º 14
0
int8_t nativenet_send(radio_packet_t *packet)
{
    packet->src = _native_net_addr;
    DEBUG("nativenet_send:  Sending packet of length %" PRIu16 " from %" PRIu16 " to %" PRIu16 "\n", packet->length, packet->src, packet->dst);

    return send_buf(packet);
}
Ejemplo n.º 15
0
std::vector<uint8_t>
Datagram_Handshake_IO::format_fragment(const uint8_t fragment[],
                                       size_t frag_len,
                                       uint16_t frag_offset,
                                       uint16_t msg_len,
                                       Handshake_Type type,
                                       uint16_t msg_sequence) const
   {
   std::vector<uint8_t> send_buf(12 + frag_len);

   send_buf[0] = static_cast<uint8_t>(type);

   store_be24(&send_buf[1], msg_len);

   store_be(msg_sequence, &send_buf[4]);

   store_be24(&send_buf[6], frag_offset);
   store_be24(&send_buf[9], frag_len);

   if (frag_len > 0)
      {
      copy_mem(&send_buf[12], fragment, frag_len);
      }

   return send_buf;
   }
Ejemplo n.º 16
0
void CRClient::sendIOtoRenderer (std::string io)
{
    boost::shared_ptr<std::string> send_buf(new std::string(io));
    rsocket.async_send_to(boost::asio::buffer(*send_buf), renderer_endpoint,
                          boost::bind(&CRClient::handle_rsend, this, send_buf,
                                      boost::asio::placeholders::error,
                                      boost::asio::placeholders::bytes_transferred));
}
Ejemplo n.º 17
0
static int cbt_writer(void *data, const void *buf, int len, off_t pos)
{
	struct ploop_copy_handle *h = (struct ploop_copy_handle *)data;

	h->eof_offset += len;

	return send_buf(h, buf, len, pos);
}
Ejemplo n.º 18
0
int main (int argc,char **argv){
   struct sockaddr_in server;
   struct fgetinfo    *p1;
   struct finfo       p4;
   char               buffer[10000];
   FILE *foutfd;
   
   char host[1000],fin[FILENAME_MAX],fout[FILENAME_MAX];
   int sock,port,connected,retval;
 
   parse(argc,argv,host,&port,fin,fout);
   
   /* PRINT PARSED ARGUMENTS */
   printf("Port %i<--\n",port);
   printf("Server %s<--\n",host);

   start_client(&sock,&server,port,host);
   printf("Starting communication\n\n");
   p1=get_info(fin);

   // Try to open out file
   if((foutfd=(FILE *)fopen(fout,"wb"))==NULL){
      printf("Out file could't be created or truncated for writing\n");
      exit(1);
   }
   
   connected=0;
   while (connected<3){
      connected++;
      send_buf(sock,&server,p1,sizeof(*p1));
      print_fgetinfo(*p1);
      
      if(receive(sock,buffer,sizeof(buffer))==0){
         memcpy(&p4,buffer,sizeof(p4));
         if(!check_finfo(p4)){
            connected=4;
            print_finfo(p4);
            if (p4.file_exist==1){
               // Start transfer
               retval=transfer(sock,&server,p4.file_id,foutfd,p4.file_size);
               fclose(foutfd);
               // Show transfer result
               exit(retval);
            }
            else{
               printf("\nERROR: Requested file does not exist on server\n\n");
               exit(1);
            }
         }
      }
   }
   if (connected==3){
      printf("\nERROR: Server not responding\n\n");
      exit(1);
   }
   exit (0);
}
Ejemplo n.º 19
0
static void get_send_irg(void)
{
	int i;
	for(i = 0; i < MAX_PORT; i++)
	{
		if(UART_GET_WST(i) & (i%8))
		{
			send_buf(&serial_devp[i]);
		}
	}
}
Ejemplo n.º 20
0
uint8_t nativenet_send(radio_packet_t *packet)
{
    packet->src = _native_net_addr;
    DEBUG("nativenet_send:  Sending packet of length %"PRIu16" from %"PRIu16" to %"PRIu16"\n", packet->length, packet->src, packet->dst);

    if (send_buf(packet) == -1) {
        warnx("nativenet_send: error sending packet");
        return 0;
    }
    return true;
}
Ejemplo n.º 21
0
int HTTP::download(ParsedLink link)
{
	s.reset();
	if(s.sock_create() == ERROR_FAIL)
		return ERROR_FAIL;
	DWORD address;
	if(get_address((char*)link.host.c_str(),&address) == ERROR_FAIL)
		return ERROR_FAIL;
	if(s.sock_connect(address,link.port) == ERROR_FAIL)
		return ERROR_FAIL;
	

	std::unique_ptr<char> send_buf(new char[2048]);
	int count = 0;
	count += sprintf(send_buf.get() + count,"GET %s HTTP/1.1\r\n",link.request.c_str());
	count += sprintf(send_buf.get() + count,"Host: %s\r\n",link.host.c_str());
	count += sprintf(send_buf.get() + count,"User-agent: Crawler-ke-wang-1.2\r\n");
	count += sprintf(send_buf.get() + count,"Connection: close\r\n");
	count += sprintf(send_buf.get() + count,"\r\n");
	send_buf.get()[count] = '\0';

	if(!s.sock_send(send_buf.get(),count))
		return ERROR_FAIL;

	if(!s.sock_recv())
		return ERROR_FAIL;
	try
	{
	if((head_start = s.get_header()) == NULL)
		return ERROR_FAIL;
	
	if((head_size = s.get_header_size()) == -1)
		return ERROR_FAIL;

	if((body_start = s.get_body()) == NULL)
		return ERROR_FAIL;

	if((body_size = s.get_body_size()) == -1)
		return ERROR_FAIL;
	}
	catch(...)
	{
		return ERROR_FAIL;
	}
	full_size = s.get_full_size();
	local_stat.download_size += full_size;

	if(!s.close())
		return ERROR_FAIL;

	return ERROR_SUCCESS;
}
Ejemplo n.º 22
0
Archivo: mtcp.c Proyecto: vjoel/mtcp
ssize_t mtcp_send_message(mtcp_state *pmts, const void *buf, size_t len)
{
    int         blocking;
    ssize_t     result;
    
    blocking = mtcp_get_block_state(pmts);
    if (blocking < 0) {
        return blocking;
    }
    
    if (pmts->lenbufpos < 4) {
        if (pmts->lenbufpos == 0) {
            *(uint32_t*)pmts->lenbuf = htonl(len);
        }
        result = send_buf(pmts->sock, pmts->lenbuf, &pmts->lenbufpos, 4, blocking);
        if (result <= 0) {
            return result;
        }
    }
    
    result = send_buf(pmts->sock, buf, &pmts->bufpos, len, blocking);
    return result;
}
Ejemplo n.º 23
0
int main(void) 
{

    uint8_t command;

    serial_init();
    trigger_setup();
    aes_setup();
#ifdef DELAYS
    random_setup();
#endif

    while(1) {
        command = usart_recv_byte();

        switch(command) {
            case 'e':
                fill_buf();
                random_setup();
                encrypt();
                send_buf();
                break;

            case 'd':
                fill_buf();
                random_setup();
                decrypt();
                send_buf();
                break;

            default:
                continue;
        }
    }
    return 0;
}
Ejemplo n.º 24
0
static int
send_str (SOCKET s, ...)
{
    va_list ap;
    char *p;
    int ret;
    size_t len;

    va_start (ap, s);
    p = vstrmake (&len, ap);
    va_end (ap);
    if (!p) return 1;
    ret = send_buf (s, p, len);
    heap_free (p);
    return ret;
}
Ejemplo n.º 25
0
void ParallelBFS::calculate(NodeId root) {
  distance.assign((size_t) vertex_count, infinity);
  NodeId level = 1;
  NodeList frontier;
  frontier.reserve((size_t)vertex_count);
  if (comm.rank() == find_owner(root)) {
    frontier.push_back(root - first_vertex);
    distance[root - first_vertex] = 0;
  }
  std::vector<NodeList> send_buf((size_t)comm.size());
  NodeList new_frontier;

  NodeList sizes((size_t)comm.size()),
           displacements((size_t)comm.size());

  while (mpi::all_reduce(comm, (NodeId)frontier.size(),
                         std::plus<NodeId>()) > 0) {
    for (NodeId u : frontier)
      for (int e = vertices[u]; e < vertices[u + 1]; ++e) {
        int v = edges[e];
        send_buf[find_owner(v)].push_back(v);
      }
    for (int i = 0; i < comm.size(); ++i) {
      mpi::gather(comm, (NodeId)send_buf[i].size(), sizes.data(), i);
      if (i == comm.rank()) {
        for (int j = 1; j < comm.size(); ++j)
          displacements[j] = displacements[j - 1] + sizes[j - 1];
        new_frontier.resize(
            (size_t)(displacements[comm.size()-1] + sizes[comm.size() - 1]));
        mpi::gatherv(comm, send_buf[i], new_frontier, sizes, displacements, i);
      } else {
        mpi::gatherv(comm, send_buf[i], i);
      }
    }
    for (size_t i = 0; i < comm.size(); ++i)
      send_buf[i].clear();
    frontier.clear();
    for (int v : new_frontier) {
      v -= first_vertex;
      if (distance[v] == infinity) {
        distance[v] = level;
        frontier.push_back(v);
      }
    }
    ++level;
  }
}
Ejemplo n.º 26
0
static ssize_t send_data(int fd, const char *fmt, ...)
{
	char buf[REMOTE_BUF_SIZE];
	va_list ap;
	int ret;

	if (verbose)
		dbg("called %s(fd, \"%s\", ...)", __FUNCTION__, fmt);

	va_start(ap, fmt);
	ret = __prepare_data(buf, sizeof(buf), fmt, ap);
	va_end(ap);
	if (ret < 0)
		return ret;

	return send_buf(fd, buf, ret);
}
Ejemplo n.º 27
0
void RDMACMSocket::setup_verbs_buf() {
        
    this->verbs_buf = Buffer::allocate(PACKET_SIZE * PACKET_WINDOW_SIZE * 2);

    this->verbs_mr = rdma_reg_msgs(this->client_id, this->verbs_buf.addr, this->verbs_buf.size);
    if (this->verbs_mr == NULL) {
	this->verbs_buf.free();
        rdma_destroy_ep(this->client_id);
	perror("rdma_reg_msgs");
	exit(1);
    }

    char* send_buf_begin = this->verbs_buf.addr + PACKET_SIZE * PACKET_WINDOW_SIZE;    
    for (int i = 0; i < PACKET_WINDOW_SIZE; ++i) {
	Buffer recv_buf(this->verbs_buf.addr + i * PACKET_SIZE, PACKET_SIZE);
	post_recv(recv_buf);
	Buffer send_buf(send_buf_begin + i * PACKET_SIZE, PACKET_SIZE);
       	send_bufs.push_back(send_buf);
    }
}
Ejemplo n.º 28
0
/** @brief Dump general infos
 *
 * Reply fields:
 *  - ROID (u8)
 *  - SPM_PAGESIZE value (u16)
 *  - supported features (SZ)
 *  - supported commands (SZ)
 *
 * Supported features are:
 *  - \c U if UART is enabled
 *  - \c S if I2C (as slave) is enabled
 *  - \c C if CRC check while programming is enabled
 *
 * @todo Return bitmasks, not strings.
 */
static void cmd_infos(void)
{
  static const uint8_t infos_buf[] = {
    ROID,
    SPM_PAGESIZE&0xff, (SPM_PAGESIZE>>8)&0xff,
    // features
#ifndef DISABLE_PROG_CRC
    'C',
#endif
#ifdef ENABLE_UART
    'U',
#endif
#ifdef ENABLE_I2C_SLAVE
    'S',
#endif
    0,
    // commands
    'i', 0xff, 'm',  // commands which cannot be disabled
#ifndef DISABLE_EXECUTE
    'x',
#endif
#ifndef DISABLE_PROG_PAGE
    'p',
#endif
#ifndef DISABLE_MEM_CRC
    'c',
#endif
#ifndef DISABLE_FUSE_READ
    'f',
#endif
#ifndef DISABLE_COPY_PAGES
    'y',
#endif
#ifdef ENABLE_I2C_MASTER
    '<', '>',
#endif
    0
  };
  reply_success(sizeof(infos_buf));
  send_buf(infos_buf, sizeof(infos_buf));
}
Ejemplo n.º 29
0
void CRClient::connectRenderer ()
{
    udp::resolver::query query(udp::v4(), renderer_ip.c_str(), renderer_port.c_str());
    renderer_endpoint = *rresolver.resolve(query);
    rsocket.open(udp::v4());

    rlisten ();
    //io_service.run();

    char conn = CONNECT;
    boost::shared_ptr<std::string> send_buf(new std::string(&conn));
    //	while (!connection) {
    rsocket.async_send_to(boost::asio::buffer(*send_buf), renderer_endpoint,
                          boost::bind(&CRClient::handle_rsend, this, send_buf,
                                      boost::asio::placeholders::error,
                                      boost::asio::placeholders::bytes_transferred));
    //	}

    std::cout << "Renderer Connection status " << connection << std::endl;
    run();
}
Ejemplo n.º 30
0
Archivo: pcopy.c Proyecto: avagin/ploop
static void *send_thread(void *data) {
	struct send_data *sd = data;
	int done;

	pthread_mutex_lock(&sd->mutex);
	do {
		while (!sd->has_data) {
			pthread_cond_wait(&sd->cond, &sd->mutex);
		}
		sd->ret = send_buf(sd->fd, sd->buf,
				sd->len, sd->pos, sd->is_pipe);
		if (sd->ret)
			sd->err_no = errno;
		done = (sd->len == 0 && sd->pos == 0);
		sd->has_data = 0;
		pthread_cond_signal(&sd->cond_sent);
	} while (!done);
	pthread_mutex_unlock(&sd->mutex);

	return NULL;
}