Ejemplo n.º 1
0
static void test_wqueue_limit(void)
{
	struct msgb *msg;
	struct osmo_wqueue wqueue;
	int rc;

	osmo_wqueue_init(&wqueue, 0);
	OSMO_ASSERT(wqueue.max_length == 0);
	OSMO_ASSERT(wqueue.current_length == 0);
	OSMO_ASSERT(wqueue.read_cb == NULL);
	OSMO_ASSERT(wqueue.write_cb == NULL);
	OSMO_ASSERT(wqueue.except_cb == NULL);

	/* try to add and fail */
	msg = msgb_alloc(4096, "msg1");
	rc = osmo_wqueue_enqueue(&wqueue, msg);
	OSMO_ASSERT(rc < 0);

	/* add one and fail on the second */
	wqueue.max_length = 1;
	rc = osmo_wqueue_enqueue(&wqueue, msg);
	OSMO_ASSERT(rc == 0);
	OSMO_ASSERT(wqueue.current_length == 1);
	msg = msgb_alloc(4096, "msg2");
	rc = osmo_wqueue_enqueue(&wqueue, msg);
	OSMO_ASSERT(rc < 0);

	/* add one more */
	wqueue.max_length = 2;
	rc = osmo_wqueue_enqueue(&wqueue, msg);
	OSMO_ASSERT(rc == 0);
	OSMO_ASSERT(wqueue.current_length == 2);

	/* release everything */
	osmo_wqueue_clear(&wqueue);
	OSMO_ASSERT(wqueue.current_length == 0);
	OSMO_ASSERT(wqueue.max_length == 2);

	/* Add two, fail on the third, free it and the queue */
	msg = msgb_alloc(4096, "msg3");
	rc = osmo_wqueue_enqueue(&wqueue, msg);
	OSMO_ASSERT(rc == 0);
	OSMO_ASSERT(wqueue.current_length == 1);
	msg = msgb_alloc(4096, "msg4");
	rc = osmo_wqueue_enqueue(&wqueue, msg);
	OSMO_ASSERT(rc == 0);
	OSMO_ASSERT(wqueue.current_length == 2);
	msg = msgb_alloc(4096, "msg5");
	rc = osmo_wqueue_enqueue(&wqueue, msg);
	OSMO_ASSERT(rc < 0);
	OSMO_ASSERT(wqueue.current_length == 2);
	msgb_free(msg);
	osmo_wqueue_clear(&wqueue);
}
Ejemplo n.º 2
0
void bsc_msc_lost(struct bsc_msc_connection *con)
{
	osmo_wqueue_clear(&con->write_queue);
	osmo_timer_del(&con->timeout_timer);
	osmo_timer_del(&con->reconnect_timer);

	if (con->write_queue.bfd.fd >= 0)
		osmo_fd_unregister(&con->write_queue.bfd);
	connection_loss(con);
}
Ejemplo n.º 3
0
static void bsc_nat_ussd_destroy(struct bsc_nat_ussd_con *con)
{
	if (con->nat->ussd_con == con) {
		bsc_close_ussd_connections(con->nat);
		con->nat->ussd_con = NULL;
	}

	close(con->queue.bfd.fd);
	osmo_fd_unregister(&con->queue.bfd);
	osmo_timer_del(&con->auth_timeout);
	osmo_wqueue_clear(&con->queue);
	talloc_free(con);
}
Ejemplo n.º 4
0
int meas_feed_cfg_set(const char *dst_host, uint16_t dst_port)
{
	int rc;
	int already_initialized = 0;

	if (g_mfs.wqueue.bfd.fd)
		already_initialized = 1;


	if (already_initialized &&
	    !strcmp(dst_host, g_mfs.dst_host) &&
	    dst_port == g_mfs.dst_port)
		return 0;

	if (!already_initialized) {
		osmo_wqueue_init(&g_mfs.wqueue, 10);
		g_mfs.wqueue.write_cb = feed_write_cb;
		g_mfs.wqueue.read_cb = feed_read_cb;
		osmo_signal_register_handler(SS_LCHAN, meas_feed_sig_cb, NULL);
	}

	if (already_initialized) {
		osmo_wqueue_clear(&g_mfs.wqueue);
		osmo_fd_unregister(&g_mfs.wqueue.bfd);
		close(g_mfs.wqueue.bfd.fd);
		/* don't set to zero, as that would mean 'not yet initialized' */
		g_mfs.wqueue.bfd.fd = -1;
	}
	rc = osmo_sock_init_ofd(&g_mfs.wqueue.bfd, AF_UNSPEC, SOCK_DGRAM,
				IPPROTO_UDP, dst_host, dst_port,
				OSMO_SOCK_F_CONNECT);
	if (rc < 0)
		return rc;

	g_mfs.wqueue.bfd.when &= ~BSC_FD_READ;

	if (g_mfs.dst_host)
		talloc_free(g_mfs.dst_host);
	g_mfs.dst_host = talloc_strdup(NULL, dst_host);
	g_mfs.dst_port = dst_port;

	return 0;
}