예제 #1
0
파일: kbd.c 프로젝트: Efreak/elinks
/** A select_handler_T read_func for itrm_in.std.  This is called when
 * characters typed by the user arrive from the terminal. */
static void
in_kbd(struct itrm *itrm)
{
	int r;

	if (!can_read(itrm->in.std)) return;

	kill_timer(&itrm->timer);

	if (itrm->in.queue.len >= ITRM_IN_QUEUE_SIZE) {
		unhandle_itrm_stdin(itrm);
		while (process_queue(itrm));
		return;
	}

	r = safe_read(itrm->in.std, itrm->in.queue.data + itrm->in.queue.len,
		      ITRM_IN_QUEUE_SIZE - itrm->in.queue.len);
	if (r <= 0) {
		free_itrm(itrm);
		return;
	}

	itrm->in.queue.len += r;
	if (itrm->in.queue.len > ITRM_IN_QUEUE_SIZE) {
		ERROR(gettext("Too many bytes read from the itrm!"));
		itrm->in.queue.len = ITRM_IN_QUEUE_SIZE;
	}

	while (process_queue(itrm));
}
예제 #2
0
파일: packages.c 프로젝트: guillemj/dpkg
int
packages(const char *const *argv)
{
  trigproc_install_hooks();

  modstatdb_open(f_noact ?                  msdbrw_readonly :
                 in_force(FORCE_NON_ROOT) ? msdbrw_write :
                                            msdbrw_needsuperuser);
  checkpath();
  pkg_infodb_upgrade();

  log_message("startup packages %s", cipaction->olong);

  if (f_pending) {
    if (*argv)
      badusage(_("--%s --pending does not take any non-option arguments"),cipaction->olong);

    enqueue_pending();
  } else {
    if (!*argv)
      badusage(_("--%s needs at least one package name argument"), cipaction->olong);

    enqueue_specified(argv);
  }

  ensure_diversions();

  process_queue();
  trigproc_run_deferred();

  modstatdb_shutdown();

  return 0;
}
예제 #3
0
static void
joi_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
{
	MsnSession *session;
	PurpleAccount *account;
	PurpleConnection *gc;
	MsnSwitchBoard *swboard;
	const char *passport;

	passport = cmd->params[0];

	session = cmdproc->session;
	account = session->account;
	gc = account->gc;
	swboard = cmdproc->data;

	msn_switchboard_add_user(swboard, passport);

	process_queue(swboard);

	if (!session->http_method)
		send_clientcaps(swboard);

	if (swboard->closed)
		msn_switchboard_close(swboard);
}
/**
 * Transmit the given message to the given target.
 *
 * @param target peer that should receive the message (must be connected)
 * @param msg message to transmit
 * @param timeout by when should the transmission be done?
 */
void
GSC_NEIGHBOURS_transmit (const struct GNUNET_PeerIdentity *target,
                         const struct GNUNET_MessageHeader *msg,
                         struct GNUNET_TIME_Relative timeout)
{
  struct NeighbourMessageEntry *me;
  struct Neighbour *n;
  size_t msize;

  n = find_neighbour (target);
  if (NULL == n)
  {
    GNUNET_break (0);
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                "Peer %s not found\n",
                GNUNET_i2s (target));
    return;
  }
  msize = ntohs (msg->size);
  me = GNUNET_malloc (sizeof (struct NeighbourMessageEntry) + msize);
  me->deadline = GNUNET_TIME_relative_to_absolute (timeout);
  me->size = msize;
  memcpy (&me[1],
          msg,
          msize);
  GNUNET_CONTAINER_DLL_insert_tail (n->message_head,
                                    n->message_tail,
                                    me);
  n->queue_size++;
  process_queue (n);
}
예제 #5
0
/*
 * Add a message to sending queue
 * 
 * Do not free @message.
 */
static void
queue_message (GSSDPResourceGroup *resource_group,
               char               *message)
{
        GSSDPResourceGroupPrivate *priv;
        priv = gssdp_resource_group_get_instance_private (resource_group);

        g_queue_push_tail (priv->message_queue, message);

        if (priv->message_src != NULL) {
                return;
        }

        /* nothing in the queue: process message immediately
           and add a timeout for (possible) next message */
        process_queue (resource_group);
        priv->message_src = g_timeout_source_new (priv->message_delay);
        g_source_set_callback (priv->message_src,
                               process_queue,
                               resource_group,
                               NULL);
        g_source_attach (priv->message_src,
                        g_main_context_get_thread_default ());
        g_source_unref (priv->message_src);
}
예제 #6
0
파일: kbd.c 프로젝트: Efreak/elinks
/** Timer callback for itrm.timer.  As explained in install_timer(),
 * this function must erase the expired timer ID from all variables.  */
