Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/tcp/rqueue.c

    r9520af7 r2f19103  
    3838#include <errno.h>
    3939#include <io/log.h>
    40 #include <stdbool.h>
    4140#include <stdlib.h>
    4241#include <fibril.h>
    43 #include <fibril_synch.h>
    4442#include "conn.h"
     43#include "pdu.h"
    4544#include "rqueue.h"
    4645#include "segment.h"
     
    4847#include "ucall.h"
    4948
     49/** Transcode bounced segments.
     50 *
     51 * If defined, segments bounced via the internal debugging loopback will
     52 * be encoded to a PDU and the decoded. Otherwise they will be bounced back
     53 * directly without passing the encoder-decoder.
     54 */
     55#define BOUNCE_TRANSCODE
     56
    5057static prodcons_t rqueue;
    51 static bool fibril_active;
    52 static fibril_mutex_t lock;
    53 static fibril_condvar_t cv;
    54 static tcp_rqueue_cb_t *rqueue_cb;
    5558
    5659/** Initialize segment receive queue. */
    57 void tcp_rqueue_init(tcp_rqueue_cb_t *rcb)
     60void tcp_rqueue_init(void)
    5861{
    5962        prodcons_initialize(&rqueue);
    60         fibril_mutex_initialize(&lock);
    61         fibril_condvar_initialize(&cv);
    62         fibril_active = false;
    63         rqueue_cb = rcb;
    6463}
    6564
    66 /** Finalize segment receive queue. */
    67 void tcp_rqueue_fini(void)
     65/** Bounce segment directy into receive queue without constructing the PDU.
     66 *
     67 * This is for testing purposes only.
     68 *
     69 * @param sp    Endpoint pair, oriented for transmission
     70 * @param seg   Segment
     71 */
     72void tcp_rqueue_bounce_seg(inet_ep2_t *epp, tcp_segment_t *seg)
    6873{
    69         inet_ep2_t epp;
     74        inet_ep2_t rident;
    7075
    71         inet_ep2_init(&epp);
    72         tcp_rqueue_insert_seg(&epp, NULL);
     76        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_rqueue_bounce_seg()");
    7377
    74         fibril_mutex_lock(&lock);
    75         while (fibril_active)
    76                 fibril_condvar_wait(&cv, &lock);
    77         fibril_mutex_unlock(&lock);
     78#ifdef BOUNCE_TRANSCODE
     79        tcp_pdu_t *pdu;
     80        tcp_segment_t *dseg;
     81
     82        if (tcp_pdu_encode(epp, seg, &pdu) != EOK) {
     83                log_msg(LOG_DEFAULT, LVL_WARN, "Not enough memory. Segment dropped.");
     84                return;
     85        }
     86
     87        if (tcp_pdu_decode(pdu, &rident, &dseg) != EOK) {
     88                log_msg(LOG_DEFAULT, LVL_WARN, "Not enough memory. Segment dropped.");
     89                return;
     90        }
     91
     92        tcp_pdu_delete(pdu);
     93
     94        /** Insert decoded segment into rqueue */
     95        tcp_rqueue_insert_seg(&rident, dseg);
     96        tcp_segment_delete(seg);
     97#else
     98        /* Reverse the identification */
     99        tcp_ep2_flipped(epp, &rident);
     100
     101        /* Insert segment back into rqueue */
     102        tcp_rqueue_insert_seg(&rident, seg);
     103#endif
    78104}
    79105
     
    81107 *
    82108 * @param epp   Endpoint pair, oriented for reception
    83  * @param seg   Segment (ownership transferred to rqueue)
     109 * @param seg   Segment
    84110 */
    85111void tcp_rqueue_insert_seg(inet_ep2_t *epp, tcp_segment_t *seg)
    86112{
    87113        tcp_rqueue_entry_t *rqe;
     114        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_rqueue_insert_seg()");
    88115
    89         log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_rqueue_insert_seg()");
    90 
    91         if (seg != NULL)
    92                 tcp_segment_dump(seg);
     116        tcp_segment_dump(seg);
    93117
    94118        rqe = calloc(1, sizeof(tcp_rqueue_entry_t));
     
    116140                rqe = list_get_instance(link, tcp_rqueue_entry_t, link);
    117141
    118                 if (rqe->seg == NULL) {
    119                         free(rqe);
    120                         break;
    121                 }
    122 
    123                 rqueue_cb->seg_received(&rqe->epp, rqe->seg);
     142                tcp_as_segment_arrived(&rqe->epp, rqe->seg);
    124143                free(rqe);
    125144        }
    126145
    127         log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_rqueue_fibril() exiting");
    128 
    129         /* Finished */
    130         fibril_mutex_lock(&lock);
    131         fibril_active = false;
    132         fibril_mutex_unlock(&lock);
    133         fibril_condvar_broadcast(&cv);
    134 
     146        /* Not reached */
    135147        return 0;
    136148}
     
    150162
    151163        fibril_add_ready(fid);
    152         fibril_active = true;
    153164}
    154165
Note: See TracChangeset for help on using the changeset viewer.