Exemple #1
1
static void test4() {
    struct Buffer *buffer;
    int read_fd, write_fd;

    buffer = new_buffer(4096, EV_DEFAULT);

    read_fd = open("/dev/zero", O_RDONLY);
    if (read_fd < 0) {
        perror("open:");
        exit(1);
    }

    write_fd = open("/dev/null", O_WRONLY);
    if (write_fd < 0) {
        perror("open:");
        exit(1);
    }

    while (buffer->tx_bytes < 65536) {
        buffer_read(buffer, read_fd);
        buffer_write(buffer, write_fd);
    }

    free_buffer(buffer);
}
Exemple #2
0
static int extent_read(struct fs *fs, struct extent *e, char *buf,
		       offset_t off, offset_t len)
{
	assert(fs);
	assert(e);
	assert(buf);

	switch (e->type) {
	case EXTENT_TYPE_BOOT:
		return buffer_read((char*)&fs->boot, sizeof(fs->boot), buf,
				   off, len);
	case EXTENT_TYPE_INFO:
		return buffer_read((char*)&fs->info, sizeof(fs->info), buf,
				   off, len);
	case EXTENT_TYPE_FAT:
		return buffer_read((char*)fs->fat, fs->fat_size, buf,
				   off, len);
	case EXTENT_TYPE_FILE:
		return file_read((struct file *)e, buf, off, len);
	case EXTENT_TYPE_DIR:
		return dir_read((struct dir *)e, buf, off, len);
	default:
		WARN("reading extent: unexpected type %d\n", e->type);
		return -1;
	}
}
Exemple #3
0
int sec_read(int fd, void *data, int length)
{
	size_t len;
	int rx = 0;

	if (ftp->sec_complete == 0 || ftp->data_prot == 0)
		return read(fd, data, length);

	if (ftp->in_buffer.eof_flag) {
		ftp->in_buffer.eof_flag = 0;
		return 0;
	}

	len = buffer_read(&ftp->in_buffer, data, length);
	length -= len;
	rx += len;
	data = (char *)data + len;

	while (length) {
		if (sec_get_data(fd, &ftp->in_buffer, ftp->data_prot) < 0)
			return -1;
		if (ftp->in_buffer.size == 0) {
			if (rx)
				ftp->in_buffer.eof_flag = 1;
			return rx;
		}
		len = buffer_read(&ftp->in_buffer, data, length);
		length -= len;
		rx += len;
		data = (char *)data + len;
	}
	return rx;
}
Exemple #4
0
int
Curl_sec_read(struct connectdata *conn, int fd, void *buffer, int length)
{
    size_t len;
    int rx = 0;

    if(conn->sec_complete == 0 || conn->data_prot == 0)
      return read(fd, buffer, length);

    if(conn->in_buffer.eof_flag){
      conn->in_buffer.eof_flag = 0;
      return 0;
    }
    
    len = buffer_read(&conn->in_buffer, buffer, length);
    length -= len;
    rx += len;
    buffer = (char*)buffer + len;
    
    while(length) {
      if(sec_get_data(conn, fd, &conn->in_buffer) < 0)
        return -1;
      if(conn->in_buffer.size == 0) {
        if(rx)
          conn->in_buffer.eof_flag = 1;
        return rx;
      }
      len = buffer_read(&conn->in_buffer, buffer, length);
      length -= len;
      rx += len;
      buffer = (char*)buffer + len;
    }
    return rx;
}
Exemple #5
0
static word network_regs_get_put(armaddr_t address, word data, int size, int put)
{
    word val;
    uint offset;

    SYS_TRACE(5, "sys: network_regs_get_put at 0x%08x, data 0x%08x, size %d, put %d\n",
              address, data, size, put);

    switch (address) {
        case NET_HEAD:
            /* head is read/only */
            val = network->head;
            break;
        case NET_TAIL:
            if (put) {
                network->tail = data % PACKET_QUEUE_LEN;
                if (network->head == network->tail) {
                    pic_deassert_level(INT_NET);
                }
            }
            val = network->tail;
            break;
        case NET_SEND:
            if (put) {
                write(network->fd, network->out_packet, network->out_packet_len);
            }
            val = 0;
            break;
        case NET_SEND_LEN:
            if (put) {
                network->out_packet_len = data % PACKET_LEN;
            }
            val = network->out_packet_len;
            break;
        case NET_IN_BUF_LEN:
            /* read/only */
            val = network->in_packet_len[network->tail];
            break;
        case NET_OUT_BUF...(NET_OUT_BUF + NET_BUF_LEN - 1):
            offset = address - NET_OUT_BUF;
            if (put) {
                val = buffer_write(network->out_packet, offset, data, size);
            } else {
                val = buffer_read(network->out_packet, offset, size);
            }
            break;
        case NET_IN_BUF...(NET_IN_BUF + NET_BUF_LEN - 1):
            offset = address - NET_IN_BUF;

            /* in buffers are read/only */
            val = buffer_read(network->in_packet[network->tail], offset, size);
            break;
        default:
            SYS_TRACE(0, "sys: unhandled network address 0x%08x\n", address);
            return 0;
    }

    return val;
}
Exemple #6
0
static const_string_t *read_string(su_state *s, reader_buffer_t *buffer) {
	const_string_t *str;
	unsigned size;

	if (buffer_read(s, buffer, &size, sizeof(unsigned)))
		return NULL;

	str = su_allocate(s, NULL, sizeof(unsigned) + size + 1);
	if (buffer_read(s, buffer, str->str, size))
		return NULL;

	str->size = size;
	str->str[size] = '\0';
	return str;
}
Exemple #7
0
static int i_read_data(void *opaque, uint8_t *buf, int buf_size)
{
	//printf("i_read_data run \n");
	
	BufferContext *tx = (BufferContext *)opaque;
	int64_t dsize = tx->size;
	int64_t rsize = tx->cur_read_pos;
	int64_t nsize = (int64_t)buf_size;
	int ret = 0;
redo:	
	if(nsize >= dsize - rsize) //δ´¦Àí
		nsize = dsize - rsize;
	
	ret = buffer_read(tx, buf, nsize);
	if(ret == -2 || ret == -3) {
		usleep(2);
		goto redo;
	} else if(ret == -1) {
		printf("o---size > tail size\n");
		return 0;
	} else {
		
	}
	
	return nsize;
}
Exemple #8
0
static buffer_t *buffers_readfile(FILE *f, const char *filename, int noro)
{
	buffer_t *b;
	int nread;

	nread = buffer_read(&b, f);

	if(nread == -1){
		gui_status(GUI_ERR, "read \"%s\": %s",
				filename,
				errno ? strerror(errno) : "unknown error - binary file?");

	}else{
		if(!noro)
			buffer_readonly(b) = access(filename, W_OK);

		if(nread == 0)
			gui_status(GUI_NONE, "%s: empty file%s", filename, buffer_readonly(b) ? " [read only]" : "");
		else
			gui_status(GUI_NONE, "%s%s: %dC, %dL%s%s",
					filename,
					buffer_readonly(b) ? " [read only]" : "",
					buffer_nchars(b),
					buffer_nlines(b),
					buffer_eol(b)  ? "" : " [noeol]",
					buffer_crlf(b) ? " [crlf]" : ""
					);
	}

	return b;
}
Exemple #9
0
Fichier : dns.c Projet : lc7cl/www
int get_record(buffer_type *buffer,
               struct decompress_ctx * decompress, 
               struct rr *record)
{
    int ret;
    
