コード例 #1
0
ファイル: scheduler.c プロジェクト: ConfusedReality/h2o
static int proceed(h2o_http2_scheduler_node_t *node, h2o_http2_scheduler_run_cb cb, void *cb_arg)
{
Redo:
    if (node->_queue == NULL)
        return 0;

    h2o_http2_scheduler_queue_node_t *drr_node = queue_pop(node->_queue);
    if (drr_node == NULL)
        return 0;

    h2o_http2_scheduler_openref_t *ref = H2O_STRUCT_FROM_MEMBER(h2o_http2_scheduler_openref_t, _queue_node, drr_node);

    if (!ref->_self_is_active) {
        /* run the children (manually-unrolled tail recursion) */
        queue_set(node->_queue, &ref->_queue_node, ref->weight);
        node = &ref->node;
        goto Redo;
    }
    assert(ref->_active_cnt != 0);

    /* call the callbacks */
    int still_is_active, bail_out = cb(ref, &still_is_active, cb_arg);
    if (still_is_active) {
        queue_set(node->_queue, &ref->_queue_node, ref->weight);
    } else {
        ref->_self_is_active = 0;
        if (--ref->_active_cnt != 0) {
            queue_set(node->_queue, &ref->_queue_node, ref->weight);
        } else if (ref->node._parent != NULL) {
            decr_active_cnt(ref->node._parent);
        }
    }

    return bail_out;
}
コード例 #2
0
ファイル: task.c プロジェクト: bvancea/spospl
void sched_handler_try_steal(scheduler_t* scheduler, int steal_attempts) {
	if (schedulers_nr > 1) {
		unsigned int seed = 42;
		srand(time(NULL));
		long victim_id = 0;
		int attempt = 0;
		task_t* stolen = NULL;

		while (stolen == NULL && attempt < steal_attempts) {
			do {
				victim_id = rand_r(&seed) % schedulers_nr;
			} while (victim_id == scheduler->id);

			scheduler_t* victim = &schedulers[victim_id];
			stolen = queue_pop(&victim->ready);
			if (stolen) {
				debug("%d - yay", scheduler->id);
			}
			attempt+=1;
		}
		if (stolen) {
			debug("%d - Succesfully stolen task %d from victim %d", scheduler->id, stolen->id, (int) victim_id);
			scheduler->action = YIELD;
			scheduler->current_task = stolen;
		} else {
			//debug("%d - Failed to steal from victim %d", scheduler->id, (int) victim_id);
		}		
	}
}
コード例 #3
0
ファイル: 225.c プロジェクト: tiancaiamao/leetcode
/* Push element x onto stack */
void stackPush(Stack *stack, int element) {
    while(!queue_empty(&stack->q[stack->cur])) {
        int x = queue_pop(&stack->q[stack->cur]);
        queue_push(&stack->q[(stack->cur+1)%2], x);
    }
    queue_push(&stack->q[stack->cur], element);
}
コード例 #4
0
ファイル: main.c プロジェクト: mattmckillip/Cpre308
/**
 * @brief     This thread represents a print spooler which directly talks to a single printer
 * @param     param
 *                 The PRINT_SPOOL_PARAM this printer should pull its jobs from, casted to a void*
 * @return    NULL
 *
 * This function should loop forever.  The basic process is as follows:
 * 1) pop a print job from this threads queue
 * 2) if it is NULL return
 * 3) print to the log file that printing of the job is starting
 * 4) call the print method on the printer object of the param and check the return
 * 5) handel errors correctly
 * 6) destroy the print job and get the next
 */
