void amqpmanagement_destroy(AMQP_MANAGEMENT_HANDLE amqp_management)
{
	if (amqp_management != NULL)
	{
		(void)amqpmanagement_close(amqp_management);

		if (amqp_management->operation_message_count > 0)
		{
			size_t i;
			for (i = 0; i < amqp_management->operation_message_count; i++)
			{
				message_destroy(amqp_management->operation_messages[i]->message);
				amqpalloc_free(amqp_management->operation_messages[i]);
			}

			amqpalloc_free(amqp_management->operation_messages);
		}

		link_destroy(amqp_management->sender_link);
		link_destroy(amqp_management->receiver_link);
		messagesender_destroy(amqp_management->message_sender);
		messagereceiver_destroy(amqp_management->message_receiver);
		amqpalloc_free(amqp_management);
	}
}
Beispiel #2
0
/* ARGSUSED1 */
static int
process_db_read(dlmgmt_db_req_t *req, FILE *fp, FILE *nfp)
{
	avl_index_t	name_where, id_where;
	dlmgmt_link_t	*link_in_file;
	dlmgmt_link_t	*linkp1, *linkp2;
	char		buf[MAXLINELEN];
	int		err = 0;

	/*
	 * This loop processes each line of the configuration file.
	 */
	while (fgets(buf, MAXLINELEN, fp) != NULL) {
		if (!process_link_line(buf, &link_in_file)) {
			err = EINVAL;
			break;
		}

		/*
		 * Skip the comment line.
		 */
		if (link_in_file == NULL)
			continue;

		linkp1 = avl_find(&dlmgmt_name_avl, link_in_file, &name_where);
		linkp2 = avl_find(&dlmgmt_id_avl, link_in_file, &id_where);
		if ((linkp1 != NULL) || (linkp2 != NULL)) {
			/*
			 * If any of the following conditions are met, this is
			 * a duplicate entry:
			 *
			 * 1. link2 (with the given name) and link2 (with the
			 *    given id) are not the same link;
			 * 2. This is a persistent req and find the link with
			 *    the given name and id. Note that persistent db
			 *    is read before the active one.
			 * 3. Found the link with the given name and id but
			 *    the link is already active.
			 */
			if ((linkp1 != linkp2) ||
			    (req->ls_flags == DLMGMT_PERSIST) ||
			    ((linkp1->ll_flags & DLMGMT_ACTIVE) != 0)) {
				dlmgmt_log(LOG_WARNING, "Duplicate link "
				    "entries in repository:  link name %s "
				    "link id %i", link_in_file->ll_link,
				    link_in_file->ll_linkid);
			} else {
				linkp1->ll_flags |= DLMGMT_ACTIVE;
			}
			link_destroy(link_in_file);
		} else {
			avl_insert(&dlmgmt_name_avl, link_in_file, name_where);
			avl_insert(&dlmgmt_id_avl, link_in_file, id_where);
			dlmgmt_advance(link_in_file);
			link_in_file->ll_flags |= req->ls_flags;
		}
	}

	return (err);
}
Beispiel #3
0
int main(int argc, char **argv)
{
      unsigned char       retVal;
      int                 i;
      LINK_NODE           *head = NULL;


      if( NULL == (head=link_create()) )
              return -1;

      for(i=1; i<5; i++)
      {
           retVal = link_insert(head, i, i);
           if(COMMON_OK != retVal) 
           {
                 printf("Insert node[%d] failure, retVal = 0x%02x\n", i, retVal); 
                 break;
           }
      }
      link_traverse(head);

      link_revers(head);
      printf("After revers...........................................................\n");
      link_traverse(head);

      printf("Destroy the linker now.\n");
      link_destroy(head);

      return 0;
}
Beispiel #4
0
/*******************************************************************************
 * Private functions
 ******************************************************************************/
static void destroy_links(struct dc *dc)
{
	uint32_t i;

	for (i = 0; i < dc->link_count; i++) {
		if (NULL != dc->links[i])
			link_destroy(&dc->links[i]);
	}
}
Beispiel #5
0
static void on_cleanup(u_conn *conn)
{
	u_log(LG_VERBOSE, "link: being cleaned up");

	if (conn->priv) {
		link_destroy(conn->priv);
		conn->priv = NULL;
	}
}
Beispiel #6
0
/*
 * Takes a link from the end of the linked list
 * and returns the item
 */