    if (buffer == NULL || record == NULL)
        return -1;
    ret = dns_name_from_wire(buffer, decompress, record->name);
    if (ret == -1)
        return -1;
    if (!buffer_available(buffer, 2 * sizeof(u_int16_t)))
        return -1;
    record->type = buffer_read_u16(buffer);
    buffer_skip(buffer, 
                sizeof(u_int16_t) + sizeof(u_int32_t) + sizeof(u_int16_t));
    switch (record->type) {
    case TYPE_A:
        if (!buffer_available(buffer, sizeof(u_int32_t)))
            return -1;
        buffer_read(buffer, record->rdata, 4);
        break;
    case TYPE_CNAME:
        ret = dns_name_from_wire(buffer, decompress, record->rdata);
        if (ret == -1)
            return ret;
        break;
    default:
        return -1;
    }
    return 0;
}
Exemple #10
0
int getpixelv(buffer_t *sound_buffer, apt_t *apt, float *pvbuff, int nb)
{
    int n;

    for (n = 0; n < nb; n++) {
	double mult;
	int shift;

	if (apt->nam < BLKAMP) {
	    int res;
	    memmove(apt->ambuff, &(apt->ambuff[apt->idxam]), apt->nam * sizeof(float));
	    apt->idxam = 0;

	    float sound_buff[BLKAMP];
	    int num_samples = BLKAMP - apt->nam;
	    res = buffer_read(sound_buffer, num_samples, sound_buff);
	    getamp(&(apt->phaselock_state), &(apt->ambuff[apt->nam]), sound_buff, res);
	    apt->nam += res;
	    if (apt->nam < BLKAMP)
		return (n);
	}

	mult = (double) Fi * apt->phaselock_state.fr / Fc * apt->FreqLine;

	pvbuff[n] =
	    rsfir(&(apt->ambuff[apt->idxam]), rsfilter, RSFilterLen, offset,
		  mult) * mult * 2 * 256.0;

	shift = (int) ((RSMULT - offset + mult - 1) / mult);
	offset = shift * mult + offset - RSMULT;
	apt->idxam += shift;
	apt->nam -= shift;
    }
    return (nb);
}
Exemple #11
0
static int dir_read(struct dir *d, char *buf, offset_t off, offset_t len)
{
	assert(d);
	assert(buf);

	return buffer_read((char*)d->entries, d->size, buf, off, len);
}
Exemple #12
0
/*****************************************************************************
 * GdipCreateRegionRgnData [GDIPLUS.@]
 */
