Changeset ee603c4 in mainline


Ignore:
Timestamp:
2012-04-04T21:10:22Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
92b42442
Parents:
4794417
Message:

UDP associations, sending datagrams.

Location:
uspace/srv/udp
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/udp/Makefile

    r4794417 ree603c4  
    3333
    3434SOURCES = \
     35        assoc.c \
    3536        msg.c \
    3637        sock.c \
  • uspace/srv/udp/ucall.c

    r4794417 ree603c4  
    3737#include <io/log.h>
    3838
    39 //#include "conn.h"
     39#include "assoc.h"
    4040#include "udp_type.h"
    4141#include "ucall.h"
     
    4343udp_error_t udp_uc_create(udp_assoc_t **assoc)
    4444{
    45 //      udo_assoc_t *nassoc;
     45        udp_assoc_t *nassoc;
    4646
    4747        log_msg(LVL_DEBUG, "udp_uc_create()");
     48        nassoc = udp_assoc_new(NULL, NULL);
     49        if (nassoc == NULL)
     50                return UDP_ENORES;
    4851
     52        udp_assoc_add(nassoc);
     53        *assoc = nassoc;
    4954        return UDP_EOK;
    5055}
     
    5257udp_error_t udp_uc_set_foreign(udp_assoc_t *assoc, udp_sock_t *fsock)
    5358{
    54 //      udo_assoc_t *nconn;
    55 
    5659        log_msg(LVL_DEBUG, "udp_uc_set_foreign(%p, %p)", assoc, fsock);
    5760
     61        udp_assoc_set_foreign(assoc, fsock);
    5862        return UDP_EOK;
    5963}
     
    6165udp_error_t udp_uc_set_local(udp_assoc_t *assoc, udp_sock_t *lsock)
    6266{
    63 //      udo_assoc_t *nconn;
    64 
    6567        log_msg(LVL_DEBUG, "udp_uc_set_local(%p, %p)", assoc, lsock);
    6668
     69        udp_assoc_set_local(assoc, lsock);
    6770        return UDP_EOK;
    6871}
     
    7174    size_t size, xflags_t flags)
    7275{
     76        int rc;
     77        udp_msg_t msg;
     78
    7379        log_msg(LVL_DEBUG, "%s: udp_uc_send()", assoc->name);
     80
     81        msg.data = data;
     82        msg.data_size = size;
     83
     84        rc = udp_assoc_send(assoc, fsock, &msg);
     85        switch (rc) {
     86        case ENOMEM:
     87                return UDP_ENORES;
     88        case EINVAL:
     89                return UDP_EUNSPEC;
     90        case EIO:
     91                return UDP_ENOROUTE;
     92        }
    7493        return UDP_EOK;
    7594}
     
    92111void udp_uc_destroy(udp_assoc_t *assoc)
    93112{
    94         log_msg(LVL_DEBUG, "udp_uc_delete()");
    95 //      udp_assoc_destroy(assoc);
     113        log_msg(LVL_DEBUG, "udp_uc_destroy()");
     114        udp_assoc_remove(assoc);
     115        udp_assoc_delete(assoc);
    96116}
    97117
  • uspace/srv/udp/udp_inet.c

    r4794417 ree603c4  
    4343#include <task.h>
    4444
    45 /*
    46 #include "pdu.h"
    47 #include "rqueue.h"
    48 */
    4945#include "std.h"
    5046#include "udp_inet.h"
     47#include "udp_type.h"
    5148
    5249static int udp_inet_ev_recv(inet_dgram_t *dgram);
     
    123120
    124121/** Transmit PDU over network layer. */
    125 /*void tcp_transmit_pdu(tcp_pdu_t *pdu)
     122int udp_transmit_pdu(udp_pdu_t *pdu)
    126123{
    127124        int rc;
    128         uint8_t *pdu_raw;
    129         size_t pdu_raw_size;
    130125        inet_dgram_t dgram;
    131126
    132         pdu_raw_size = pdu->header_size + pdu->text_size;
    133         pdu_raw = malloc(pdu_raw_size);
    134         if (pdu_raw == NULL) {
    135                 log_msg(LVL_ERROR, "Failed to transmit PDU. Out of memory.");
    136                 return;
    137         }
    138 
    139         memcpy(pdu_raw, pdu->header, pdu->header_size);
    140         memcpy(pdu_raw + pdu->header_size, pdu->text,
    141             pdu->text_size);
    142 
    143         dgram.src.ipv4 = pdu->src_addr.ipv4;
    144         dgram.dest.ipv4 = pdu->dest_addr.ipv4;
     127        dgram.src.ipv4 = pdu->src.ipv4;
     128        dgram.dest.ipv4 = pdu->dest.ipv4;
    145129        dgram.tos = 0;
    146         dgram.data = pdu_raw;
    147         dgram.size = pdu_raw_size;
     130        dgram.data = pdu->data;
     131        dgram.size = pdu->data_size;
    148132
    149133        rc = inet_send(&dgram, INET_TTL_MAX, 0);
    150134        if (rc != EOK)
    151135                log_msg(LVL_ERROR, "Failed to transmit PDU.");
     136
     137        return rc;
    152138}
    153 */
     139
    154140/** Process received PDU. */
    155141/*
  • uspace/srv/udp/udp_inet.h

    r4794417 ree603c4  
    3636#define UDP_INET_H
    3737
     38#include "udp_type.h"
     39
    3840extern int udp_inet_init(void);
     41extern int udp_transmit_pdu(udp_pdu_t *);
    3942
    4043#endif
  • uspace/srv/udp/udp_type.h

    r4794417 ree603c4  
    4141
    4242typedef enum {
    43         UDP_EOK
     43        UDP_EOK,
     44        /* Insufficient resources */
     45        UDP_ENORES,
     46        /* Foreign socket unspecified */
     47        UDP_EUNSPEC,
     48        /* No route to destination */
     49        UDP_ENOROUTE
    4450} udp_error_t;
    4551
     
    9298} udp_client_t;
    9399
     100/** UDP association
     101 *
     102 * This is a rough equivalent of a TCP connection endpoint. It allows
     103 * sending and receiving UDP datagrams and it is uniquely identified
     104 * by a socket pair.
     105 */
    94106typedef struct {
    95107        char *name;
     108        link_t link;
     109
     110        /** Association identification (local and foreign socket) */
    96111        udp_sockpair_t ident;
     112
     113        /** True if association was deleted by user */
     114        bool deleted;
     115
     116        /** Protects access to association structure */
     117        fibril_mutex_t lock;
     118        /** Reference count */
     119        atomic_t refcnt;
     120
     121        /** Receive queue */
     122        list_t rcv_queue;
     123        /** Receive queue CV. Broadcast when new datagram is inserted */
     124        fibril_condvar_t rcv_queue_cv;
    97125} udp_assoc_t;
    98126
Note: See TracChangeset for help on using the changeset viewer.