Index: uspace/srv/net/tcp/Makefile
===================================================================
--- uspace/srv/net/tcp/Makefile	(revision 42f61f01d63ea6e84027b6626fed850d1cd20d9e)
+++ uspace/srv/net/tcp/Makefile	(revision d14840df52c3a32ad14b49726c96b06479dbfa52)
@@ -60,4 +60,5 @@
 	test/main.c \
 	test/pdu.c \
+	test/rqueue.c \
 	test/segment.c \
 	test/seq_no.c
Index: uspace/srv/net/tcp/rqueue.c
===================================================================
--- uspace/srv/net/tcp/rqueue.c	(revision 42f61f01d63ea6e84027b6626fed850d1cd20d9e)
+++ uspace/srv/net/tcp/rqueue.c	(revision d14840df52c3a32ad14b49726c96b06479dbfa52)
@@ -38,6 +38,8 @@
 #include <errno.h>
 #include <io/log.h>
+#include <stdbool.h>
 #include <stdlib.h>
 #include <fibril.h>
+#include <fibril_synch.h>
 #include "conn.h"
 #include "pdu.h"
@@ -56,9 +58,31 @@
 
 static prodcons_t rqueue;
+static bool fibril_active;
+static fibril_mutex_t lock;
+static fibril_condvar_t cv;
+static tcp_rqueue_cb_t *rqueue_cb;
 
 /** Initialize segment receive queue. */
-void tcp_rqueue_init(void)
+void tcp_rqueue_init(tcp_rqueue_cb_t *rcb)
 {
 	prodcons_initialize(&rqueue);
+	fibril_mutex_initialize(&lock);
+	fibril_condvar_initialize(&cv);
+	fibril_active = false;
+	rqueue_cb = rcb;
+}
+
+/** Finalize segment receive queue. */
+void tcp_rqueue_fini(void)
+{
+	inet_ep2_t epp;
+
+	inet_ep2_init(&epp);
+	tcp_rqueue_insert_seg(&epp, NULL);
+
+	fibril_mutex_lock(&lock);
+	while (fibril_active)
+		fibril_condvar_wait(&cv, &lock);
+	fibril_mutex_unlock(&lock);
 }
 
@@ -112,7 +136,9 @@
 {
 	tcp_rqueue_entry_t *rqe;
-	log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_rqueue_insert_seg()");
-
-	tcp_segment_dump(seg);
+
+	log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_rqueue_insert_seg()");
+
+	if (seg != NULL)
+		tcp_segment_dump(seg);
 
 	rqe = calloc(1, sizeof(tcp_rqueue_entry_t));
@@ -140,9 +166,21 @@
 		rqe = list_get_instance(link, tcp_rqueue_entry_t, link);
 
-		tcp_as_segment_arrived(&rqe->epp, rqe->seg);
+		if (rqe->seg == NULL) {
+			free(rqe);
+			break;
+		}
+
+		rqueue_cb->seg_received(&rqe->epp, rqe->seg);
 		free(rqe);
 	}
 
-	/* Not reached */
+	log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_rqueue_fibril() exiting");
+
+	/* Finished */
+	fibril_mutex_lock(&lock);
+	fibril_active = false;
+	fibril_mutex_unlock(&lock);
+	fibril_condvar_broadcast(&cv);
+
 	return 0;
 }
@@ -162,4 +200,5 @@
 
 	fibril_add_ready(fid);
+	fibril_active = true;
 }
 
Index: uspace/srv/net/tcp/rqueue.h
===================================================================
--- uspace/srv/net/tcp/rqueue.h	(revision 42f61f01d63ea6e84027b6626fed850d1cd20d9e)
+++ uspace/srv/net/tcp/rqueue.h	(revision d14840df52c3a32ad14b49726c96b06479dbfa52)
@@ -39,9 +39,9 @@
 #include "tcp_type.h"
 
-extern void tcp_rqueue_init(void);
+extern void tcp_rqueue_init(tcp_rqueue_cb_t *);
+extern void tcp_rqueue_fibril_start(void);
+extern void tcp_rqueue_fini(void);
 extern void tcp_rqueue_bounce_seg(inet_ep2_t *, tcp_segment_t *);
 extern void tcp_rqueue_insert_seg(inet_ep2_t *, tcp_segment_t *);
-extern void tcp_rqueue_handler(void *);
-extern void tcp_rqueue_fibril_start(void);
 
 
Index: uspace/srv/net/tcp/tcp.c
===================================================================
--- uspace/srv/net/tcp/tcp.c	(revision 42f61f01d63ea6e84027b6626fed850d1cd20d9e)
+++ uspace/srv/net/tcp/tcp.c	(revision d14840df52c3a32ad14b49726c96b06479dbfa52)
@@ -47,6 +47,11 @@
 #include "service.h"
 #include "test.h"
+#include "ucall.h"
 
 #define NAME       "tcp"
+
+static tcp_rqueue_cb_t tcp_rqueue_cb = {
+	.seg_received = tcp_as_segment_arrived
+};
 
 static int tcp_init(void)