GpStatus WINGDIPAPI GdipCreateRegionRgnData(GDIPCONST BYTE *data, INT size, GpRegion **region)
{
    const struct region_data_header *region_data_header;
    struct memory_buffer mbuf;
    GpStatus status;
    INT count;

    TRACE("(%p, %d, %p)\n", data, size, region);

    if (!data || !size)
        return InvalidParameter;

    init_memory_buffer(&mbuf, data, size);

    region_data_header = buffer_read(&mbuf, sizeof(*region_data_header));
    if (!region_data_header || !VALID_MAGIC(region_data_header->header.magic))
        return InvalidParameter;

    status = GdipCreateRegion(region);
    if (status != Ok)
        return status;

    count = 0;
    status = read_element(&mbuf, *region, &(*region)->node, &count);
    if (status == Ok && !count)
        status = InvalidParameter;

    if (status != Ok)
    {
        GdipDeleteRegion(*region);
        *region = NULL;
    }

    return status;
}
Exemple #13
0
GpStatus WINGDIPAPI GdipCreateRegionRgnData(GDIPCONST BYTE *data, INT size, GpRegion **region)
{
    GpStatus status;
    struct memory_buffer mbuf;
    const struct region_header *region_header;
    INT count;

    if (!data || !size) return InvalidParameter;

    TRACE("%p, %d, %p\n", data, size, region);

    init_memory_buffer(&mbuf, data, size);

    region_header = buffer_read(&mbuf, sizeof(struct region_header));
    if (!region_header || region_header->magic != VERSION_MAGIC)
        return InvalidParameter;

    status = GdipCreateRegion(region);
    if (status != Ok) return status;

    count = 0;
    status = read_element(&mbuf, *region, &(*region)->node, &count);
    if (status == Ok && !count)
        status = InvalidParameter;

    if (status != Ok)
        GdipDeleteRegion(*region);

    return status;
}
Exemple #14
0
/**
 *  call-seq:
 *    Rev::Buffer#read(length = nil) -> String
 * 
 * Read the specified abount of data from the buffer.  If no value
 * is given the entire contents of the buffer are returned.  Any data
 * read from the buffer is cleared.
 */
