Changeset ee603c4 in mainline
- Timestamp:
- 2012-04-04T21:10:22Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 92b42442
- Parents:
- 4794417
- Location:
- uspace/srv/udp
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/udp/Makefile
r4794417 ree603c4 33 33 34 34 SOURCES = \ 35 assoc.c \ 35 36 msg.c \ 36 37 sock.c \ -
uspace/srv/udp/ucall.c
r4794417 ree603c4 37 37 #include <io/log.h> 38 38 39 //#include "conn.h"39 #include "assoc.h" 40 40 #include "udp_type.h" 41 41 #include "ucall.h" … … 43 43 udp_error_t udp_uc_create(udp_assoc_t **assoc) 44 44 { 45 // udo_assoc_t *nassoc;45 udp_assoc_t *nassoc; 46 46 47 47 log_msg(LVL_DEBUG, "udp_uc_create()"); 48 nassoc = udp_assoc_new(NULL, NULL); 49 if (nassoc == NULL) 50 return UDP_ENORES; 48 51 52 udp_assoc_add(nassoc); 53 *assoc = nassoc; 49 54 return UDP_EOK; 50 55 } … … 52 57 udp_error_t udp_uc_set_foreign(udp_assoc_t *assoc, udp_sock_t *fsock) 53 58 { 54 // udo_assoc_t *nconn;55 56 59 log_msg(LVL_DEBUG, "udp_uc_set_foreign(%p, %p)", assoc, fsock); 57 60 61 udp_assoc_set_foreign(assoc, fsock); 58 62 return UDP_EOK; 59 63 } … … 61 65 udp_error_t udp_uc_set_local(udp_assoc_t *assoc, udp_sock_t *lsock) 62 66 { 63 // udo_assoc_t *nconn;64 65 67 log_msg(LVL_DEBUG, "udp_uc_set_local(%p, %p)", assoc, lsock); 66 68 69 udp_assoc_set_local(assoc, lsock); 67 70 return UDP_EOK; 68 71 } … … 71 74 size_t size, xflags_t flags) 72 75 { 76 int rc; 77 udp_msg_t msg; 78 73 79 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 } 74 93 return UDP_EOK; 75 94 } … … 92 111 void udp_uc_destroy(udp_assoc_t *assoc) 93 112 { 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); 96 116 } 97 117 -
uspace/srv/udp/udp_inet.c
r4794417 ree603c4 43 43 #include <task.h> 44 44 45 /*46 #include "pdu.h"47 #include "rqueue.h"48 */49 45 #include "std.h" 50 46 #include "udp_inet.h" 47 #include "udp_type.h" 51 48 52 49 static int udp_inet_ev_recv(inet_dgram_t *dgram); … … 123 120 124 121 /** Transmit PDU over network layer. */ 125 /*void tcp_transmit_pdu(tcp_pdu_t *pdu)122 int udp_transmit_pdu(udp_pdu_t *pdu) 126 123 { 127 124 int rc; 128 uint8_t *pdu_raw;129 size_t pdu_raw_size;130 125 inet_dgram_t dgram; 131 126 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; 145 129 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; 148 132 149 133 rc = inet_send(&dgram, INET_TTL_MAX, 0); 150 134 if (rc != EOK) 151 135 log_msg(LVL_ERROR, "Failed to transmit PDU."); 136 137 return rc; 152 138 } 153 */ 139 154 140 /** Process received PDU. */ 155 141 /* -
uspace/srv/udp/udp_inet.h
r4794417 ree603c4 36 36 #define UDP_INET_H 37 37 38 #include "udp_type.h" 39 38 40 extern int udp_inet_init(void); 41 extern int udp_transmit_pdu(udp_pdu_t *); 39 42 40 43 #endif -
uspace/srv/udp/udp_type.h
r4794417 ree603c4 41 41 42 42 typedef 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 44 50 } udp_error_t; 45 51 … … 92 98 } udp_client_t; 93 99 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 */ 94 106 typedef struct { 95 107 char *name; 108 link_t link; 109 110 /** Association identification (local and foreign socket) */ 96 111 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; 97 125 } udp_assoc_t; 98 126
Note:
See TracChangeset
for help on using the changeset viewer.