@@ -63,5 +68,5 @@
 	}
 
-	tcp_rqueue_init();
+	tcp_rqueue_init(&tcp_rqueue_cb);
 	tcp_rqueue_fibril_start();
 
Index: uspace/srv/net/tcp/tcp_type.h
===================================================================
--- uspace/srv/net/tcp/tcp_type.h	(revision 42f61f01d63ea6e84027b6626fed850d1cd20d9e)
+++ uspace/srv/net/tcp/tcp_type.h	(revision d14840df52c3a32ad14b49726c96b06479dbfa52)
@@ -280,4 +280,10 @@
 } tcp_rqueue_entry_t;
 
+/** Receive queue callbacks */
+typedef struct {
+	/** Segment received */
+	void (*seg_received)(inet_ep2_t *, tcp_segment_t *);
+} tcp_rqueue_cb_t;
+
 /** NCSim queue entry */
 typedef struct {
Index: uspace/srv/net/tcp/test/main.c
===================================================================
--- uspace/srv/net/tcp/test/main.c	(revision 42f61f01d63ea6e84027b6626fed850d1cd20d9e)
+++ uspace/srv/net/tcp/test/main.c	(revision d14840df52c3a32ad14b49726c96b06479dbfa52)
@@ -59,4 +59,5 @@
 PCUT_IMPORT(iqueue);
 PCUT_IMPORT(pdu);
+PCUT_IMPORT(rqueue);
 PCUT_IMPORT(segment);
 PCUT_IMPORT(seq_no);
Index: uspace/srv/net/tcp/test/rqueue.c
===================================================================
--- uspace/srv/net/tcp/test/rqueue.c	(revision d14840df52c3a32ad14b49726c96b06479dbfa52)
+++ uspace/srv/net/tcp/test/rqueue.c	(revision d14840df52c3a32ad14b49726c96b06479dbfa52)
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2017 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <adt/prodcons.h>
+#include <inet/endpoint.h>
+#include <io/log.h>
+#include <pcut/pcut.h>
+
+#include "../rqueue.h"
+#include "../segment.h"
+
+PCUT_INIT
+
+PCUT_TEST_SUITE(rqueue);
+
+enum {
+	test_seg_max = 10
+};
+
+static void test_seg_received(inet_ep2_t *, tcp_segment_t *);
+
+static tcp_rqueue_cb_t rcb = {
+	.seg_received = test_seg_received
+};
+
+static int seg_cnt;
+static tcp_segment_t *recv_seg[test_seg_max];
+
+static void test_seg_received(inet_ep2_t *epp, tcp_segment_t *seg)
+{
+	recv_seg[seg_cnt++] = seg;
+}
+
+PCUT_TEST_BEFORE
+{
+	int rc;
+
+	/* We will be calling functions that perform logging */
+	rc = log_init("test-tcp");
+	PCUT_ASSERT_INT_EQUALS(EOK, rc);
+}
+
+/** Test empty queue */
+PCUT_TEST(init_fini)
+{
+	tcp_rqueue_init(&rcb);
+	tcp_rqueue_fibril_start();
+	tcp_rqueue_fini();
+}
+
+/** Test one segment */
+PCUT_TEST(one_segment)
+{
+	tcp_segment_t *seg;
+	inet_ep2_t epp;
+
+	tcp_rqueue_init(&rcb);
+	seg_cnt = 0;
+
+	seg = tcp_segment_make_ctrl(CTL_SYN);
+	PCUT_ASSERT_NOT_NULL(seg);
+	inet_ep2_init(&epp);
+
+	tcp_rqueue_insert_seg(&epp, seg);
+	tcp_rqueue_fibril_start();
+	tcp_rqueue_fini();
+
+	PCUT_ASSERT_INT_EQUALS(1, seg_cnt);
+	PCUT_ASSERT_EQUALS(seg, recv_seg[0]);
+
+	tcp_segment_delete(seg);
+}
+
+/** Test multiple segments */
+PCUT_TEST(multiple_segments)
+{
+	tcp_segment_t *seg[test_seg_max];
+	inet_ep2_t epp;
+	int i;
+
+	tcp_rqueue_init(&rcb);
+	seg_cnt = 0;
+
+    	inet_ep2_init(&epp);
+
+	tcp_rqueue_fibril_start();
+
+	for (i = 0; i < test_seg_max; i++) {
+		seg[i] = tcp_segment_make_ctrl(CTL_ACK);
+		PCUT_ASSERT_NOT_NULL(seg[i]);
+		tcp_rqueue_insert_seg(&epp, seg[i]);
+	}
+
+	tcp_rqueue_fini();
+
+	PCUT_ASSERT_INT_EQUALS(test_seg_max, seg_cnt);
+	for (i = 0; i < test_seg_max; i++) {
+		PCUT_ASSERT_EQUALS(seg[i], recv_seg[i]);
+		tcp_segment_delete(seg[i]);
+	}
+
+}
+
+PCUT_EXPORT(rqueue);
