source: mainline/uspace/srv/net/tl/tcp/iqueue.c@ 32105348

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 32105348 was 032bbe7, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Document functions and files.

  • Property mode set to 100644
File size: 3.9 KB
Line 
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 Connection incoming segments queue
35 *
36 * Segments are sorted in order of their sequence number.
37 */
38
39#include <adt/list.h>
40#include <errno.h>
41#include <io/log.h>
42#include <stdlib.h>
43#include "iqueue.h"
44#include "segment.h"
45#include "seq_no.h"
46#include "tcp_type.h"
47
48/** Initialize incoming segments queue.
49 *
50 * @param iqueue Incoming queue
51 * @param conn Connection the queue is associated with
52 */
53void tcp_iqueue_init(tcp_iqueue_t *iqueue, tcp_conn_t *conn)
54{
55 list_initialize(&iqueue->list);
56 iqueue->conn = conn;
57}
58
59/** Insert segment into incoming queue.
60 *
61 * @param iqueue Incoming queue
62 * @param seg Segment
63 */
64void tcp_iqueue_insert_seg(tcp_iqueue_t *iqueue, tcp_segment_t *seg)
65{
66 tcp_iqueue_entry_t *iqe;
67 log_msg(LVL_DEBUG, "tcp_iqueue_insert_seg()");
68
69 iqe = calloc(1, sizeof(tcp_iqueue_entry_t));
70 if (iqe == NULL) {
71 log_msg(LVL_ERROR, "Failed allocating IQE.");
72 return;
73 }
74
75 iqe->seg = seg;
76
77 /* XXX Sort by sequence number */
78 list_append(&iqe->link, &iqueue->list);
79}
80
81/** Get next ready segment from incoming queue.
82 *
83 * Return the segment with the earliest sequence number if it is ready.
84 * A segment is ready if its SEG.SEQ is earlier or equal to RCV.NXT.
85 *
86 * @param iqueue Incoming queue
87 * @param seg Place to store pointer to segment
88 * @return EOK on success, ENOENT if no segment is ready
89 */
90int tcp_iqueue_get_ready_seg(tcp_iqueue_t *iqueue, tcp_segment_t **seg)
91{
92 tcp_iqueue_entry_t *iqe;
93 link_t *link;
94
95 log_msg(LVL_DEBUG, "tcp_get_ready_seg()");
96
97 link = list_first(&iqueue->list);
98 if (link == NULL) {
99 log_msg(LVL_DEBUG, "iqueue is empty");
100 return ENOENT;
101 }
102
103 iqe = list_get_instance(link, tcp_iqueue_entry_t, link);
104
105 while (!seq_no_segment_acceptable(iqueue->conn, iqe->seg)) {
106 log_msg(LVL_DEBUG, "Skipping unacceptable segment");
107
108 list_remove(&iqe->link);
109 tcp_segment_delete(iqe->seg);
110
111 link = list_first(&iqueue->list);
112 if (link == NULL) {
113 log_msg(LVL_DEBUG, "iqueue is empty");
114 return ENOENT;
115 }
116
117 iqe = list_get_instance(link, tcp_iqueue_entry_t, link);
118 }
119
120 /* Do not return segments that are not ready for processing */
121 if (!seq_no_segment_ready(iqueue->conn, iqe->seg)) {
122 log_msg(LVL_DEBUG, "Next segment not ready: SEG.SEQ=%u, "
123 "RCV.NXT=%u, SEG.LEN=%u", iqe->seg->seq,
124 iqueue->conn->rcv_nxt, iqe->seg->len);
125 return ENOENT;
126 }
127
128 log_msg(LVL_DEBUG, "Returning ready segment %p", iqe->seg);
129 list_remove(&iqe->link);
130 *seg = iqe->seg;
131
132 return EOK;
133}
134
135/**
136 * @}
137 */
Note: See TracBrowser for help on using the repository browser.