static void
kbd_timeout(struct itrm *itrm)
{
	struct interlink_event ev;
	int el;

	itrm->timer = TIMER_ID_UNDEF;
	/* The expired timer ID has now been erased.  */

	assertm(itrm->in.queue.len, "timeout on empty queue");
	assert(!itrm->blocked);	/* block_itrm should have killed itrm->timer */
	if_assert_failed return;

	if (can_read(itrm->in.std)) {
		in_kbd(itrm);
		return;
	}

	if (itrm->in.queue.len >= 2 && itrm->in.queue.data[0] == ASCII_ESC) {
		/* This is used for ESC [ and ESC O.  */
		set_kbd_event(itrm, &ev, itrm->in.queue.data[1], KBD_MOD_ALT);
		el = 2;
	} else {
		set_kbd_event(itrm, &ev, itrm->in.queue.data[0], KBD_MOD_NONE);
		el = 1;
	}
	itrm->bracketed_pasting = 0;
	itrm_queue_event(itrm, (char *) &ev, sizeof(ev));

	itrm->in.queue.len -= el;
	if (itrm->in.queue.len)
		memmove(itrm->in.queue.data, itrm->in.queue.data + el, itrm->in.queue.len);

	while (process_queue(itrm));
}
예제 #7
0
int main (int argc, char ** argv)
{
    int addr_server_port;
    struct timeval timeout;
    int i;
    int nb;
    char *ipaddress = 0;

    if (argc > 1) {
	if ((addr_server_port = atoi(argv[1])) == 0) {
	    fprintf(stderr, "addr_server: malformed port number.\n");
	    exit(2);
	}
	if (argc > 2) {
	    if (inet_addr((ipaddress = argv[2])) == INADDR_NONE) {
		fprintf(stderr, "addr_server: malformed ip address.\n");
		exit(3);
	    }
	}
    } else {
	fprintf(stderr, "addr_server: first arg must be port number.\n");
	exit(1);
    }
    init_conn_sock(addr_server_port, ipaddress);
    while (1) {
	/*
	 * use finite timeout for robustness.
	 */
	timeout.tv_sec = 2;
	timeout.tv_usec = 0;
	/*
	 * clear selectmasks.
	 */
	FD_ZERO(&readmask);
	/*
	 * set new connection accept fd in readmask.
	 */
	FD_SET(conn_fd, &readmask);
	/*
	 * set active fds in readmask.
	 */
	for (i = 0; i < MAX_CONNS; i++) {
	    if (all_conns[i].state == CONN_OPEN)
		FD_SET(all_conns[i].fd, &readmask);
	}
#ifndef hpux
	nb = select(FD_SETSIZE, &readmask, (fd_set *) 0, (fd_set *) 0, &timeout);
#else
	nb = select(FD_SETSIZE, (int *) &readmask, (int *) 0, (int *) 0, &timeout);
#endif
	if (nb != 0)
	    aserv_process_io(nb);
	process_queue();
    }
    /* the following is to shut lint up */
    /*NOTREACHED*/
    return 0;			/* never reached */
}
예제 #8
0
static void
xxunlock()
{
	DPF((stderr, "** UNLOCK **\n"));
	the_lock.remote_daemon = NULL;
	the_lock.type = LOCK_NOTLOCKED;
	the_lock.nholders = 0;
	the_lock.state = STATE_CLEAR;
	process_queue();
}
예제 #9
0
static gboolean
process_queue_timeout_cb (MexDownloadQueue *self)
{
  MexDownloadQueuePrivate *priv = self->priv;

  priv->process_timeout = 0;
  process_queue (self);

  return FALSE;
}
static void
gssdp_resource_group_dispose (GObject *object)
{
        GSSDPResourceGroup *resource_group;
        GSSDPResourceGroupPrivate *priv;

        resource_group = GSSDP_RESOURCE_GROUP (object);
        priv = resource_group->priv;

        while (priv->resources) {
                resource_free (priv->resources->data);
                priv->resources =
                        g_list_delete_link (priv->resources,
                                            priv->resources);
        }

        if (priv->message_queue) {
                /* send messages without usual delay */
                while (!g_queue_is_empty (priv->message_queue)) {
                        if (priv->available)
                                process_queue (resource_group);
                        else
                                g_free (g_queue_pop_head
                                        (priv->message_queue));
                }

                g_queue_free (priv->message_queue);
                priv->message_queue = NULL;
        }

        if (priv->message_src) {
                g_source_destroy (priv->message_src);
                priv->message_src = NULL;
        }

        if (priv->timeout_src) {
                g_source_destroy (priv->timeout_src);
                priv->timeout_src = NULL;
        }

        if (priv->client) {
                if (g_signal_handler_is_connected
                        (priv->client,
                         priv->message_received_id)) {
                        g_signal_handler_disconnect
                                (priv->client,
                                 priv->message_received_id);
                }

                g_object_unref (priv->client);
                priv->client = NULL;
        }

        G_OBJECT_CLASS (gssdp_resource_group_parent_class)->dispose (object);
}
예제 #11
0
static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
{
	// Pop the service
	mlt_filter filter = mlt_frame_pop_service( frame );

	// Get the frame properties
	mlt_properties frame_properties = MLT_FRAME_PROPERTIES( frame );

	mlt_service_lock( MLT_FILTER_SERVICE( filter ) );

	// Track specific
	process_queue( mlt_properties_get_data( frame_properties, "data_queue", NULL ), frame, filter );

	// Global
	process_queue( mlt_properties_get_data( frame_properties, "global_queue", NULL ), frame, filter );

	mlt_service_unlock( MLT_FILTER_SERVICE( filter ) );

	// Need to get the image
	return mlt_frame_get_image( frame, image, format, width, height, 1 );
}
예제 #12
0
    //! Thread body method.
    void
    body()
    {
        m_thread_id = so_5::query_current_thread_id();

        agent_queue_t * agent_queue;
        while( nullptr !=
                (agent_queue = m_disp_queue->pop( *m_condition )) )
        {
            process_queue( *agent_queue );
        }
    }