void *spooler(void* param)
{
	struct PRINTER_SPOOLER_PARAM* params =  malloc(sizeof(struct PRINTER_SPOOLER_PARAM));
	params = (struct PRINTER_SPOOLER_PARAM*)param;
	queue_t queue = params->print_queue_list;
	printer_t printer = params->printer_driver;
	struct arguments arguments = params->arguments;

	queue_ends_t q_ends = QUEUE_HEAD;
	print_job_t* popped;
	FILE *file;
	char *str;
	while(1){
		popped = queue_pop(queue,  q_ends);
		if (popped == NULL){	
			printer_uninstall(printer);
			return NULL;
		}
	
		file = fopen(arguments.log_file_name, "a");

		if(file == NULL){
			fprintf(stderr, "%s: error opening log file\n", __func__);	
			exit(-1);
		}
		asprintf(&str, "Starting to print job %s\n", popped->job_name);
		fputs(str,file);
		fclose(file);
		printer_print(printer, popped);
	}
}
コード例 #5
0
ファイル: Wendys.c プロジェクト: 1168392/exercises
bool esta_bien_armada() {
	/*Esta correctamente armada si tiene todos los ingredientes,
		 *  y los tiene definidos en el orden dado por el enum t_Ingredientes*/

	for (int i = 0; (((t_Ingredientes) i) <= PANSUPERIOR); i++) {
		t_Ingredientes ingrediente_correcto = (t_Ingredientes) i;
		t_Ingredientes ingrediente_hamburguesa;

		pthread_mutex_lock(&mutex);
		int* ingrediente = queue_pop(hamburguesa.ingredientes);
		pthread_mutex_unlock(&mutex);

		if (ingrediente == NULL) {
			printf("Faltaron ingredientes!\n");
			return false;
		}

		ingrediente_hamburguesa = (t_Ingredientes) *ingrediente;
		if (ingrediente_hamburguesa != ingrediente_correcto) {
			printf("Ingrediente incorrecto debia ser %s y era %s\n",
					ingrediente_to_string(ingrediente_correcto),
					ingrediente_to_string(ingrediente_hamburguesa));

			free(ingrediente);
			return false;
		}
	}

	return true;
}
コード例 #6
0
ファイル: multilookup.c プロジェクト: entzel/Dnslookup
void* ResThreads(void* empty)
{
	char* outhostname; //hostname you pop off the queue
	char firstipstring[INET6_ADDRSTRLEN];
	
	//while the search is incomplete or the queue is not empty
	while (!queue_is_empty(requesterQ) || !SearchComplete)
	{
		//if queue is empty wait
		while (queue_is_empty(requesterQ)){
			if(SearchComplete)
			{
				free(outhostname);
				return 0;
			}
		}
		//if there is an item in the queue, pop 
		pthread_mutex_lock(&Q_lock);//lock to have exclusion
		outhostname = queue_pop(requesterQ); //hostname 
		pthread_mutex_unlock(&Q_lock);
		
		//Lookup hostname and get IP string
		if(dnslookup(outhostname, firstipstring, sizeof(firstipstring)) == UTIL_FAILURE)
		{
			fprintf(stderr, "dnslookup error: %s\n", outhostname);
			strncpy(firstipstring, "", sizeof(firstipstring));
		}
		//Write to output file
		pthread_mutex_lock( &Out_lock ); //Lock the outputfile so you only put one thing at a time in it
		fprintf(outputfp, "%s,%s\n", outhostname, firstipstring);
		free(outhostname);
		pthread_mutex_unlock( &Out_lock );
	}
	return 0;
}
コード例 #7
0
ファイル: my_queue.c プロジェクト: aa838260772/linux-study
void queue_destroy(queue *Q)
{
    while(!queue_empty(Q))
    {
        queue_pop(Q);
    }
}
コード例 #8
0
void threadDispositivo(stDispositivo* unDispositivo) {
	int error = 0;
	t_queue *colaRafaga;
	stRafaga *unaRafaga;
	stPCB *unPCB;

	colaRafaga = unDispositivo->rafagas;

	while (!error) {
		while (unDispositivo->numInq == 0)
			pthread_mutex_lock(&unDispositivo->empty);
		pthread_mutex_lock(&unDispositivo->mutex);		// Se lockea el acceso a la cola
		unaRafaga = queue_pop(colaRafaga);
		unDispositivo->numInq--;
		pthread_mutex_unlock(&unDispositivo->mutex);	// Se desbloquea el acceso a la cola

		log_info("Pedido I/O - Retardo de dispositivo [%s] con [%d].",unDispositivo->nombre,atoi(unDispositivo->retardo));
		usleep(atoi(unDispositivo->retardo)*unaRafaga->unidades*1000);

		/*Busqueda del pcb en la lista de pcb bloqueados*/
		int _es_el_pcb(stPCB *p) {
			return p->pid == unaRafaga->pid;
		}
		pthread_mutex_lock(&mutex_listaBlock);
		unPCB = list_remove_by_condition(listaBlock, (void*) _es_el_pcb);
		pthread_mutex_unlock(&mutex_listaBlock);

		/*Ponemos en la cola de Ready para que lo vuelva a ejecutar un CPU*/
		ready_productor(unPCB);
		log_info("El PCB [PID - %d] cambia de estado BLOCK a READY\n", unPCB->pid);
		free(unaRafaga);

	}
}
コード例 #9
0
static void
command(struct skynet_context *ctx, struct package *P, int session, uint32_t source, const char *msg, size_t sz) {
	switch (msg[0]) {
	case 'R':
		// request a package
		if (P->closed) {
			skynet_send(ctx, 0, source, PTYPE_ERROR, session, NULL, 0);
			break;
		}
		if (!queue_empty(&P->response)) {
			assert(queue_empty(&P->request));
			struct response resp;
			queue_pop(&P->response, &resp);
			skynet_send(ctx, 0, source, PTYPE_RESPONSE | PTYPE_TAG_DONTCOPY, session, resp.msg, resp.sz);
		} else {
			struct request req;
			req.source = source;
			req.session = session;
			queue_push(&P->request, &req);
		}
		break;
	case 'K':
		// shutdown the connection
		skynet_socket_shutdown(ctx, P->fd);
		break;
	case 'I':
		report_info(ctx, P, session, source);
		break;
	default:
		// invalid command
		skynet_error(ctx, "Invalid command %.*s", (int)sz, msg);
		skynet_send(ctx, 0, source, PTYPE_ERROR, session, NULL, 0);
		break;
	};
}
コード例 #10
0
ファイル: exec.c プロジェクト: FangKuangKuang/egui
si_t application_exec()
{
    /**
     * parse the application before execute
     **/
    application_parse();

	event_listener_add_read_event(&global_application.app_event_listener, &global_application.uds, NULL, application_event_handler, NULL);

	while(!queue_empty(&global_application.message_queue))
	{
		union message* msg = queue_front(&global_application.message_queue);
		application_handle_message(msg);
		queue_pop(&global_application.message_queue);
	}

	global_application.exec_flag = 1;
	if(0 != event_listener_exec(&global_application.app_event_listener))
	{
		EGUI_PRINT_ERROR("failed to run event_listener.");
		return -1;
	}
	global_application.exec_flag = 0;

    return 0;
}
コード例 #11
0
ファイル: exec.c プロジェクト: FangKuangKuang/egui
si_t application_event_handler(struct egui_uds* uds_ptr, addr_t arg)
{
	union message msg;
    NOT_USED(arg);

	if(0 != comm_recv_msg(uds_ptr, &msg))
	{
		EGUI_PRINT_ERROR("failed to recv msg");
		return SELECTER_RETURN_TYPE_CONTINUE;
	}

	application_handle_message(&msg);

	/**
	 * 处理器消息过程中,应用程序需要发送一些请求,等待回应的过程中,窗口管理器可能会发送消息。
	 * 因此当请求处理完毕之后,再逐一处理消息。
	 **/
	while(!queue_empty(&global_application.message_queue))
	{
		union message* msg = queue_front(&global_application.message_queue);
		application_handle_message(msg);
		queue_pop(&global_application.message_queue);
	}

	return SELECTER_RETURN_TYPE_CONTINUE;
}
コード例 #12
0
ファイル: ipc_msg.c プロジェクト: cbart/sop-lab-2009
void queue_clear(orders_queue *q)
{
    order_t tmp_order;
    assert(q != NULL);
    while(!queue_empty(q))
        queue_pop(q, &tmp_order);
}
コード例 #13
0
ファイル: pathfinding.c プロジェクト: progschj/TLDR
void dijkstra_distance_target(grid *distances, grid *target, const pos *targets, int count, int neighbors, cost_function_t cost_function, void *userdata){
    grid_fill(distances, distances->x0, distances->y0, distances->width, distances->height, DBL_MAX);
    if(target != NULL) grid_fill(target, target->x0, target->y0, target->width, target->height, -1);

    queue open_set = queue_create(sizeof(pos));

    for(int i = 0;i<count;++i) {
        grid_set(distances, targets[i].x, targets[i].y, 0.0);
        if(target != NULL) grid_set(target, targets[i].x, targets[i].y, i);
        queue_push(&open_set, targets+i);
    }

    while(!queue_empty(&open_set)) {
        pos cur = *(pos*)queue_front(&open_set);
        double curdist = grid_get(distances, cur.x, cur.y);
        queue_pop(&open_set);
        for(int i = 0;i<neighbors;++i) {
            pos neigh = {cur.x+offsets[i].x, cur.y+offsets[i].y};

            if(!grid_contains(distances, neigh.x, neigh.y)) continue;

            double neighdist = grid_get(distances, neigh.x, neigh.y);

            double cost = cost_function(cur.x, cur.y, neigh.x, neigh.y, userdata);
            if(neighdist > curdist + cost) {
                grid_set(distances, neigh.x, neigh.y, curdist + cost);
                if(target != NULL) grid_set(target, neigh.x, neigh.y, grid_get(target, cur.x, cur.y));
                queue_push(&open_set, &neigh);
            }
        }
    }

    queue_destroy(open_set);
}
コード例 #14
0
ファイル: unabto_app_adapter.c プロジェクト: nabto/unabto
/* Release the event handle returned by framework_event_query.
 * In the ASYNC model we must remove the event handle from the FIFO request
 * queue. */