void *linklst_take(LINKLST_T *linklst) {
  if (linklst->size == 0) return NULL;
  LINK_T *link = linklst->last;
  LINK_T *new_last = link->before;
  if (new_last != NULL) new_last->after = NULL;
  linklst->last = new_last;
  linklst->size -= 1;
  void *item = link->item;
  link_destroy(link);
  return item;
}
Beispiel #7
0
/*
 * Removes the passed link from the list and 
 * returns the item.
 * Note that the link must be a part of the
 * list or bad things will happen!
 */
void *linklst_remove(LINK_T *link, LINKLST_T *linklst) {
  LINK_T *before = link->before;
  LINK_T *after = link->after;
  if (before != NULL) before->after = after;
  if (after != NULL) after->before = before;
  if (link == linklst->first) linklst->first = after;
  if (link == linklst->last) linklst->last = before;
  linklst->size -= 1;
  void *item = link->item;
  link_destroy(link);
  return item;
}
Beispiel #8
0
/*
 * Destroys a linked list, using the passed function to free the items
 */
void linklst_destroy_all(LINKLST_T *linklst, void(*free_item)(void *)) {
  LINK_T *current = linklst->first; 
  LINK_T *next;
  while (current != NULL) {
    next = current->after; 
    free_item(current->item);
    link_destroy(current);
    current = next;
  }
  memset(linklst, 0, sizeof(LINKLST_T));
  free(linklst);
}
Beispiel #9
0
void
links_destroy (void)
{
  GSList *list;

  while ((list = links))
    {
      Link *link = list->data;
      links = g_slist_remove (links, link);
      link_destroy (link);
    }
}
Beispiel #10
0
/*
 * Pops an item off the front of the linked list
 * and returns the item
 */
