Exemplo n.º 1
0
/* _write:
 */
static LStreamStatus _write ( LStream *stream,
                              gconstpointer buffer,
                              gint64 size,
                              gint64 *bytes_written,
                              GError **error )
{
#define m (L_MEM_STREAM(stream))
  gint64 pos2 = m->pos + size;
  gint64 new_size = MAX(pos2, m->data_size);
  _grow_buffer(m, new_size);
  memcpy(m->buffer + m->pos, buffer, size);
  m->pos = pos2;
  m->data_size = new_size;
  if (bytes_written)
    *bytes_written = size;
  return L_STREAM_STATUS_OK;
#undef m
}
Exemplo n.º 2
0
/* l_mem_stream_new:
 */
LStream *l_mem_stream_new ( const gchar *content,
                            gint64 size )
{
  LMemStream *m;
  m = L_MEM_STREAM(l_object_new(L_CLASS_MEM_STREAM, NULL));
  if (content)
    {
      if (size < 0)
        size = strlen(content);
      if (size > 0) {
        _grow_buffer(m, size);
        memcpy(m->buffer, content, size);
        m->data_size = size;
      }
    }
  else
    {
      ASSERT(size <= 0);
    }
  return L_STREAM(m);
}
Exemplo n.º 3
0
// check if a command needs processing
static void _poll_command(protocolState_t *ps)
{
	if (ps->stopped) return;

	threadIPC_t *ipc = ps->ipc;

	pthread_mutex_lock(&ipc->lock);

	switch (ipc->command) {

	case COMMAND_SHUTDOWN:
	    DBGPRINTF("omamqp1: Protocol thread processing shutdown command\n");
	    ps->stopped = true;
	    _close_connection(ps);
	    // wait for the shutdown to complete before ack'ing this command
	    break;

	case COMMAND_IS_READY:
	    DBGPRINTF("omamqp1: Protocol thread processing ready query command\n");
	    ipc->result = _is_ready(ps->sender)
	                  ? RS_RET_OK
	                  : RS_RET_SUSPENDED;
	    ipc->command = COMMAND_DONE;
	    pthread_cond_signal(&ipc->condition);
	    break;

	case COMMAND_SEND:
	    if (ps->delivery) break;  // currently processing this command
	    DBGPRINTF("omamqp1: Protocol thread processing send message command\n");
	    if (!_is_ready(ps->sender)) {
	        ipc->result = RS_RET_SUSPENDED;
	        ipc->command = COMMAND_DONE;
	        pthread_cond_signal(&ipc->condition);
	        break;
	    }

	    // send the message
	    ++ps->tag;
	    ps->delivery = pn_delivery(ps->sender,
	                               pn_dtag((const char *)&ps->tag, sizeof(ps->tag)));
	    pn_message_t *message = ipc->message;
	    assert(message);

	    int rc = 0;
	    size_t len = ps->buffer_size;
	    do {
	        rc = pn_message_encode(message, ps->encode_buffer, &len);
	        if (rc == PN_OVERFLOW) {
	            _grow_buffer(ps);
	            len = ps->buffer_size;
	        }
	    } while (rc == PN_OVERFLOW);

	    pn_link_send(ps->sender, ps->encode_buffer, len);
	    pn_link_advance(ps->sender);
	    ++ps->msgs_sent;
	    // command completes when remote updates the delivery (see PN_DELIVERY)
	    break;

	case COMMAND_DONE:
	    break;
	}

	pthread_mutex_unlock(&ipc->lock);
}