void framework_release_handle(naf_handle handle)
{
    queue_entry* entry;

    if (!handle) {
        return;
    }
    if (queue_empty()) {
        /* Why do the application try to release a handle on an empty queue? */
        NABTO_LOG_FATAL(("SW error: Calling framework_release_handle on an empty queue"));
        return;
    }

    /* Find the entry containing the handle */
    entry = queue_find_entry(handle);
    /* The given handle must belong to the queue */
    UNABTO_ASSERT(entry);

    entry->state = APPREQ_FREE;
    LOG_APPREQ_WHERE("framework_release_handle", entry);

    /* Remove top entry from FIFO queue - and remove all consecutive
     * entries that have expired/finished in the mean time. */
    while (!queue_empty()) {
        if (queue_top()->state != APPREQ_FREE)
            break;
        queue_pop();
    }

    LOG_APPREQ_QUEUE();
}
コード例 #15
0
static void
update_frame_v1(struct accuraterip_v1 *v1,
                unsigned total_pcm_frames,
                unsigned start_offset,
                unsigned end_offset,
                unsigned value)
{
    /*calculate initial checksum*/
    if ((v1->index >= start_offset) && (v1->index <= end_offset)) {
        v1->checksums[0] += (value * v1->index);
        v1->values_sum += value;
    }

    /*store the first (pcm_frame_range - 1) values in initial_values*/
    if ((v1->index >= start_offset) && (!queue_full(v1->initial_values))) {
        queue_push(v1->initial_values, value);
    }

    /*store the trailing (pcm_frame_range - 1) values in final_values*/
    if ((v1->index > end_offset) && (!queue_full(v1->final_values))) {
        queue_push(v1->final_values, value);
    }

    /*calculate incremental checksums*/
    if (v1->index > total_pcm_frames) {
        const uint32_t initial_value = queue_pop(v1->initial_values);

        const uint32_t final_value = queue_pop(v1->final_values);

        const uint32_t initial_value_product =
            (uint32_t)(start_offset - 1) * initial_value;

        const uint32_t final_value_product =
            (uint32_t)end_offset * final_value;

        v1->checksums[v1->index - total_pcm_frames] =
            v1->checksums[v1->index - total_pcm_frames - 1] +
            final_value_product -
            v1->values_sum -
            initial_value_product;

        v1->values_sum -= initial_value;
        v1->values_sum += final_value;
    }

    v1->index++;
}
コード例 #16
0
ファイル: queue.c プロジェクト: nathanielherman/sto-stamp
int
main ()
{
    queue_t* queuePtr;
    random_t* randomPtr;
    long data[] = {3, 1, 4, 1, 5};
    long numData = sizeof(data) / sizeof(data[0]);
    long i;

    randomPtr = random_alloc();
    assert(randomPtr);
    random_seed(randomPtr, 0);

    puts("Starting tests...");

    queuePtr = queue_alloc(-1);

    assert(queue_isEmpty(queuePtr));
    for (i = 0; i < numData; i++) {
        insertData(queuePtr, &data[i]);
    }
    assert(!queue_isEmpty(queuePtr));

    for (i = 0; i < numData; i++) {
        long* dataPtr = (long*)queue_pop(queuePtr);
        printf("Removing %li: ", *dataPtr);
        printQueue(queuePtr);
    }
    assert(!queue_pop(queuePtr));
    assert(queue_isEmpty(queuePtr));

    puts("All tests passed.");

    for (i = 0; i < numData; i++) {
        insertData(queuePtr, &data[i]);
    }
    for (i = 0; i < numData; i++) {
        printf("Shuffle %li: ", i);
        queue_shuffle(queuePtr, randomPtr);
        printQueue(queuePtr);
    }
    assert(!queue_isEmpty(queuePtr));

    queue_free(queuePtr);

    return 0;
}
コード例 #17
0
/**
 * TGDB will search it's command queue's and determine what the next command
 * to deliever to GDB should be.
 *
 * \return
 * 0 on success, -1 on error
 */