예제 #13
0
static void
mex_download_queue_free (DQTask *task)
{
  MexDownloadQueue *self = task->any.queue;
  MexDownloadQueuePrivate *priv = self->priv;

  switch (task->any.type)
    {
    case MEX_DQ_TYPE_GIO:
      if (task->gio.cancellable)
        {
          g_cancellable_cancel (task->gio.cancellable);

          /* Return, cancelling the task will run the file load callback,
            * which will unref the cancellable and call this free function
            * again.
            */
          return;
        }

      if (task->gio.file)
        g_object_unref (task->gio.file);

      break;

    case MEX_DQ_TYPE_SOUP:
      if (task->soup.message)
        {
          soup_session_cancel_message (priv->session,
                                       task->soup.message,
                                       SOUP_STATUS_CANCELLED);

          /* Return, the callback will call this function again
            * after setting the message to NULL.
            */
          return;
        }

      break;

    default:
      break;
    }

  if (task->any.type != MEX_DQ_TYPE_NONE)
    {
      priv->in_progress--;
      process_queue (self);
      g_object_notify (G_OBJECT (self), "queue-length");
    }

  g_slice_free (DQTask, task);
}
예제 #14
0
파일: of_war.cpp 프로젝트: 7k2/7k2
//--------- Begin of function FirmWar::next_day ---------//
//
void FirmWar::next_day()
{
    //----- call next_day() of the base class -----//

    FirmWork::next_day();

    //--------- process building weapon -------//

    if( build_unit_id )
        process_build();
    else
        process_queue();
}
예제 #15
0
/**
 * Function called whenever we receive a message from
 * the service.  Calls the appropriate handler.
 *
 * @param cls the 'struct GNUNET_DATASTORE_Handle'
 * @param msg the received message
 */
