Example #1
0
struct hfp_gw *hfp_gw_new(int fd)
{
	struct hfp_gw *hfp;

	if (fd < 0)
		return NULL;

	hfp = new0(struct hfp_gw, 1);
	if (!hfp)
		return NULL;

	hfp->fd = fd;
	hfp->close_on_unref = false;

	hfp->read_buf = ringbuf_new(4096);
	if (!hfp->read_buf) {
		free(hfp);
		return NULL;
	}

	hfp->write_buf = ringbuf_new(4096);
	if (!hfp->write_buf) {
		ringbuf_free(hfp->read_buf);
		free(hfp);
		return NULL;
	}

	hfp->io = io_new(fd);
	if (!hfp->io) {
		ringbuf_free(hfp->write_buf);
		ringbuf_free(hfp->read_buf);
		free(hfp);
		return NULL;
	}

	hfp->cmd_handlers = queue_new();
	if (!hfp->cmd_handlers) {
		io_destroy(hfp->io);
		ringbuf_free(hfp->write_buf);
		ringbuf_free(hfp->read_buf);
		free(hfp);
		return NULL;
	}

	if (!io_set_read_handler(hfp->io, can_read_data, hfp,
							read_watch_destroy)) {
		queue_destroy(hfp->cmd_handlers, destroy_cmd_handler);
		io_destroy(hfp->io);
		ringbuf_free(hfp->write_buf);
		ringbuf_free(hfp->read_buf);
		free(hfp);
		return NULL;
	}

	hfp->writer_active = false;
	hfp->result_pending = false;

	return hfp_gw_ref(hfp);
}
Example #2
0
static gboolean oss_init(gboolean silent)
{
     oss_output_buffer = ringbuf_new(
	  inifile_get_guint32(INI_SETTING_SOUNDBUFSIZE,
			      INI_SETTING_SOUNDBUFSIZE_DEFAULT));
     oss_noselect = inifile_get_gboolean(OSS_NOSELECT,OSS_NOSELECT_DEFAULT);
     play_source = mainloop_time_source_add(NULL, oss_output_flush, NULL);
     /* When autodetecting, this is the last tested driver before the dummy,
      * so we might as well return TRUE */
     return TRUE;
}
Example #3
0
struct channel*
channel_new(struct fdh* fdh,
            size_t rbsz,
            enum channel_direction direction)
{
    struct channel* ch = xcalloc(sizeof (*ch));
    ch->fdh = fdh;
    ch->dir = direction;
    ch->rb = ringbuf_new(rbsz);
    return ch;
}
Example #4
0
File: test7.c Project: hotfics/misc
int main() {
    ringbuf *r;
    size_t sz;
    int rc;
    char *d;

    r = ringbuf_new(11);
    printf("putting 7 bytes into buffer of sz 11\n");
    rc = ringbuf_put(r, z, 7);
    printf("put: %s\n", (rc == -1) ? "failed" : "ok");
    printf("consuming 7\n");
    ringbuf_mark_consumed(r, 7);
    printf("next put of > 4 bytes wraps buffer, writing 5\n");
    rc = ringbuf_put(r, z, 5);
    printf("put: %s\n", (rc == -1) ? "failed" : "ok");

    sz = ringbuf_get_next_chunk(r, &d);
    printf("chunk sz %lu: sz, %.*s\n", sz, (int)sz, d);
    printf("reading 3, of 5 available\n");
    ringbuf_mark_consumed(r, 3);

    printf("next read is last byte before wrapping\n");
    sz = ringbuf_get_next_chunk(r, &d);
    printf("chunk sz %lu: sz, %.*s\n", sz, (int)sz, d);
    ringbuf_mark_consumed(r, 1);

    printf("next read starts reading from wrapped part\n");
    sz = ringbuf_get_next_chunk(r, &d);
    printf("chunk sz %lu: sz, %.*s\n", sz, (int)sz, d);
    ringbuf_mark_consumed(r, 1);

    printf("nothing left\n");
    sz = ringbuf_get_pending_size(r);
    printf("size = %lu\n", sz);
    ringbuf_free(r);
    return 0;
}
Example #5
0
File: test1.c Project: hotfics/misc
int main() {
    ringbuf *r;
    r = ringbuf_new(100);
    ringbuf_free(r);
    return 0;
}
Example #6
0
static int acd_open(const char *path, struct fuse_file_info *fi)
{
        char ID[50];
        char *zErrMsg = 0;
        int rc;
        char SQLstr[1024];
        
        if(acd_path_to_id(path, ID)){
                fprintf(stderr,"No Such Path: %s",path);
                return -ENOENT;
        }

        /* Get url to file */
        FILE *fp;
        char cmd[1024];
        sprintf(cmd, "acd_cli m %s", ID);
        fprintf(stderr,"POPEN: %s\n", cmd);
        fp = popen(cmd, "r");
        if (fp == NULL) {
                fprintf(stderr,"Failed to run command\n" );
        }

        while (fgets(cmd, sizeof(cmd)-1, fp) != NULL) {
                //fprintf(stderr,"%s\n", cmd);
                
                if(strstr(cmd,"RequestError")){
                        return -EHOSTDOWN; 
                }
                
                if(strstr(cmd,"tempLink")){
                        break;
                }
                
        }
        pclose(fp);
        
        char * url = cmd;
        char * p;
        while( *url != ':') url++;
        url+=3;
        p=url;
        while( *p != '"') p++;
        *p=0;
        
        fprintf(stderr,"URL: %s\n", url);

        file_ctx * ctx = calloc(1, sizeof(file_ctx));
        fi->fh = (void*) ctx;
        
        ctx->url = strdup(url);
        //TODO: Adaptive buffer sizing
        ctx->rb = ringbuf_new(1024*1024*10); //10MB read buffer
        //Get Size
        struct stat st;
        st.st_size=0;

        sprintf(SQLstr, FileInfoSQL, ID);
        rc = sqlite3_exec(db, SQLstr, SQLcallback_getattr, (void*)&st, &zErrMsg);
        if( rc!=SQLITE_OK ){
                fprintf(stderr, "SQL error: %s\n", zErrMsg);
                sqlite3_free(zErrMsg);
        }
        
        ctx->filesize = st.st_size;
        ctx->offset = 0;
        fprintf(stderr,"OPEN: FileSize: %u" , ctx->filesize);
        pthread_mutex_init(&ctx->readmutex, NULL);
        pthread_mutex_init(&ctx->writemutex, NULL);
        
        ctx->curl = curl_easy_init();   
        if(!ctx->curl){
                fprintf(stderr,"Curl init failed",path);
                return -ENOENT;
        }
        //curl_easy_setopt(ctx->curl, CURLOPT_VERBOSE, 1L);
        curl_easy_setopt(ctx->curl, CURLOPT_URL, ctx->url);
        curl_easy_setopt(ctx->curl, CURLOPT_WRITEFUNCTION, curl_callback);
        curl_easy_setopt(ctx->curl, CURLOPT_WRITEDATA, ctx);

        pthread_create( &ctx->curlthread, NULL, curl_thread, (void*)ctx);
        
        return 0;
}
Example #7
0
struct hfp_hf *hfp_hf_new(int fd)
{
	struct hfp_hf *hfp;