static VALUE Rev_Buffer_read(int argc, VALUE *argv, VALUE self)
{
  VALUE length_obj, str;
  int length;
  struct buffer *buf;

  Data_Get_Struct(self, struct buffer, buf);

  if(rb_scan_args(argc, argv, "01", &length_obj) == 1) {
    length = NUM2INT(length_obj);
  } else {
    if(buf->size == 0)
      return rb_str_new2("");

    length = buf->size;
  }

  if(length > buf->size)
    length = buf->size;

  if(length < 1)
    rb_raise(rb_eArgError, "length must be greater than zero");

  str = rb_str_new(0, length);
  buffer_read(buf, RSTRING_PTR(str), length);

  return str;
}
Exemple #15
0
static inline void unpack(struct connection *c)
{
	uint32_t pk_len = 0;
	uint32_t pk_total_size;
	rpacket_t r;
	for(;;)
	{

		if(!c->raw)
		{		
			if(c->unpack_size <= sizeof(uint32_t))
				break;//return 0;
			buffer_read(c->unpack_buf,c->unpack_pos,(int8_t*)&pk_len,sizeof(pk_len));
			pk_total_size = pk_len+sizeof(pk_len);
			if(pk_total_size > c->unpack_size)
				break;//return 0;
			r = rpacket_create(c->mt,c->rpacket_allocator,c->unpack_buf,c->unpack_pos,pk_len,c->raw);
			//调整unpack_buf和unpack_pos
			while(pk_total_size)
			{
				uint32_t size = c->unpack_buf->size - c->unpack_pos;
				size = pk_total_size > size ? size:pk_total_size;
				c->unpack_pos  += size;
				pk_total_size  -= size;
				c->unpack_size -= size;
				if(c->unpack_pos >= c->unpack_buf->capacity)
				{
					/* unpack之前先执行了update_next_recv_pos,在update_next_recv_pos中
					*  如果buffer被填满,会扩展一块新的buffer加入链表中,所以这里的
					*  c->unpack_buf->next不应该会是NULL
					*/
					assert(c->unpack_buf->next);
					c->unpack_pos = 0;
					c->unpack_buf = buffer_acquire(c->unpack_buf,c->unpack_buf->next);
				}
			}
		}
		else
		{
			pk_len = c->unpack_buf->size - c->unpack_pos;
			if(!pk_len)
				return; 
			r = rpacket_create(c->mt,NULL,c->unpack_buf,c->unpack_pos,pk_len,c->raw);
			c->unpack_pos  += pk_len;
			c->unpack_size -= pk_len;
			if(c->unpack_pos >= c->unpack_buf->capacity)
			{
				/* unpack之前先执行了update_next_recv_pos,在update_next_recv_pos中
				*  如果buffer被填满,会扩展一块新的buffer加入链表中,所以这里的
				*  c->unpack_buf->next不应该会是NULL
				*/
				assert(c->unpack_buf->next);
				c->unpack_pos = 0;
				c->unpack_buf = buffer_acquire(c->unpack_buf,c->unpack_buf->next);
			}
		}
		c->_process_packet(c,r);
	}
	//return r;
}
Exemple #16
0
/**
 * reads the image data of a tga file into a buffer
 */