static void
receive_cb (void *cls, const struct GNUNET_MessageHeader *msg)
{
  struct GNUNET_DATASTORE_Handle *h = cls;
  struct GNUNET_DATASTORE_QueueEntry *qe;

  h->in_receive = GNUNET_NO;
  LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving reply from datastore\n");
  if (h->skip_next_messages > 0)
  {
    h->skip_next_messages--;
    process_queue (h);
    return;
  }
  if (NULL == (qe = h->queue_head))
  {
    GNUNET_break (0);
    process_queue (h);
    return;
  }
  qe->response_proc (h, msg);
}
예제 #16
0
/**
 * Store an item in the datastore.  If the item is already present,
 * the priorities are summed up and the higher expiration time and
 * lower anonymity level is used.
 *
 * @param h handle to the datastore
 * @param rid reservation ID to use (from "reserve"); use 0 if no
 *            prior reservation was made
 * @param key key for the value
 * @param size number of bytes in data
 * @param data content stored
 * @param type type of the content
 * @param priority priority of the content
 * @param anonymity anonymity-level for the content
 * @param replication how often should the content be replicated to other peers?
 * @param expiration expiration time for the content
 * @param queue_priority ranking of this request in the priority queue
 * @param max_queue_size at what queue size should this request be dropped
 *        (if other requests of higher priority are in the queue)
 * @param timeout timeout for the operation
 * @param cont continuation to call when done
 * @param cont_cls closure for cont
 * @return NULL if the entry was not queued, otherwise a handle that can be used to
 *         cancel; note that even if NULL is returned, the callback will be invoked
 *         (or rather, will already have been invoked)
 */
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, uint32_t rid,
                      const struct GNUNET_HashCode * key, size_t size,
                      const void *data, enum GNUNET_BLOCK_Type type,
                      uint32_t priority, uint32_t anonymity,
                      uint32_t replication,
                      struct GNUNET_TIME_Absolute expiration,
                      unsigned int queue_priority, unsigned int max_queue_size,
                      struct GNUNET_TIME_Relative timeout,
                      GNUNET_DATASTORE_ContinuationWithStatus cont,
                      void *cont_cls)
{
  struct GNUNET_DATASTORE_QueueEntry *qe;
  struct DataMessage *dm;
  size_t msize;
  union QueueContext qc;

  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Asked to put %u bytes of data under key `%s' for %llu ms\n", size,
       GNUNET_h2s (key),
       GNUNET_TIME_absolute_get_remaining (expiration).rel_value);
  msize = sizeof (struct DataMessage) + size;
  GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
  qc.sc.cont = cont;
  qc.sc.cont_cls = cont_cls;
  qe = make_queue_entry (h, msize, queue_priority, max_queue_size, timeout,
                         &process_status_message, &qc);
  if (qe == NULL)
  {
    LOG (GNUNET_ERROR_TYPE_DEBUG, "Could not create queue entry for PUT\n");
    return NULL;
  }
  GNUNET_STATISTICS_update (h->stats, gettext_noop ("# PUT requests executed"),
                            1, GNUNET_NO);
  dm = (struct DataMessage *) &qe[1];
  dm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_PUT);
  dm->header.size = htons (msize);
  dm->rid = htonl (rid);
  dm->size = htonl ((uint32_t) size);
  dm->type = htonl (type);
  dm->priority = htonl (priority);
  dm->anonymity = htonl (anonymity);
  dm->replication = htonl (replication);
  dm->reserved = htonl (0);
  dm->uid = GNUNET_htonll (0);
  dm->expiration = GNUNET_TIME_absolute_hton (expiration);
  dm->key = *key;
  memcpy (&dm[1], data, size);
  process_queue (h);
  return qe;
}
예제 #17
0
/**
 * Get a result for a particular key from the datastore.  The processor
 * will only be called once.
 *
 * @param h handle to the datastore
 * @param offset offset of the result (modulo num-results); set to
 *               a random 64-bit value initially; then increment by
 *               one each time; detect that all results have been found by uid
 *               being again the first uid ever returned.
 * @param key maybe NULL (to match all entries)
 * @param type desired type, 0 for any
 * @param queue_priority ranking of this request in the priority queue
 * @param max_queue_size at what queue size should this request be dropped
 *        (if other requests of higher priority are in the queue)
 * @param timeout how long to wait at most for a response
 * @param proc function to call on each matching value;
 *        will be called once with a NULL value at the end
 * @param proc_cls closure for proc
 * @return NULL if the entry was not queued, otherwise a handle that can be used to
 *         cancel
 */
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, uint64_t offset,
                          const struct GNUNET_HashCode * key,
                          enum GNUNET_BLOCK_Type type,
                          unsigned int queue_priority,
                          unsigned int max_queue_size,
                          struct GNUNET_TIME_Relative timeout,
                          GNUNET_DATASTORE_DatumProcessor proc, void *proc_cls)
{
  struct GNUNET_DATASTORE_QueueEntry *qe;
  struct GetMessage *gm;
  union QueueContext qc;

  GNUNET_assert (NULL != proc);
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Asked to look for data of type %u under key `%s'\n",
       (unsigned int) type, GNUNET_h2s (key));
  qc.rc.proc = proc;
  qc.rc.proc_cls = proc_cls;
  qe = make_queue_entry (h, sizeof (struct GetMessage), queue_priority,
                         max_queue_size, timeout, &process_result_message, &qc);
  if (qe == NULL)
  {
    LOG (GNUNET_ERROR_TYPE_DEBUG, "Could not queue request for `%s'\n",
         GNUNET_h2s (key));
    return NULL;
  }
#if INSANE_STATISTICS
  GNUNET_STATISTICS_update (h->stats, gettext_noop ("# GET requests executed"),
                            1, GNUNET_NO);