	if (fd < 0)
		return NULL;

	hfp = new0(struct hfp_hf, 1);
	if (!hfp)
		return NULL;

	hfp->fd = fd;
	hfp->close_on_unref = false;

	hfp->read_buf = ringbuf_new(4096);
	if (!hfp->read_buf) {
		free(hfp);
		return NULL;
	}

	hfp->write_buf = ringbuf_new(4096);
	if (!hfp->write_buf) {
		ringbuf_free(hfp->read_buf);
		free(hfp);
		return NULL;
	}

	hfp->io = io_new(fd);
	if (!hfp->io) {
		ringbuf_free(hfp->write_buf);
		ringbuf_free(hfp->read_buf);
		free(hfp);
		return NULL;
	}

	hfp->event_handlers = queue_new();
	if (!hfp->event_handlers) {
		io_destroy(hfp->io);
		ringbuf_free(hfp->write_buf);
		ringbuf_free(hfp->read_buf);
		free(hfp);
		return NULL;
	}

	hfp->cmd_queue = queue_new();
	if (!hfp->cmd_queue) {
		io_destroy(hfp->io);
		ringbuf_free(hfp->write_buf);
		ringbuf_free(hfp->read_buf);
		queue_destroy(hfp->event_handlers, NULL);
		free(hfp);
		return NULL;
	}

	hfp->writer_active = false;

	if (!io_set_read_handler(hfp->io, hf_can_read_data, hfp,
							read_watch_destroy)) {
		queue_destroy(hfp->event_handlers,
						destroy_event_handler);
		io_destroy(hfp->io);
		ringbuf_free(hfp->write_buf);
		ringbuf_free(hfp->read_buf);
		free(hfp);
		return NULL;
	}

	return hfp_hf_ref(hfp);
}