int Ctgdb::Unqueue_and_deliver_command()
{
tgdb_unqueue_and_deliver_command_tag:

	/* This will redisplay the prompt when a command is run
	 * through the gui with data on the console.
	 */
	/* The out of band commands should always be run first */
	if (queue_size (oob_input_queue) > 0)
	{
		/* These commands are always run. 
		 * However, if an assumption is made that a misc
		 * prompt can never be set while in this spot.
		 */
		tgdb_command *item = NULL;
		item = (tgdb_command *) queue_pop(oob_input_queue);
		Deliver_command (item);
		tgdb_command_destroy (item);
	}
	/* If the queue is not empty, run a command */
	else if (queue_size (gdb_input_queue) > 0)
	{
		struct tgdb_command *item = NULL;
		item = (tgdb_command *) queue_pop (gdb_input_queue);

		/* If at the misc prompt, don't run the internal tgdb commands,
		 * In fact throw them out for now, since they are only 
		 * 'info breakpoints' */
		if (tgdb_client_can_tgdb_run_commands (tcc) == 1)
		{
			if (item->command_choice != TGDB_COMMAND_CONSOLE)
			{
				tgdb_command_destroy (item);
				goto tgdb_unqueue_and_deliver_command_tag;
			}
		}

		/* This happens when a command was skipped because the client no longer
		 * needs the command to be run */
		if (Deliver_command(item) == -1)
			goto tgdb_unqueue_and_deliver_command_tag;

		tgdb_command_destroy (item);
	}

	return 0;
}
コード例 #18
0
ファイル: queue.c プロジェクト: designtestcode/thin-turbo
void queue_reset(queue_t *q)
{
  /* drain the queue */
  while (q->first != NULL)
    queue_pop(q);
  
  queue_init(q);
}
コード例 #19
0
ファイル: queue_test.c プロジェクト: bcrafton/Data-Structures
int main(){

	char* a1 = "Brian";
	char* b1 = "Julia";
	char* c1 = "Rex";

	Queue* queue = queue_constructor();
	queue_push(a1, queue);
	queue_push(b1, queue);
	queue_push(c1, queue);
	
	assert(strcmp((char*)queue_pop(queue), a1) == 0);
	assert(strcmp((char*)queue_pop(queue), b1) == 0);
	assert(strcmp((char*)queue_pop(queue), c1) == 0);
	
	printf("test complete\n");
}
コード例 #20
0
nodoStack_t* sacarLlamada(imagen_proceso_t proceso)
{
	void* punteroALlamada = queue_pop(proceso.segmentoDeStack);
	nodoStack_t* unaLlamada;
	unaLlamada = malloc(sizeof(nodoStack_t));
	unaLlamada = (nodoStack_t*) punteroALlamada;
	return unaLlamada;
}
コード例 #21
0
void connection_start(backend_t *backend, int fd, struct sockaddr_in remote_addr)
{
  connection_t *c = (connection_t *) queue_pop(&backend->connections);
  
  /* no free connection found, add more */
  if (c == NULL) {
    connections_push(backend);
    c = (connection_t *) queue_pop(&backend->connections);
  }
  
  assert(c != NULL);
  
  /* init connection */
  c->finished       = 0;
  c->loop           = backend->loop;
  c->backend        = backend;
  c->content_length = 0;
  c->fd             = fd;
  c->remote_addr    = inet_ntoa(remote_addr.sin_addr);
  c->thread.obj     = Qnil;
  c->thread.active  = 0;
  
  /* mark as used to Ruby GC */
  c->env = rb_hash_new();
  rb_gc_register_address(&c->env);
  
  /* reset buffers */
  buffer_reset(&c->read_buffer);
  buffer_reset(&c->write_buffer);
  
  /* reinit parser */
  http_parser_init(&c->parser);
  c->parser.data = c;
  
  /* init libev stuff */
  c->read_watcher.data    = c;
  c->write_watcher.data   = c;
  c->timeout_watcher.data = c;
  ev_io_init(&c->read_watcher, connection_readable_cb, c->fd, EV_READ | EV_ERROR);
  ev_io_init(&c->write_watcher, connection_writable_cb, c->fd, EV_WRITE | EV_ERROR);
  ev_timer_init(&c->timeout_watcher, connection_timeout_cb, backend->timeout, backend->timeout);
  
  /* start event watchers */
  ev_timer_start(c->loop, &c->timeout_watcher);
  ev_io_start(c->loop, &c->read_watcher);
}
コード例 #22
0
void delete_all_memory(void) {
  while( top != NULL )
    stack_pop();
  while( front != NULL )
    queue_pop();
  while( c_front != NULL )
    c_queue_pop();
}
コード例 #23
0
ファイル: entradaSalida.c プロジェクト: ferjjp/personalCopyTP
t_nodo_proceso_bloqueadoIO* waitForProcess(t_dataDispositivo* datos)
{
	sem_wait(&datos->sem_io);
	pthread_mutex_lock(&datos->mutex_io);
	t_nodo_proceso_bloqueadoIO* proceso = queue_pop(datos->bloqueados);
	pthread_mutex_unlock(&datos->mutex_io);
	return proceso;
}
コード例 #24
0
/**
 * Get a tgdb_request command back from TGDB.
 *
 * \param tgdb
 * An instance of the tgdb library to operate on.
 *
 * \return
 * The requested command at the top of the stack, or NULL on error.
 * Popping a command when the queue is empty is also considered an error,
 * and NULL will be returned.
 */