int tga_image_read(int fd, tga_header *h, void *data)
{
    lseek(fd, h->id_len, SEEK_CUR); //ignore optional ID field

    if(!tga_header_is_valid(h)){
        assert(false && "Invalid TGA file");
        return -1;
    }

    //unsigned int cm_sz = tga_colormap_sz(h);
    //unsigned int img_sz = tga_image_sz(h);
    if(HAS_CMAP(*h)){
        assert(false && "TGA Color map not yet supported");
            //cmap = malloc(cm_sz); ///<@TODO: proper color map for tga
            //read(fd, cmap, cm_sz); 
    }
    
    uint8_t nrepeat = 0;
    uint8_t rle_flag = 0;
    uint8_t Bpp = tga_pxl_sz(h);

    uint8_t buf[BUF_SZ];
    struct buffer_t buffer = {BUF_SZ, BUF_SZ, buf};

    int i, j;
    for(j = 0; j < h->img.h; j++){
        for(i = 0; i < h->img.w; i++, data = (void*)OFFSET(data,Bpp)){

            if(nrepeat == 0 && HAS_RLE(*h)){
                uint8_t rle_pkt;
                buffer_read(&buffer, fd, 1, &rle_pkt);
                rle_flag = rle_pkt & RLE_FLAG_MASK;
                nrepeat  = rle_pkt & RLE_REPEAT_MASK;
                ///<@TODO: include cmap indexing
                buffer_read(&buffer, fd, Bpp, data);
                continue;
            }
            if(rle_flag){
                memcpy(data, OFFSET(data, -Bpp), Bpp);
            } else {
                buffer_read(&buffer, fd, Bpp, data);
            }
            nrepeat--;
        }
    }
    return errno;
}
Exemple #17
0
uint8_t uart1_read()
{
	uint8_t byte;
	uart1_int_disable();
	byte = buffer_read(&buffer_rx1);
	uart1_int_enable();
	return byte;
}
Exemple #18
0
// Read some data. Returns bytes read
int s_read(int fd, void *buf, int len) {
    if (len > S_MAXBUF || len < 0)
        return FR_INVALID_PARAMETER;
    simplecall(c_read, fd, 0, len);
    len = get_length();
    buffer_read(buf, len);
    return len;
}
Exemple #19
0
static void buffer_clear(PayloadBuffer *b)
{
    while (!buffer_empty(b)) {
        Payload *p;
        buffer_read(b, &p);
        free(p);
    }
}
static int decode_read_byte( rawbuffer * buf )
{
	char * p = buffer_read(buf, 1);
	if(p) {
		return *p;
	}
	return 0;
}
Exemple #21
0
int usock_read(USocket *usock, void *data, Uint32 size)
{
	int retval = -1;

	if (size <= 0)
		return 0;

	if (usock->status & USOCK_CLOSE)
		return -1;
	if (!(usock->status & USOCK_CONNECT))
		return 0;

	pthread_mutex_lock(&usock->rlock);

	if (usock->tsize > 0) {
		int n = buffer_write(usock->rbuf, usock->tbuf, usock->tsize);
		usock->tsize -= n;

		if (usock->tsize == 0) {
			int timeout = 1;
			int ret;
			Uint32 mcount = htonl(usock->r_pack_count);
			while (timeout < 16) {
				struct timespec tsp;
				maketimeout(&tsp, timeout);
				if (send_umsg(usock, UMSG_CONT, &mcount, sizeof(mcount)) < 0)
					return -1;
				ret = pthread_cond_timedwait(&usock->rcond, &usock->rlock, &tsp);
				if (ret == 0)
					break;
				if (ret != ETIMEDOUT)
					return -1;
				timeout *= 2;
			}
			if (timeout >= 16)
				return -1;
		}
	}

	while (buffer_empty(usock->rbuf)) {
		if (usock->status & USOCK_CLOSE)
			goto err;
		if (!(usock->status & USOCK_CONNECT)) {
			retval = 0;
			goto err;
		}

		pthread_cond_wait(&usock->rcond, &usock->rlock);
	}

	retval = buffer_read(usock->rbuf, data, size);

err:
	pthread_mutex_unlock(&usock->rlock);
	pthread_cond_signal(&usock->wcond);

	return retval;
}
void bufreverse_process_internal(t_bufreverse *x, t_symbol *sym, short argc, t_atom *argv)
{
    t_symbol *target = atom_getsym(argv++);
    t_symbol *source = atom_getsym(argv++);

    float *temp1;
    double *temp2;

    t_buffer_write_error error;

    AH_SIntPtr full_length = buffer_length(source);
    AH_SIntPtr i;

    double sample_rate = 0;
    t_atom_long read_chan = x->read_chan - 1;

    // Check source buffer

    if (buffer_check((t_object *) x, source, read_chan))
        return;
    sample_rate = buffer_sample_rate(source);

    // Allocate Memory

    temp1 = (float *) ALIGNED_MALLOC(full_length * (sizeof(double) + sizeof(float)));
    temp2 = (double *) (temp1 + full_length);

    // Check momory allocation

    if (!temp1)
    {
        object_error((t_object *)x, "could not allocate temporary memory for processing");
        free(temp1);
        return;
    }

    // Read from buffer

    buffer_read(source, read_chan, (float *) temp1, full_length);

    // Copy to double precision version

    for (i = 0; i < full_length; i++)
         temp2[i] = temp1[full_length - i - 1];

    // Copy out to buffer

    error = buffer_write(target, temp2, full_length, x->write_chan - 1, x->resize, sample_rate, 1.);
    buffer_write_error((t_object *)x, target, error);

    // Free Resources

    ALIGNED_FREE(temp1);

    if (!error)
        outlet_bang(x->process_done);
}
Exemple #23
0
int main (void) {
   unsigned char kommando[32];                    		// Kommandozeilenbuffer
   unsigned char* k_sp = kommando;		  		// und dazugehöriger Pointer
   volatile struct buffer put_buffer, get_buffer; 		// Sende- u. Empfangsbuffer

   buffer_init(put_buffer);
   buffer_init(get_buffer);
   put_bp=&put_buffer;
   get_bp=&get_buffer;

   DDRD  = 0xE0;         // Port D, Pin 6,7,8 als Ausgang

   tim0_init();          // Initialisiere Timer_0
   tim1_init();          // Initialisiere Timer_1
   tim2_init();          // Initialisiere Timer_2
   uart_init();          // Initialisiere serielle Schnittstelle
   adc_init();		 // Initialisiere Analog-Digitalwandler ADC

   uart_puts(version);	 // Startmeldung/Version ausgeben
   beep(1000);
   uart_puts("\n> ");    // newline und prompt
   UCSRB |= (1<<RXCIE);  // Empfaenger-Interrupts freigeben
   sei();                // Interrupts global freigeben


   while(1) {

     while(buffer_size(get_bp)){
       *k_sp = buffer_read(get_bp);
       uart_putc(*k_sp);
       if(*k_sp == '\n' || *k_sp == '\r'){
         *k_sp = 0x00;
         k_sp=kommando;
         uart_putc('\n');
//         uart_puts(k_sp);   // Ausgabe für Testwecke
	 parser(k_sp);
       }
       else
         k_sp++;
	 // hier noch Bufferoverflow abfangen
     }
           
     if(status_LED2 == 's'){
       PORTD ^= 1<<PD6;       // toggle LED2
       my_delay_ms(delay);    // warte delay ms
       PORTD ^= 1<<PD6;       // toggle LED2
       status_LED2 = '0';     // Status_Flag auf Aus
     }
     if(status_LED2 == 't'){
       my_delay_ms(delay);    // warte delay ms
       PORTD ^= 1<<PD6;       // toggle LED2
     }
   } 
   /* wird nie erreicht */
   return 0;
}
Exemple #24
0
static int verify_header(su_state *s, reader_buffer_t *buffer) {
	char sign[4];
	unsigned char version[2];
	unsigned short flags;

	buffer_read(s, buffer, sign, sizeof(sign));
	if (memcmp(sign, "\x1bsuc", sizeof(sign)))
		return -1;

	buffer_read(s, buffer, version, sizeof(version));
	if (version[0] != VERSION_MAJOR && version[1] != VERSION_MINOR)
		return -1;

	buffer_read(s, buffer, &flags, sizeof(flags));
	if (flags != 0)
		return -1;

	return 0;
}
Exemple #25
0
static acl_options_t*
unmarshal_acl(region_type* r, struct buffer* b)
{
	acl_options_t* acl = (acl_options_t*)region_alloc(r, sizeof(*acl));
	buffer_read(b, acl, sizeof(*acl));
	acl->next = NULL;
	acl->key_options = NULL;
	acl->ip_address_spec = unmarshal_str(r, b);
	acl->key_name = unmarshal_str(r, b);
	return acl;
}
Exemple #26
0
void channel_handle_client_read(connector_t pconn, int event)
{
    //由于和客户端只有一次交互,不用一直读取
    if (connector_read(pconn, event) > 0)
    {
        char *val = buffer_get_read(pconn->preadbuf);
        message_t pmsg = (message_t)malloc(sizeof(message));
        memset(pmsg, 0, sizeof(pmsg));
        size_t len1 = get_client_msg(val, pmsg);

        if (len1 == 0)
        {
            print_log(LOG_TYPE_ERROR, "Read Client Msg Error %s", val);
            free(pmsg);
            return;
        }

        char data[20] = {0};
        memcpy(data, pmsg->uid, pmsg->len);
        buffer_read(pconn->preadbuf, len1, TRUE);

        memcpy(pconn->uid, data, pmsg->len);

        int len2 = sizeof(connector_t);
        ht_insert(pconn->pworker->pht, data, (pmsg->len)+1, pconn, len2+1);

        context_t pcontext = (context_t)malloc(sizeof(context));
        memset(pcontext, 0, sizeof(context));
        memcpy(pcontext->data, data, pmsg->len);
        list_push_tail(pconn->pworker->plist, pcontext);

        //print_log(LOG_TYPE_DEBUG, "Hash key %s, Len %d", pcontext->data, pmsg->len);

        char cmd[REDIS_CMD_LEN] = {'\0'};
        get_request_str(data, cmd);

        int len = strlen(cmd);

        if (pconn->pworker->redis->state == CONN_STATE_RUN)
        {
            buffer_write(pconn->pworker->redis->pwritebuf, cmd, len);
            connector_write(pconn->pworker->redis);
        }
        else
        {
            print_log(LOG_TYPE_ERROR, "Redis not run");
            list_pop_head(pconn->pworker->plist);
            ht_remove(pconn->pworker->pht, data, (pmsg->len)+1);
            pconn->pworker->neterr_count++;
        }

        free(pmsg);
    }
}
void
cmd_new_window_recv(struct cmd *self, struct buffer *b)
{
	struct cmd_new_window_data	*data;

	self->data = data = xmalloc(sizeof *data);
	buffer_read(b, data, sizeof *data);
	data->target = cmd_recv_string(b);
	data->name = cmd_recv_string(b);
	data->cmd = cmd_recv_string(b);
}
Exemple #28
0
/** Read data from i8042 port.
 *
 * @param fun    DDF function.
 * @param buffer Data place.
 * @param size   Data place size.
 *
 * @return Bytes read.
 *
 */