#endif
  gm = (struct GetMessage *) &qe[1];
  gm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_GET);
  gm->type = htonl (type);
  gm->offset = GNUNET_htonll (offset);
  if (key != NULL)
  {
    gm->header.size = htons (sizeof (struct GetMessage));
    gm->key = *key;
  }
  else
  {
    gm->header.size =
        htons (sizeof (struct GetMessage) - sizeof (struct GNUNET_HashCode));
  }
  process_queue (h);
  return qe;
}
예제 #18
0
/**
 * Explicitly remove some content from the database.
 * The "cont"inuation will be called with status
 * "GNUNET_OK" if content was removed, "GNUNET_NO"
 * if no matching entry was found and "GNUNET_SYSERR"
 * on all other types of errors.
 *
 * @param h handle to the datastore
 * @param key key for the value
 * @param size number of bytes in data
 * @param data content stored
 * @param queue_priority ranking of this request in the priority queue
 * @param max_queue_size at what queue size should this request be dropped
 *        (if other requests of higher priority are in the queue)
 * @param timeout how long to wait at most for a response
 * @param cont continuation to call when done
 * @param cont_cls closure for cont
 * @return NULL if the entry was not queued, otherwise a handle that can be used to
 *         cancel; note that even if NULL is returned, the callback will be invoked
 *         (or rather, will already have been invoked)
 */
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
                         const struct GNUNET_HashCode * key, size_t size,
                         const void *data, unsigned int queue_priority,
                         unsigned int max_queue_size,
                         struct GNUNET_TIME_Relative timeout,
                         GNUNET_DATASTORE_ContinuationWithStatus cont,
                         void *cont_cls)
{
  struct GNUNET_DATASTORE_QueueEntry *qe;
  struct DataMessage *dm;
  size_t msize;
  union QueueContext qc;

  if (cont == NULL)
    cont = &drop_status_cont;
  LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to remove %u bytes under key `%s'\n",
       size, GNUNET_h2s (key));
  qc.sc.cont = cont;
  qc.sc.cont_cls = cont_cls;
  msize = sizeof (struct DataMessage) + size;
  GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
  qe = make_queue_entry (h, msize, queue_priority, max_queue_size, timeout,
                         &process_status_message, &qc);
  if (qe == NULL)
  {
    LOG (GNUNET_ERROR_TYPE_DEBUG, "Could not create queue entry for REMOVE\n");
    return NULL;
  }
  GNUNET_STATISTICS_update (h->stats,
                            gettext_noop ("# REMOVE requests executed"), 1,
                            GNUNET_NO);
  dm = (struct DataMessage *) &qe[1];
  dm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE);
  dm->header.size = htons (msize);
  dm->rid = htonl (0);
  dm->size = htonl (size);
  dm->type = htonl (0);
  dm->priority = htonl (0);
  dm->anonymity = htonl (0);
  dm->uid = GNUNET_htonll (0);
  dm->expiration = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_ZERO_ABS);
  dm->key = *key;
  memcpy (&dm[1], data, size);
  process_queue (h);
  return qe;
}
예제 #19
0
gpointer
mex_download_queue_enqueue (MexDownloadQueue               *queue,
                            const char                     *uri,
                            MexDownloadQueueCompletedReply  reply,
                            gpointer                        userdata)
{
  MexDownloadQueuePrivate *priv;
  DQTask *task;

  g_return_val_if_fail (MEX_IS_DOWNLOAD_QUEUE (queue), NULL);
  g_return_val_if_fail (uri, NULL);

  priv = queue->priv;

  task = g_slice_new0 (DQTask);
  task->any.uri = g_strdup (uri);
  task->any.queue = queue;
  task->any.callback = reply;
  task->any.userdata = userdata;

  MEX_NOTE (DOWNLOAD_QUEUE, "queueing download: %s", uri);

  if (g_str_has_prefix (uri, "http://"))
    g_queue_push_tail (priv->queue, task);
  else
    {
      /* Push local requests before web requests */
      if (!priv->last_local)
        {
          g_queue_push_head (priv->queue, task);
          priv->last_local = priv->queue->head;
        }
      else
        {
          g_queue_insert_after (priv->queue, priv->last_local, task);
          priv->last_local = priv->last_local->next;
        }
    }

  process_queue (queue);

  g_object_notify (G_OBJECT (queue), "queue-length");

  return task;
}
예제 #20
0
파일: OF_HARB.cpp 프로젝트: Stummi/7kaa
//--------- Begin of function FirmHarbor::next_day ---------//
//
void FirmHarbor::next_day()
{
	//----- call next_day() of the base class -----//

	Firm::next_day();

	//------- process building -------//

	if( build_unit_id )
		process_build();
	else
		process_queue();

	//-*********** simulate ship movement ************-//
	//if(build_unit_id==0)
	//	build_ship(UNIT_CARAVEL, 0);
	//-*********** simulate ship movement ************-//
}
예제 #21
0
static void
gssdp_resource_group_dispose (GObject *object)
{
        GSSDPResourceGroup *resource_group;
        GSSDPResourceGroupPrivate *priv;

        resource_group = GSSDP_RESOURCE_GROUP (object);
        priv = gssdp_resource_group_get_instance_private (resource_group);

        g_list_free_full (priv->resources, (GFreeFunc) resource_free);
        priv->resources = NULL;

        if (priv->message_queue) {
                /* send messages without usual delay */
                while (!g_queue_is_empty (priv->message_queue)) {
                        if (priv->available)
                                process_queue (resource_group);
                        else
                                g_free (g_queue_pop_head
                                        (priv->message_queue));
                }

                g_clear_pointer (&priv->message_queue, g_queue_free);
        }


        /* No need to unref sources, already done on creation */
        g_clear_pointer (&priv->message_src, g_source_destroy);
        g_clear_pointer (&priv->timeout_src, g_source_destroy);

        if (priv->client) {
                if (g_signal_handler_is_connected
                        (priv->client,
                         priv->message_received_id)) {
                        g_signal_handler_disconnect
                                (priv->client,
                                 priv->message_received_id);
                }

                g_clear_object (&priv->client);
        }

        G_OBJECT_CLASS (gssdp_resource_group_parent_class)->dispose (object);
}
예제 #22
0
/**
 * Get a single zero-anonymity value from the datastore.
 *
 * @param h handle to the datastore
 * @param offset offset of the result (modulo num-results); set to
 *               a random 64-bit value initially; then increment by
 *               one each time; detect that all results have been found by uid
 *               being again the first uid ever returned.
 * @param queue_priority ranking of this request in the priority queue
 * @param max_queue_size at what queue size should this request be dropped
 *        (if other requests of higher priority are in the queue)
 * @param timeout how long to wait at most for a response
 * @param type allowed type for the operation (never zero)
 * @param proc function to call on a random value; it
 *        will be called once with a value (if available)
 *        or with NULL if none value exists.
 * @param proc_cls closure for proc
 * @return NULL if the entry was not queued, otherwise a handle that can be used to
 *         cancel
 */
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
                                     uint64_t offset,
                                     unsigned int queue_priority,
                                     unsigned int max_queue_size,
                                     struct GNUNET_TIME_Relative timeout,
                                     enum GNUNET_BLOCK_Type type,
                                     GNUNET_DATASTORE_DatumProcessor proc,
                                     void *proc_cls)
{
  struct GNUNET_DATASTORE_QueueEntry *qe;
  struct GetZeroAnonymityMessage *m;
  union QueueContext qc;

  GNUNET_assert (NULL != proc);
  GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY);
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Asked to get %llu-th zero-anonymity entry of type %d in %llu ms\n",
       (unsigned long long) offset, type,
       (unsigned long long) timeout.rel_value);
  qc.rc.proc = proc;
  qc.rc.proc_cls = proc_cls;
  qe = make_queue_entry (h, sizeof (struct GetZeroAnonymityMessage),
                         queue_priority, max_queue_size, timeout,
                         &process_result_message, &qc);
  if (qe == NULL)
  {
    LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Could not create queue entry for zero-anonymity procation\n");
    return NULL;
  }
  GNUNET_STATISTICS_update (h->stats,
                            gettext_noop
                            ("# GET ZERO ANONYMITY requests executed"), 1,
                            GNUNET_NO);
  m = (struct GetZeroAnonymityMessage *) &qe[1];
  m->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY);
  m->header.size = htons (sizeof (struct GetZeroAnonymityMessage));
  m->type = htonl ((uint32_t) type);
  m->offset = GNUNET_htonll (offset);
  process_queue (h);
  return qe;
}
예제 #23
0
/**
 * Cancel a datastore operation.  The final callback from the
 * operation must not have been done yet.
 *
 * @param qe operation to cancel
 */
void
GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe)
{
  struct GNUNET_DATASTORE_Handle *h;

  GNUNET_assert (GNUNET_SYSERR != qe->was_transmitted);
  h = qe->h;
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Pending DATASTORE request %p cancelled (%d, %d)\n", qe,
       qe->was_transmitted, h->queue_head == qe);
  if (GNUNET_YES == qe->was_transmitted)
  {
    free_queue_entry (qe);
    h->skip_next_messages++;
    return;
  }
  free_queue_entry (qe);
  process_queue (h);
}
/*
 * Add a message to sending queue
 *
 * Do not free @message.
 */
static void
queue_message (GSSDPResourceGroup *resource_group,
               char               *message)
{
        g_queue_push_tail (resource_group->priv->message_queue,
                           message);

        if (resource_group->priv->message_src == NULL) {
                /* nothing in the queue: process message immediately
                   and add a timeout for (possible) next message */
                process_queue (resource_group);
                resource_group->priv->message_src = g_timeout_source_new (
                    resource_group->priv->message_delay);
                g_source_set_callback (resource_group->priv->message_src,
                    process_queue, resource_group, NULL);
                g_source_attach (resource_group->priv->message_src,
                                 g_main_context_get_thread_default ());
                g_source_unref (resource_group->priv->message_src);
        }
}
예제 #25
0
//=============================================================================
void Logger::log(const std::string& category,
                 const std::string& message,
                 LogData* data)
{
  LogEntry* entry = new LogEntry();
  ::gettimeofday(&entry->m_time,0);
  entry->m_category = category;
  entry->m_message = message;
  entry->m_data = data;

  m_mutex->lock();
  m_queue.push_back(entry);
  m_mutex->unlock();

  if (m_thread) {
    m_thread->wakeup();
  } else {
    process_queue();
  }
}
예제 #26
0
/**
 * Try reconnecting to the datastore service.
 *
 * @param cls the 'struct GNUNET_DATASTORE_Handle'
 * @param tc scheduler context
 */
static void
try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct GNUNET_DATASTORE_Handle *h = cls;

  h->retry_time = GNUNET_TIME_STD_BACKOFF (h->retry_time);
  h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
  h->client = GNUNET_CLIENT_connect ("datastore", h->cfg);
  if (h->client == NULL)
  {
    LOG (GNUNET_ERROR_TYPE_ERROR, "DATASTORE reconnect failed (fatally)\n");
    return;
  }
  GNUNET_STATISTICS_update (h->stats,
                            gettext_noop
                            ("# datastore connections (re)created"), 1,
                            GNUNET_NO);
  LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnected to DATASTORE\n");
  process_queue (h);
}
/**
 * Check if we have messages for the specified neighbour pending, and
 * if so, check with the transport about sending them out.
 *
 * @param n neighbour to check.
 */
static void
process_queue (struct Neighbour *n)
{
  struct NeighbourMessageEntry *m;

  if (NULL != n->th)
    return;                     /* request already pending */
  m = n->message_head;
  if (NULL == m)
  {
    /* notify sessions that the queue is empty and more messages
     * could thus be queued now */
    GSC_SESSIONS_solicit (&n->peer);
    return;
  }
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Asking transport for transmission of %u bytes to `%s' in next %s\n",
              (unsigned int) m->size,
              GNUNET_i2s (&n->peer),
              GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (m->deadline),
                                                      GNUNET_NO));
  m->submission_time = GNUNET_TIME_absolute_get ();
  n->th
    = GNUNET_TRANSPORT_notify_transmit_ready (transport,
                                              &n->peer,
                                              m->size,
                                              GNUNET_TIME_absolute_get_remaining (m->deadline),
                                              &transmit_ready,
                                              n);
  if (NULL != n->th)
    return;
  /* message request too large or duplicate request */
  GNUNET_break (0);
  /* discard encrypted message */
  GNUNET_CONTAINER_DLL_remove (n->message_head,
                               n->message_tail,
                               m);
  n->queue_size--;
  GNUNET_free (m);
  process_queue (n);
}
예제 #28
0
/**
 * Transmit request from queue to datastore service.
 *
 * @param cls the 'struct GNUNET_DATASTORE_Handle'
 * @param size number of bytes that can be copied to buf
 * @param buf where to copy the drop message
 * @return number of bytes written to buf
 */