void *linklst_pop(LINKLST_T *linklst) {
  if (linklst->size == 0) return NULL;
  LINK_T *link = linklst->first;
  LINK_T *new_first = link->after;
  if (new_first != NULL) new_first->before = NULL;
  else linklst->last = NULL;
  linklst->first = new_first;
  linklst->size -= 1;
  void *item = link->item;
  link_destroy(link);
  return item;
}
Beispiel #11
0
void dabbad_interface_statistics_get(Dabba__DabbaService_Service * service,
                                     const Dabba__InterfaceIdList * id_list,
                                     Dabba__InterfaceStatisticsList_Closure
                                     closure, void *closure_data)
{
    Dabba__InterfaceStatisticsList statistics_list =
        DABBA__INTERFACE_STATISTICS_LIST__INIT;
    Dabba__InterfaceStatisticsList *statistics_listp = NULL;
    struct nl_sock *sock = NULL;
    struct nl_cache *cache;
    struct rtnl_link *link;
    size_t a;

    assert(service);
    assert(closure_data);

    cache = link_cache_alloc(&sock);
    link = rtnl_link_alloc();

    if (!link || !cache)
        goto out;

    if (id_list->n_list) {
        for (a = 0; a < id_list->n_list; a++) {
            rtnl_link_set_name(link, id_list->list[a]->name);
            nl_cache_foreach_filter(cache, OBJ_CAST(link),
                                    __interface_statistics_get,
                                    &statistics_list);
        }
    } else
        nl_cache_foreach(cache, __interface_statistics_get,
                         &statistics_list);

    statistics_listp = &statistics_list;

out:
    closure(statistics_listp, closure_data);
    for (a = 0; a < statistics_list.n_list; a++) {
        free(statistics_list.list[a]->status);
        free(statistics_list.list[a]->id);
        free(statistics_list.list[a]);
    }
    free(statistics_list.list);
    link_destroy(link);
    link_cache_destroy(sock, cache);
}
int main(void)
{
	//	link_head_init(&link_head);

	int a[5] = {1,2,3,4,5};
	int i;
	node_t *tmp = NULL;
	for (i = 0; i < 5; i++)
		link_head = link_insert_e(link_head, a[i]);
	link_print(link_head);
	//tmp = link_search(link_head, 4);
	//printf("%d\n", tmp->val);
	tmp = link_remove(link_head, 3);
	link_node_free(tmp);
	link_print(link_head);
	link_destroy(link_head);
	return 0;
}
Beispiel #13
0
u_link *u_link_connect(mowgli_eventloop_t *ev, u_link_block *block,
                       const struct sockaddr *addr, socklen_t addrlen)
{
	u_link *link = link_create();

	u_conn *conn;
	if (!(conn = u_conn_connect(ev, &u_link_conn_ctx, link, 0,
	                            addr, addrlen))) {
		link_destroy(link);
		return NULL;
	}

	link->conf.link = block;

	u_log(LG_VERBOSE, "connecting to %s", conn->ip);

	return link;
}
int main(void)
{
    link_t p = make_node(10);
    link_insert(p);

    p = make_node(5);
    link_insert(p);

    p = make_node(90);
    link_insert(p);

    p = link_search(5);
    link_delete(p);
    free_node(p);
    link_traverse(link_print);

    link_destroy();
    return 0;
}
Beispiel #15
0
static void accept_ready(mowgli_eventloop_t *ev, mowgli_eventloop_io_t *io,
                         mowgli_eventloop_io_dir_t dir, void *priv)
{
	mowgli_eventloop_pollable_t *poll = mowgli_eventloop_io_pollable(io);
	u_conn *conn;
	u_link *link;

	sync_time();

	link = link_create();

	if (!(conn = u_conn_accept(ev, &u_link_conn_ctx, link, 0, poll->fd))) {
		link_destroy(link);
		/* TODO: close listener, maybe? */
		return;
	}

	u_log(LG_VERBOSE, "new connection from %s", conn->ip);
}
Beispiel #16
0
int main(int argc, char** argv)
{
	int result;

    (void)argc, argv;
	amqpalloc_set_memory_tracing_enabled(true);

	if (platform_init() != 0)
	{
		result = -1;
	}
	else
	{
		XIO_HANDLE sasl_io;
		CONNECTION_HANDLE connection;
		SESSION_HANDLE session;
		LINK_HANDLE link;
		MESSAGE_SENDER_HANDLE message_sender;
		MESSAGE_HANDLE message;

		size_t last_memory_used = 0;

		/* create SASL PLAIN handler */
		SASL_PLAIN_CONFIG sasl_plain_config = { EH_KEY_NAME, EH_KEY, NULL };
		SASL_MECHANISM_HANDLE sasl_mechanism_handle = saslmechanism_create(saslplain_get_interface(), &sasl_plain_config);
		XIO_HANDLE tls_io;

		/* create the TLS IO */
        TLSIO_CONFIG tls_io_config = { EH_HOST, 5671 };
		const IO_INTERFACE_DESCRIPTION* tlsio_interface = platform_get_default_tlsio();
		tls_io = xio_create(tlsio_interface, &tls_io_config);

		/* create the SASL client IO using the TLS IO */
		SASLCLIENTIO_CONFIG sasl_io_config;
        sasl_io_config.underlying_io = tls_io;
        sasl_io_config.sasl_mechanism = sasl_mechanism_handle;
		sasl_io = xio_create(saslclientio_get_interface_description(), &sasl_io_config);

		/* create the connection, session and link */
		connection = connection_create(sasl_io, EH_HOST, "some", NULL, NULL);
		session = session_create(connection, NULL, NULL);
		session_set_incoming_window(session, 2147483647);
		session_set_outgoing_window(session, 65536);

		AMQP_VALUE source = messaging_create_source("ingress");
		AMQP_VALUE target = messaging_create_target("amqps://" EH_HOST "/" EH_NAME);
		link = link_create(session, "sender-link", role_sender, source, target);
		link_set_snd_settle_mode(link, sender_settle_mode_unsettled);
		(void)link_set_max_message_size(link, 65536);

		amqpvalue_destroy(source);
		amqpvalue_destroy(target);

		message = message_create();
		unsigned char hello[] = { 'H', 'e', 'l', 'l', 'o' };
		BINARY_DATA binary_data;
        binary_data.bytes = hello;
        binary_data.length = sizeof(hello);
		message_add_body_amqp_data(message, binary_data);

		/* create a message sender */
		message_sender = messagesender_create(link, NULL, NULL);
		if (messagesender_open(message_sender) == 0)
		{
			uint32_t i;

#if _WIN32
			unsigned long startTime = (unsigned long)GetTickCount64();
#endif

			for (i = 0; i < msg_count; i++)
			{
				(void)messagesender_send(message_sender, message, on_message_send_complete, message);
			}

			message_destroy(message);

			while (true)
			{
				size_t current_memory_used;
				size_t maximum_memory_used;
				connection_dowork(connection);

				current_memory_used = amqpalloc_get_current_memory_used();
				maximum_memory_used = amqpalloc_get_maximum_memory_used();

				if (current_memory_used != last_memory_used)
				{
					(void)printf("Current memory usage:%lu (max:%lu)\r\n", (unsigned long)current_memory_used, (unsigned long)maximum_memory_used);
					last_memory_used = current_memory_used;
				}

				if (sent_messages == msg_count)
				{
					break;
				}
			}

#if _WIN32
			unsigned long endTime = (unsigned long)GetTickCount64();

			(void)printf("Send %zu messages in %lu ms: %.02f msgs/sec\r\n", msg_count, (endTime - startTime), (float)msg_count / ((float)(endTime - startTime) / 1000));
#endif
		}

		messagesender_destroy(message_sender);
		link_destroy(link);
		session_destroy(session);
		connection_destroy(connection);
		xio_destroy(sasl_io);
		xio_destroy(tls_io);
		saslmechanism_destroy(sasl_mechanism_handle);
		platform_deinit();

		(void)printf("Max memory usage:%lu\r\n", (unsigned long)amqpalloc_get_maximum_memory_used());
		(void)printf("Current memory usage:%lu\r\n", (unsigned long)amqpalloc_get_current_memory_used());

		result = 0;
	}

#ifdef _CRTDBG_MAP_ALLOC
	_CrtDumpMemoryLeaks();
#endif

	return result;
}
Beispiel #17
0
int main(int argc, char** argv)
{
	int result;
	XIO_HANDLE sasl_io = NULL;
	CONNECTION_HANDLE connection = NULL;
	SESSION_HANDLE session = NULL;
	LINK_HANDLE link = NULL;
	MESSAGE_RECEIVER_HANDLE message_receiver = NULL;

	amqpalloc_set_memory_tracing_enabled(true);

	if (platform_init() != 0)
	{
		result = -1;
	}
	else
	{
		size_t last_memory_used = 0;

		/* create SASL plain handler */
		SASL_PLAIN_CONFIG sasl_plain_config = { EH_KEY_NAME, EH_KEY, NULL };
		SASL_MECHANISM_HANDLE sasl_mechanism_handle = saslmechanism_create(saslplain_get_interface(), &sasl_plain_config);
		XIO_HANDLE tls_io;

		/* create the TLS IO */
        TLSIO_CONFIG tls_io_config = { EH_HOST, 5671 };
		const IO_INTERFACE_DESCRIPTION* tlsio_interface = platform_get_default_tlsio();
		tls_io = xio_create(tlsio_interface, &tls_io_config, NULL);

		/* create the SASL client IO using the TLS IO */
		SASLCLIENTIO_CONFIG sasl_io_config = { tls_io, sasl_mechanism_handle };
		sasl_io = xio_create(saslclientio_get_interface_description(), &sasl_io_config, NULL);

		/* create the connection, session and link */
		connection = connection_create(sasl_io, EH_HOST, "whatever", NULL, NULL);
		session = session_create(connection, NULL, NULL);

		/* set incoming window to 100 for the session */
		session_set_incoming_window(session, 100);
		AMQP_VALUE source = messaging_create_source("amqps://" EH_HOST "/ingress/ConsumerGroups/$Default/Partitions/0");
		AMQP_VALUE target = messaging_create_target("ingress-rx");
		link = link_create(session, "receiver-link", role_receiver, source, target);
		link_set_rcv_settle_mode(link, receiver_settle_mode_first);
		amqpvalue_destroy(source);
		amqpvalue_destroy(target);

		/* create a message receiver */
		message_receiver = messagereceiver_create(link, NULL, NULL);
		if ((message_receiver == NULL) ||
			(messagereceiver_open(message_receiver, on_message_received, message_receiver) != 0))
		{
			result = -1;
		}
		else
		{
			while (true)
			{
				size_t current_memory_used;
				size_t maximum_memory_used;
				connection_dowork(connection);

				current_memory_used = amqpalloc_get_current_memory_used();
				maximum_memory_used = amqpalloc_get_maximum_memory_used();

				if (current_memory_used != last_memory_used)
				{
					printf("Current memory usage:%lu (max:%lu)\r\n", (unsigned long)current_memory_used, (unsigned long)maximum_memory_used);
					last_memory_used = current_memory_used;
				}
			}

			result = 0;
		}

		messagereceiver_destroy(message_receiver);
		link_destroy(link);
		session_destroy(session);
		connection_destroy(connection);
		platform_deinit();

		printf("Max memory usage:%lu\r\n", (unsigned long)amqpalloc_get_maximum_memory_used());
		printf("Current memory usage:%lu\r\n", (unsigned long)amqpalloc_get_current_memory_used());

#ifdef _CRTDBG_MAP_ALLOC
		_CrtDumpMemoryLeaks();
#endif
	}

	return result;
}
Beispiel #18
0
static int
process_db_write(dlmgmt_db_req_t *req, FILE *fp, FILE *nfp)
{
	boolean_t		done = B_FALSE;
	int			err = 0;
	dlmgmt_link_t		*linkp, *link_in_file, link;
	char			buf[MAXLINELEN];

	if (req->ls_op == DLMGMT_DB_OP_WRITE) {
		/*
		 * find the link in the avl tree with the given linkid.
		 */
		link.ll_linkid = req->ls_linkid;
		linkp = avl_find(&dlmgmt_id_avl, &link, NULL);
		if (linkp == NULL || (linkp->ll_flags & req->ls_flags) == 0) {
			/*
			 * This link has already been changed. This could
			 * happen if the request is pending because of
			 * read-only file-system. If so, we are done.
			 */
			return (0);
		}
	}

	while (err == 0 && fgets(buf, sizeof (buf), fp) != NULL &&
	    process_link_line(buf, &link_in_file)) {
		if (link_in_file == NULL || done) {
			/*
			 * this is a comment line, write it out.
			 */
			if (fputs(buf, nfp) == EOF)
				err = errno;
			continue;
		}

		switch (req->ls_op) {
		case DLMGMT_DB_OP_WRITE:
			/*
			 * For write operations, if the linkid of the link
			 * read from the file does not match the id of what
			 * req->ll_linkid points to, write out the buffer.
			 * Otherwise, generate a new line. If we get to the
			 * end and have not seen what req->ll_linkid points
			 * to, write it out then.
			 */
			if (linkp == NULL ||
			    linkp->ll_linkid != link_in_file->ll_linkid) {
				if (fputs(buf, nfp) == EOF)
					err = errno;
			} else {
				generate_link_line(linkp,
				    req->ls_flags == DLMGMT_PERSIST, buf);
				if (fputs(buf, nfp) == EOF)
					err = errno;
				done = B_TRUE;
			}
			break;
		case DLMGMT_DB_OP_DELETE:
			/*
			 * Delete is simple.  If buf does not represent the
			 * link we're deleting, write it out.
			 */
			if (req->ls_linkid != link_in_file->ll_linkid) {
				if (fputs(buf, nfp) == EOF)
					err = errno;
			} else {
				done = B_TRUE;
			}
			break;
		case DLMGMT_DB_OP_READ:
		default:
			err = EINVAL;
			break;
		}
		link_destroy(link_in_file);
	}

	/*
	 * If we get to the end of the file and have not seen what
	 * req->ll_linkid points to, write it out then.
	 */
	if (req->ls_op == DLMGMT_DB_OP_WRITE && !done) {
		generate_link_line(linkp, req->ls_flags == DLMGMT_PERSIST, buf);
		done = B_TRUE;
		if (fputs(buf, nfp) == EOF)
			err = errno;
	}

	if (!done)
		err = ENOENT;

	return (err);
}
AMQP_MANAGEMENT_HANDLE amqpmanagement_create(SESSION_HANDLE session, const char* management_node, ON_AMQP_MANAGEMENT_STATE_CHANGED on_amqp_management_state_changed, void* callback_context)
{
	AMQP_MANAGEMENT_INSTANCE* result;

	if (session == NULL)
	{
		result = NULL;
	}
	else
	{
		result = (AMQP_MANAGEMENT_INSTANCE*)amqpalloc_malloc(sizeof(AMQP_MANAGEMENT_INSTANCE));
		if (result != NULL)
		{
			result->session = session;
			result->sender_connected = 0;
			result->receiver_connected = 0;
			result->operation_message_count = 0;
			result->operation_messages = NULL;
			result->on_amqp_management_state_changed = on_amqp_management_state_changed;
			result->callback_context = callback_context;

			AMQP_VALUE source = messaging_create_source(management_node);
			if (source == NULL)
			{
				amqpalloc_free(result);
				result = NULL;
			}
			else
			{
				AMQP_VALUE target = messaging_create_target(management_node);
				if (target == NULL)
				{
					amqpalloc_free(result);
					result = NULL;
				}
				else
				{
					static const char* sender_suffix = "-sender";

					char* sender_link_name = (char*)amqpalloc_malloc(strlen(management_node) + strlen(sender_suffix) + 1);
					if (sender_link_name == NULL)
					{
						result = NULL;
					}
					else
					{
						static const char* receiver_suffix = "-receiver";

						(void)strcpy(sender_link_name, management_node);
						(void)strcat(sender_link_name, sender_suffix);

						char* receiver_link_name = (char*)amqpalloc_malloc(strlen(management_node) + strlen(receiver_suffix) + 1);
						if (receiver_link_name == NULL)
						{
							result = NULL;
						}
						else
						{
							(void)strcpy(receiver_link_name, management_node);
							(void)strcat(receiver_link_name, receiver_suffix);

							result->sender_link = link_create(session, "cbs-sender", role_sender, source, target);
							if (result->sender_link == NULL)
							{
								amqpalloc_free(result);
								result = NULL;
							}
							else
							{
								result->receiver_link = link_create(session, "cbs-receiver", role_receiver, source, target);
								if (result->receiver_link == NULL)
								{
									link_destroy(result->sender_link);
									amqpalloc_free(result);
									result = NULL;
								}
								else
								{
									if ((link_set_max_message_size(result->sender_link, 65535) != 0) ||
										(link_set_max_message_size(result->receiver_link, 65535) != 0))
									{
										link_destroy(result->sender_link);
										link_destroy(result->receiver_link);
										amqpalloc_free(result);
										result = NULL;
									}
									else
									{
										result->message_sender = messagesender_create(result->sender_link, on_message_sender_state_changed, result, NULL);
										if (result->message_sender == NULL)
										{
											link_destroy(result->sender_link);
											link_destroy(result->receiver_link);
											amqpalloc_free(result);
											result = NULL;
										}
										else
										{
											result->message_receiver = messagereceiver_create(result->receiver_link, on_message_receiver_state_changed, result);
											if (result->message_receiver == NULL)
											{
												messagesender_destroy(result->message_sender);
												link_destroy(result->sender_link);
												link_destroy(result->receiver_link);
												amqpalloc_free(result);
												result = NULL;
											}
											else
											{
												result->next_message_id = 0;
											}
										}
									}
								}
							}

							amqpalloc_free(receiver_link_name);
						}

						amqpalloc_free(sender_link_name);
					}

					amqpvalue_destroy(target);
				}

				amqpvalue_destroy(source);
			}
		}
	}

	return result;
}
Beispiel #20
0
int main(int argc, char** argv)
{
	int result;

    (void)argc, argv;
    amqpalloc_set_memory_tracing_enabled(true);

	if (platform_init() != 0)
	{
		result = -1;
	}
	else
	{
		CONNECTION_HANDLE connection;
		SESSION_HANDLE session;
		LINK_HANDLE link;
		MESSAGE_SENDER_HANDLE message_sender;
		MESSAGE_HANDLE message;

		size_t last_memory_used = 0;

		/* create socket IO */
		XIO_HANDLE socket_io;

		SOCKETIO_CONFIG socketio_config = { "localhost", 5672, NULL };
		socket_io = xio_create(socketio_get_interface_description(), &socketio_config);

		/* create the connection, session and link */
		connection = connection_create(socket_io, "localhost", "some", NULL, NULL);
		session = session_create(connection, NULL, NULL);
		session_set_incoming_window(session, 2147483647);
		session_set_outgoing_window(session, 65536);

		AMQP_VALUE source = messaging_create_source("ingress");
		AMQP_VALUE target = messaging_create_target("localhost/ingress");
		link = link_create(session, "sender-link", role_sender, source, target);
		link_set_snd_settle_mode(link, sender_settle_mode_settled);
		(void)link_set_max_message_size(link, 65536);

		amqpvalue_destroy(source);
		amqpvalue_destroy(target);

		message = message_create();
		unsigned char hello[] = { 'H', 'e', 'l', 'l', 'o' };
		BINARY_DATA binary_data;
        binary_data.bytes = hello;
        binary_data.length = sizeof(hello);
		message_add_body_amqp_data(message, binary_data);

		/* create a message sender */
		message_sender = messagesender_create(link, NULL, NULL);
		if (messagesender_open(message_sender) == 0)
		{
			uint32_t i;

#if _WIN32
			unsigned long startTime = (unsigned long)GetTickCount64();
#endif

			for (i = 0; i < msg_count; i++)
			{
				(void)messagesender_send(message_sender, message, on_message_send_complete, message);
			}

			message_destroy(message);

			while (true)
			{
				size_t current_memory_used;
				size_t maximum_memory_used;
				connection_dowork(connection);

				current_memory_used = amqpalloc_get_current_memory_used();
				maximum_memory_used = amqpalloc_get_maximum_memory_used();

				if (current_memory_used != last_memory_used)
				{
					(void)printf("Current memory usage:%lu (max:%lu)\r\n", (unsigned long)current_memory_used, (unsigned long)maximum_memory_used);
					last_memory_used = current_memory_used;
				}

				if (sent_messages == msg_count)
				{
					break;
				}
			}

#if _WIN32
			unsigned long endTime = (unsigned long)GetTickCount64();

			(void)printf("Send %zu messages in %lu ms: %.02f msgs/sec\r\n", msg_count, (endTime - startTime), (float)msg_count / ((float)(endTime - startTime) / 1000));
#endif
		}

		messagesender_destroy(message_sender);
		link_destroy(link);
		session_destroy(session);
		connection_destroy(connection);
		xio_destroy(socket_io);
		platform_deinit();

		(void)printf("Max memory usage:%lu\r\n", (unsigned long)amqpalloc_get_maximum_memory_used());
		(void)printf("Current memory usage:%lu\r\n", (unsigned long)amqpalloc_get_current_memory_used());

		result = 0;
	}

#ifdef _CRTDBG_MAP_ALLOC
	_CrtDumpMemoryLeaks();
#endif

	return result;
}
Beispiel #21
0
void
links_delete (Link   *link)
{
  links = g_slist_remove (links, link);
  link_destroy (link);
}
Beispiel #22
0
int main(int argc, char** argv)
{
    int result;

    (void)argc;
    (void)argv;

    if (platform_init() != 0)
    {
        result = -1;
    }
    else
    {
        XIO_HANDLE sasl_io;
        CONNECTION_HANDLE connection;
        SESSION_HANDLE session;
        LINK_HANDLE link;
        MESSAGE_SENDER_HANDLE message_sender;
        MESSAGE_HANDLE message;

        size_t last_memory_used = 0;

        /* create SASL PLAIN handler */
        SASL_MECHANISM_HANDLE sasl_mechanism_handle = saslmechanism_create(saslmssbcbs_get_interface(), NULL);
        XIO_HANDLE tls_io;
        STRING_HANDLE sas_key_name;
        STRING_HANDLE sas_key_value;
        STRING_HANDLE resource_uri;
        STRING_HANDLE encoded_resource_uri;
        STRING_HANDLE sas_token;
        BUFFER_HANDLE buffer;
        TLSIO_CONFIG tls_io_config = { EH_HOST, 5671 };
        const IO_INTERFACE_DESCRIPTION* tlsio_interface;
        SASLCLIENTIO_CONFIG sasl_io_config;
        time_t currentTime;
        size_t expiry_time;
        CBS_HANDLE cbs;
        AMQP_VALUE source;
        AMQP_VALUE target;
        unsigned char hello[] = { 'H', 'e', 'l', 'l', 'o' };
        BINARY_DATA binary_data;

        gballoc_init();

        /* create the TLS IO */
        tlsio_interface = platform_get_default_tlsio();
        tls_io = xio_create(tlsio_interface, &tls_io_config);

        /* create the SASL client IO using the TLS IO */
        sasl_io_config.underlying_io = tls_io;
        sasl_io_config.sasl_mechanism = sasl_mechanism_handle;
        sasl_io = xio_create(saslclientio_get_interface_description(), &sasl_io_config);

        /* create the connection, session and link */
        connection = connection_create(sasl_io, EH_HOST, "some", NULL, NULL);
        session = session_create(connection, NULL, NULL);
        session_set_incoming_window(session, 2147483647);
        session_set_outgoing_window(session, 65536);

        /* Construct a SAS token */
        sas_key_name = STRING_construct(EH_KEY_NAME);

        /* unfortunately SASToken wants an encoded key - this should be fixed at a later time */
        buffer = BUFFER_create((unsigned char*)EH_KEY, strlen(EH_KEY));
        sas_key_value = Base64_Encoder(buffer);
        BUFFER_delete(buffer);
        resource_uri = STRING_construct("sb://" EH_HOST "/" EH_NAME "/publishers/" EH_PUBLISHER);
        encoded_resource_uri = URL_EncodeString(STRING_c_str(resource_uri));

        /* Make a token that expires in one hour */
        currentTime = time(NULL);
        expiry_time = (size_t)(difftime(currentTime, 0) + 3600);

        sas_token = SASToken_Create(sas_key_value, encoded_resource_uri, sas_key_name, expiry_time);

        cbs = cbs_create(session);
        if (cbs_open_async(cbs, on_cbs_open_complete, cbs, on_cbs_error, cbs) == 0)
        {
            (void)cbs_put_token_async(cbs, "servicebus.windows.net:sastoken", "sb://" EH_HOST "/" EH_NAME "/publishers/" EH_PUBLISHER, STRING_c_str(sas_token), on_cbs_put_token_complete, cbs);

            while (!auth)
            {
                size_t current_memory_used;
                size_t maximum_memory_used;
                connection_dowork(connection);

                current_memory_used = gballoc_getCurrentMemoryUsed();
                maximum_memory_used = gballoc_getMaximumMemoryUsed();

                if (current_memory_used != last_memory_used)
                {
                    (void)printf("Current memory usage:%lu (max:%lu)\r\n", (unsigned long)current_memory_used, (unsigned long)maximum_memory_used);
                    last_memory_used = current_memory_used;
                }
            }
        }

        STRING_delete(sas_token);
        STRING_delete(sas_key_name);
        STRING_delete(sas_key_value);
        STRING_delete(resource_uri);
        STRING_delete(encoded_resource_uri);

        source = messaging_create_source("ingress");
        target = messaging_create_target("amqps://" EH_HOST "/" EH_NAME);
        link = link_create(session, "sender-link", role_sender, source, target);
        link_set_snd_settle_mode(link, sender_settle_mode_settled);
        (void)link_set_max_message_size(link, 65536);

        amqpvalue_destroy(source);
        amqpvalue_destroy(target);

        message = message_create();

        binary_data.bytes = hello;
        binary_data.length = sizeof(hello);
        message_add_body_amqp_data(message, binary_data);

        /* create a message sender */
        message_sender = messagesender_create(link, NULL, NULL);
        if (messagesender_open(message_sender) == 0)
        {
            uint32_t i;
            bool keep_running = true;
            tickcounter_ms_t start_time;
            TICK_COUNTER_HANDLE tick_counter = tickcounter_create();

            if (tickcounter_get_current_ms(tick_counter, &start_time) != 0)
            {
                (void)printf("Error getting start time\r\n");
            }
            else
            {
                for (i = 0; i < msg_count; i++)
                {
                    (void)messagesender_send(message_sender, message, on_message_send_complete, message);
                }

                message_destroy(message);

                while (keep_running)
                {
                    size_t current_memory_used;
                    size_t maximum_memory_used;
                    connection_dowork(connection);

                    current_memory_used = gballoc_getCurrentMemoryUsed();
                    maximum_memory_used = gballoc_getMaximumMemoryUsed();

                    if (current_memory_used != last_memory_used)
                    {
                        (void)printf("Current memory usage:%lu (max:%lu)\r\n", (unsigned long)current_memory_used, (unsigned long)maximum_memory_used);
                        last_memory_used = current_memory_used;
                    }

                    if (sent_messages == msg_count)
                    {
                        break;
                    }
                }

                {
                    tickcounter_ms_t end_time;
                    if (tickcounter_get_current_ms(tick_counter, &end_time) != 0)
                    {
                        (void)printf("Error getting end time\r\n");
                    }
                    else
                    {
                        (void)printf("Send %u messages in %lu ms: %.02f msgs/sec\r\n", (unsigned int)msg_count, (unsigned long)(end_time - start_time), (float)msg_count / ((float)(end_time - start_time) / 1000));
                    }
                }
            }
        }

        messagesender_destroy(message_sender);
        link_destroy(link);
        session_destroy(session);
        connection_destroy(connection);
        xio_destroy(sasl_io);
        xio_destroy(tls_io);
        saslmechanism_destroy(sasl_mechanism_handle);
        platform_deinit();

        (void)printf("Max memory usage:%lu\r\n", (unsigned long)gballoc_getCurrentMemoryUsed());
        (void)printf("Current memory usage:%lu\r\n", (unsigned long)gballoc_getMaximumMemoryUsed());

        gballoc_deinit();

        result = 0;
    }

    return result;
}
Beispiel #23
0
static boolean_t
process_link_line(char *buf, dlmgmt_link_t **linkpp)
{
	dlmgmt_link_t		*linkp;
	int			i, len, llen;
	char			*str, *lasts;
	char			tmpbuf[MAXLINELEN];

	/*
	 * Use a copy of buf for parsing so that we can do whatever we want.
	 */
	(void) strlcpy(tmpbuf, buf, MAXLINELEN);

	/*
	 * Skip leading spaces, blank lines, and comments.
	 */
	len = strlen(tmpbuf);
	for (i = 0; i < len; i++) {
		if (!isspace(tmpbuf[i]))
			break;
	}
	if (i == len || tmpbuf[i] == '#') {
		*linkpp = NULL;
		return (B_TRUE);
	}

	linkp = calloc(1, sizeof (dlmgmt_link_t));
	if (linkp == NULL)
		goto fail;

	str = tmpbuf + i;
	/*
	 * Find the link id and assign it to the link structure.
	 */
	if (strtok_r(str, " \n\t", &lasts) == NULL)
		goto fail;

	llen = strlen(str);
	linkp->ll_linkid = atoi(str);

	str += llen + 1;
	if (str >= tmpbuf + len)
		goto fail;

	/*
	 * Now find the list of link properties.
	 */
	if ((str = strtok_r(str, " \n\t", &lasts)) == NULL)
		goto fail;

	if (parse_linkprops(str, linkp) < 0)
		goto fail;

	*linkpp = linkp;
	return (B_TRUE);

fail:
	link_destroy(linkp);

	/*
	 * Delete corrupted line.
	 */
	buf[0] = '\0';
	return (B_FALSE);
}