Example #1
0
File: file.c Project: nielssp/ctodo
TODOLIST *parse_todolist(char *source, size_t length) {
  TODOLIST *list = NULL;
  STREAM *input = stream_buffer(source, length);
  list = read_todolist(input);
  stream_close(input);
  return list;
}
Example #2
0
static stream_t zip_read_stream(archive_t arch,zip_file_no_t  id){
    stream_t s=(stream_t)HREmalloc(NULL,sizeof(struct stream_s));
    stream_init(s);
    s->procs.close=zip_stream_read_close;
    s->procs.read_max=zip_stream_read_max;
    s->procs.read=stream_default_read;
    s->file=zip_fopen_index(arch->archive,id,0);
    return stream_buffer(s,arch->buf);
}
Example #3
0
static stream_t stream_zip(stream_t parent,int compress,int level,int bufsize){
    stream_t s=(stream_t)RTmallocZero(sizeof(struct stream_s));
    stream_init(s);
    s->bufsize=bufsize;
    s->s=parent;
    s->compress=compress;
    if(stream_writable(parent)){
        s->procs.write=gzip_write;
        //s->procs.flush= TO DO
        s->wr.zalloc = Z_NULL;
        s->wr.zfree = Z_NULL;
        s->wr.opaque = Z_NULL;
        s->wr_buf=(char*)RTmalloc(bufsize);
        s->wr.next_in=Z_NULL;
        s->wr.avail_in=0;
        s->wr.next_out=s->wr_buf;
        s->wr.avail_out=bufsize;
        if (compress) {
            if (deflateInit(&s->wr, level)!= Z_OK) {
                Abort("gzip init failed");
            }
        } else {
            if (inflateInit(&s->wr)!= Z_OK) {
                Abort("gzip init failed");
            }
        }
    } else {
        s->wr_buf=NULL;
    }
    if(stream_readable(parent)){
        s->procs.read_max=gzip_read_max;
        s->procs.read=gzip_read;
        //s->procs.empty= TO DO
        s->rd.zalloc = Z_NULL;
        s->rd.zfree = Z_NULL;
        s->rd.opaque = Z_NULL;
        s->rd.next_in=Z_NULL;
        s->rd.avail_in=0;
        s->rd.next_out=Z_NULL;
        s->rd.avail_out=0;
        s->rd_buf=(char*)RTmalloc(bufsize);
        if (compress) {
            if (inflateInit(&s->rd)!= Z_OK) {
                Abort("gzip init failed");
            }
        } else {
            if (deflateInit(&s->rd, level)!= Z_OK) {
                Abort("gzip init failed");
            }
        }
    } else {
        s->rd_buf=NULL;
    }
    s->procs.close=gzip_close;
    s->procs.close_z=gzip_close_z;
    return stream_buffer(s,4096);
}
Example #4
0
File: file.c Project: nielssp/ctodo
char *stringify_todolist(TODOLIST *todolist) {
  size_t size = 100;
  char *str = (char *)malloc(size);
  STREAM *output = stream_buffer(str, size);
  write_todolist(output, todolist);
  stream_printf(output, "\0");
  str = stream_get_content(output);
  stream_close(output);
  return str;
}
basic_socket_impl::basic_socket_impl(boost::asio::io_service& ios) :
	ios_(ios),
	s(ios),
	last_socket_error_(0),
	check_data_recv_(ios)
{
	close_when_idle_ = false;
	//作为服务器端接受的连接使用时,默认状态应该是已连接状态.
	work_state = work_state_closed;
	recv_helper_.reading_buffer_ = stream_buffer(boost::shared_array<char>(new char[32768]), 0, 32768);
	recv_helper_.is_recving_ = false;
	send_helper_.is_sending_ = false;
	create_in_thread_ = boost::this_thread::get_id();
}