static size_t
transmit_request (void *cls, size_t size, void *buf)
{
  struct GNUNET_DATASTORE_Handle *h = cls;
  struct GNUNET_DATASTORE_QueueEntry *qe;
  size_t msize;

  h->th = NULL;
  if (NULL == (qe = h->queue_head))
    return 0;                   /* no entry in queue */
  if (buf == NULL)
  {
    LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to transmit request to DATASTORE.\n");
    GNUNET_STATISTICS_update (h->stats,
                              gettext_noop ("# transmission request failures"),
                              1, GNUNET_NO);
    do_disconnect (h);
    return 0;
  }
  if (size < (msize = qe->message_size))
  {
    process_queue (h);
    return 0;
  }
  LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting %u byte request to DATASTORE\n",
       msize);
  memcpy (buf, &qe[1], msize);
  qe->was_transmitted = GNUNET_YES;
  GNUNET_SCHEDULER_cancel (qe->task);
  qe->task = GNUNET_SCHEDULER_NO_TASK;
  GNUNET_assert (GNUNET_NO == h->in_receive);
  h->in_receive = GNUNET_YES;
  GNUNET_CLIENT_receive (h->client, &receive_cb, h,
                         GNUNET_TIME_absolute_get_remaining (qe->timeout));
#if INSANE_STATISTICS
  GNUNET_STATISTICS_update (h->stats,
                            gettext_noop ("# bytes sent to datastore"), 1,
                            GNUNET_NO);