static int i8042_read(ddf_fun_t *fun, char *data, size_t size)
{
    i8042_t *controller = dev_i8042(ddf_fun_get_dev(fun));
    buffer_t *buffer = (fun == controller->aux_fun) ?
                       &controller->aux_buffer : &controller->kbd_buffer;

    for (size_t i = 0; i < size; ++i)
        *data++ = buffer_read(buffer);

    return size;
}
Exemple #29
0
int
client_msg_fn_error(struct hdr *hdr, struct client_ctx *cctx, char **error)
{
	if (hdr->size == SIZE_MAX)
		fatalx("bad MSG_ERROR size");

	*error = xmalloc(hdr->size + 1);
	buffer_read(cctx->srv_in, *error, hdr->size);
	(*error)[hdr->size] = '\0';

	return (-1);
}
Exemple #30
0
static ssize_t data_buffer_t_read(data_t *data, fastcall_read *fargs){ // {{{
	ssize_t                ret;
	
	if(fargs->buffer == NULL)
		return -EINVAL;

	if( (ret = buffer_read( (buffer_t *)data->ptr, fargs->offset, fargs->buffer, fargs->buffer_size)) == -1){
		fargs->buffer_size = 0;
		return -1; // EOF
	}
	fargs->buffer_size = ret;
	return 0;
} // }}}