tgdb_request_ptr Ctgdb::Queue_pop()
{
	tgdb_request_ptr item;

	item = (tgdb_request_ptr) queue_pop(gdb_client_request_queue);

	return item;
}
コード例 #25
0
ファイル: queue.cpp プロジェクト: daijinwei/algorithm
void queue_print(Queue *queue){
	Position tmp = NULL;
	while(!queue_is_empty(queue)){
		tmp = queue_get_tail(queue);	
		fprintf(stdout, "Item\t%d\n", tmp->item);
		queue_pop(queue);
	}
}
コード例 #26
0
ファイル: queue.c プロジェクト: spencermcw/Code
void queue_cleanup(queue* q)
{
    while(!queue_is_empty(q)){
	queue_pop(q);
    }

    free(q->array);
}
コード例 #27
0
ファイル: p5_1.c プロジェクト: huqi/YinHomework
static void deinit(struct system_t *system)
{
    /* free remaind customer */
    while (system->queue.count != 0)
        queue_pop(&system->queue);

    memset(system, 0, sizeof(struct system_t));
}
コード例 #28
0
ファイル: bouncer.c プロジェクト: PtxDK/OSM
void
shutdown() {
  // Pop everything off of the queue.
  int dummy = 0;
  while (Queue.item_cnt != 0) {
    queue_pop(&Queue, &dummy);
  }
}
コード例 #29
0
ファイル: read.c プロジェクト: blue119/pixz
static void read_thread(void) {
    off_t offset = ftello(gInFile);
    wanted_t *w = gWantedFiles;
    
    lzma_index_iter iter;
    lzma_index_iter_init(&iter, gIndex);
    while (!lzma_index_iter_next(&iter, LZMA_INDEX_ITER_BLOCK)) {
        // Don't decode the file-index
        off_t boffset = iter.block.compressed_file_offset;
        size_t bsize = iter.block.total_size;
        if (gFileIndexOffset && boffset == gFileIndexOffset)
            continue;
        
        // Do we need this block?
        if (gWantedFiles && gExplicitFiles) {
            off_t uend = iter.block.uncompressed_file_offset +
                iter.block.uncompressed_size;
            if (!w || w->start >= uend) {
                debug("read: skip %llu", iter.block.number_in_file);
                continue;
            }
            for ( ; w && w->end < uend; w = w->next) ;
        }
        debug("read: want %llu", iter.block.number_in_file);
        
        // Seek if needed, and get the data
        if (offset != boffset) {
            fseeko(gInFile, boffset, SEEK_SET);
            offset = boffset;
        }
		
		if (iter.block.uncompressed_size > MAXSPLITSIZE) { // must stream
			if (gRbuf)
				rbuf_consume(gRbuf->insize); // clear
			read_block(true, iter.stream.flags->check,
                iter.block.uncompressed_file_offset);
		} else {
            // Get a block to work with
            pipeline_item_t *pi;
            queue_pop(gPipelineStartQ, (void**)&pi);
            io_block_t *ib = (io_block_t*)(pi->data);
            block_capacity(ib, iter.block.unpadded_size,
                iter.block.uncompressed_size);
            
	        ib->insize = fread(ib->input, 1, bsize, gInFile);
	        if (ib->insize < bsize)
	            die("Error reading block contents");
	        offset += bsize;
	        ib->uoffset = iter.block.uncompressed_file_offset;
			ib->check = iter.stream.flags->check;
			ib->btype = BLOCK_SIZED; // Indexed blocks always sized
			
	        pipeline_split(pi);
		}
    }
    
    pipeline_stop();
}
コード例 #30
0
ファイル: brute.c プロジェクト: toptut/brute
void *thread_sender(void *arg)
{
  client_info_t *client_info = (client_info_t*) arg;
  pthread_cond_broadcast(&client_info->peer_signal);
  printf("enter sender\n");
  for(;;)
    {
      char str_in[SEND_STR_SIZE], str_out[SEND_STR_SIZE];
      task_t task;
      if (queue_pop(&client_info->context->queue, &task) != 0)
	{
	  pthread_exit(0);
	}
      //printf("take job\n");
      sprintf(str_out, SEND_JOB_TMPL, task.pass, 0,  0, client_info->context->hash, client_info->context->alph, task.to, client_info->context->length);
      printf("write job into str %s\n", str_out);
      uint32_t length = strlen (str_out);
      
      if (write(client_info->i32_connect_FD, &length, sizeof(uint32_t)) == -1)
	{
	  queue_push(&task, &client_info->context->queue);
	  pthread_exit(0);
	}
      //printf("send length\n");
      if (write(client_info->i32_connect_FD, str_out, length) == -1)
	{
	  queue_push(&task, &client_info->context->queue);
	  pthread_exit(0);
	}
      printf("send job %s\n", str_out);
      if (read (client_info->i32_connect_FD, &length, sizeof(uint32_t)) == -1)
	{
	  queue_push(&task, &client_info->context->queue);
	  pthread_exit(0);
	}
      //printf("get result length %d\n", length);
      if (read (client_info->i32_connect_FD, &str_in, length) == -1)
	{
	  queue_push(&task, &client_info->context->queue);
	  pthread_exit(0);
	}
      printf("get result str %s\n", str_in);
      int id, check_result;
      sscanf(str_in, REPORT_RESULT_TMPL, str_out, &id, &id, &check_result);
      //printf("result = %s\n", str_out);
      if (check_result != 0)
	{
	  printf("beda s checkom\n");
	  client_info->context->complete = !0;
	  queue_cancel(&client_info->context->queue);
	  memcpy(client_info->context->password, str_out, client_info->context->length);
	  unrev(client_info->context);
	  pthread_exit(0);
	}
      unrev(client_info->context);
      //printf("rev %d\n", client_info->context->rev_count);
    }
}