#endif
  return msize;
}
예제 #29
0
/**
 * Update a value in the datastore.
 *
 * @param h handle to the datastore
 * @param uid identifier for the value
 * @param priority how much to increase the priority of the value
 * @param expiration new expiration value should be MAX of existing and this argument
 * @param queue_priority ranking of this request in the priority queue
 * @param max_queue_size at what queue size should this request be dropped
 *        (if other requests of higher priority are in the queue)
 * @param timeout how long to wait at most for a response
 * @param cont continuation to call when done
 * @param cont_cls closure for cont
 * @return NULL if the entry was not queued, otherwise a handle that can be used to
 *         cancel; note that even if NULL is returned, the callback will be invoked
 *         (or rather, will already have been invoked)
 */
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h, uint64_t uid,
                         uint32_t priority,
                         struct GNUNET_TIME_Absolute expiration,
                         unsigned int queue_priority,
                         unsigned int max_queue_size,
                         struct GNUNET_TIME_Relative timeout,
                         GNUNET_DATASTORE_ContinuationWithStatus cont,
                         void *cont_cls)
{
  struct GNUNET_DATASTORE_QueueEntry *qe;
  struct UpdateMessage *um;
  union QueueContext qc;

  if (cont == NULL)
    cont = &drop_status_cont;
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Asked to update entry %llu raising priority by %u and expiration to %llu\n",
       uid, (unsigned int) priority, (unsigned long long) expiration.abs_value);
  qc.sc.cont = cont;
  qc.sc.cont_cls = cont_cls;
  qe = make_queue_entry (h, sizeof (struct UpdateMessage), queue_priority,
                         max_queue_size, timeout, &process_status_message, &qc);
  if (qe == NULL)
  {
    LOG (GNUNET_ERROR_TYPE_DEBUG, "Could not create queue entry for UPDATE\n");
    return NULL;
  }
  GNUNET_STATISTICS_update (h->stats,
                            gettext_noop ("# UPDATE requests executed"), 1,
                            GNUNET_NO);
  um = (struct UpdateMessage *) &qe[1];
  um->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE);
  um->header.size = htons (sizeof (struct UpdateMessage));
  um->priority = htonl (priority);
  um->expiration = GNUNET_TIME_absolute_hton (expiration);
  um->uid = GNUNET_htonll (uid);
  process_queue (h);
  return qe;
}
예제 #30
0
/*
 * ===  FUNCTION  ======================================================================
 *         Name:  subproc_exec
 *  Description:  fork()s 'num_procs' children, each of which gets its own
 *                message queue.  Children process messages through the
 *                process_queue() function, then exit.
 * =====================================================================================
 */
static void
subproc_exec(int *queuep, key_t *keyp, int num_procs)
{
    int i;
    int msgrcv_flg = 0;
    key_t parent_key, child_key;

    for(i = 1; i <= num_procs; i++) {
        switch(pids[i] = fork()) {
            case -1:
                perror("fork");
                exit(EXIT_FAILURE);
                break;
            case 0:
                /* parent_queue and child_queue
                 * are global variables, as are
                 * the '_key' and '_pid' variables
                 * and 'keys' and 'pids' arrays. */
                parent_queue = queuep[0];
                child_queue = queuep[i];
                parent_key = keyp[0];
                child_key = keyp[i];
                /* Since pid[i] is 0 in child,
                 * call getpid() to get the real one. */
                child_pid = pids[i] = getpid();
                process_queue(parent_queue, MSG_SZ, child_pid, msgrcv_flg, &compar_mbuf, &send_msg_nodes);
                /* Each child has its own copy of these
                 * global arrays, and each must free them. */
                free(keys);
                free(queues);
                free(pids);
                _exit(EXIT_SUCCESS);
                break;
            default:
                break;
        }
    }
    return;
}