[c5808b41] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Jiri Svoboda
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup tcp
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | /**
|
---|
| 34 | * @file
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #include <adt/prodcons.h>
|
---|
| 38 | #include <errno.h>
|
---|
| 39 | #include <io/log.h>
|
---|
| 40 | #include <stdlib.h>
|
---|
| 41 | #include <thread.h>
|
---|
| 42 | #include "rqueue.h"
|
---|
| 43 | #include "state.h"
|
---|
| 44 | #include "tcp_type.h"
|
---|
| 45 |
|
---|
| 46 | static prodcons_t rqueue;
|
---|
| 47 |
|
---|
| 48 | void tcp_rqueue_init(void)
|
---|
| 49 | {
|
---|
| 50 | prodcons_initialize(&rqueue);
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | /** Bounce segment directy into receive queue without constructing the PDU.
|
---|
| 54 | *
|
---|
| 55 | * This is for testing purposes only.
|
---|
| 56 | */
|
---|
| 57 | void tcp_rqueue_bounce_seg(tcp_sockpair_t *sp, tcp_segment_t *seg)
|
---|
| 58 | {
|
---|
| 59 | tcp_sockpair_t rident;
|
---|
| 60 |
|
---|
| 61 | log_msg(LVL_DEBUG, "tcp_rqueue_bounce_seg()");
|
---|
| 62 |
|
---|
| 63 | /* Reverse the identification */
|
---|
| 64 | rident.local = sp->foreign;
|
---|
| 65 | rident.foreign = sp->local;
|
---|
| 66 |
|
---|
| 67 | tcp_rqueue_insert_seg(&rident, seg);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | void tcp_rqueue_insert_seg(tcp_sockpair_t *sp, tcp_segment_t *seg)
|
---|
| 71 | {
|
---|
| 72 | tcp_rqueue_entry_t *rqe;
|
---|
| 73 | log_msg(LVL_DEBUG, "tcp_rqueue_insert_seg()");
|
---|
| 74 |
|
---|
| 75 | rqe = calloc(1, sizeof(tcp_rqueue_entry_t));
|
---|
| 76 | if (rqe == NULL) {
|
---|
| 77 | log_msg(LVL_ERROR, "Failed allocating RQE.");
|
---|
| 78 | return;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | rqe->sp = *sp;
|
---|
| 82 | rqe->seg = seg;
|
---|
| 83 |
|
---|
| 84 | prodcons_produce(&rqueue, &rqe->link);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | static void tcp_rqueue_thread(void *arg)
|
---|
| 88 | {
|
---|
| 89 | link_t *link;
|
---|
| 90 | tcp_rqueue_entry_t *rqe;
|
---|
| 91 |
|
---|
| 92 | log_msg(LVL_DEBUG, "tcp_rqueue_thread()");
|
---|
| 93 |
|
---|
| 94 | while (true) {
|
---|
| 95 | link = prodcons_consume(&rqueue);
|
---|
| 96 | rqe = list_get_instance(link, tcp_rqueue_entry_t, link);
|
---|
| 97 |
|
---|
| 98 | tcp_as_segment_arrived(&rqe->sp, rqe->seg);
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | void tcp_rqueue_thread_start(void)
|
---|
| 103 | {
|
---|
| 104 | thread_id_t tid;
|
---|
| 105 | int rc;
|
---|
| 106 |
|
---|
| 107 | log_msg(LVL_DEBUG, "tcp_rqueue_thread_start()");
|
---|
| 108 |
|
---|
| 109 | rc = thread_create(tcp_rqueue_thread, NULL, "rqueue", &tid);
|
---|
| 110 | if (rc != EOK) {
|
---|
| 111 | log_msg(LVL_ERROR, "Failde creating rqueue thread.");
|
---|
| 112 | return;
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | /**
|
---|
| 117 | * @}
|
---|
| 118 | */
|
---|