Changeset eb083ad in mainline for uspace/srv
- Timestamp:
- 2012-05-17T21:09:06Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8fde078
- Parents:
- a8b8086 (diff), 3e67ab1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/srv
- Files:
-
- 11 edited
- 28 moved
-
locsrv/Makefile (moved) (moved from uspace/srv/loc/Makefile ) (1 diff)
-
locsrv/category.c (moved) (moved from uspace/srv/loc/category.c ) (1 diff)
-
locsrv/category.h (moved) (moved from uspace/srv/loc/category.h ) (1 diff)
-
locsrv/locsrv.c (moved) (moved from uspace/srv/loc/loc.c ) (1 diff)
-
locsrv/locsrv.h (moved) (moved from uspace/srv/loc/loc.h ) (1 diff)
-
net/inetsrv/Makefile (moved) (moved from uspace/srv/net/inet/Makefile ) (1 diff)
-
net/inetsrv/addrobj.c (moved) (moved from uspace/srv/net/inet/addrobj.c ) (5 diffs)
-
net/inetsrv/addrobj.h (moved) (moved from uspace/srv/net/inet/addrobj.h ) (2 diffs)
-
net/inetsrv/icmp.c (moved) (moved from uspace/srv/net/inet/icmp.c ) (1 diff)
-
net/inetsrv/icmp.h (moved) (moved from uspace/srv/net/inet/icmp.h ) (1 diff)
-
net/inetsrv/icmp_std.h (moved) (moved from uspace/srv/net/inet/icmp_std.h )
-
net/inetsrv/inet_link.c (moved) (moved from uspace/srv/net/inet/inet_link.c ) (3 diffs)
-
net/inetsrv/inet_link.h (moved) (moved from uspace/srv/net/inet/inet_link.h ) (1 diff)
-
net/inetsrv/inet_std.h (moved) (moved from uspace/srv/net/inet/inet_std.h )
-
net/inetsrv/inet_util.c (moved) (moved from uspace/srv/net/inet/inet_util.c )
-
net/inetsrv/inet_util.h (moved) (moved from uspace/srv/net/inet/inet_util.h )
-
net/inetsrv/inetcfg.c (moved) (moved from uspace/srv/net/inet/inetcfg.c ) (2 diffs)
-
net/inetsrv/inetcfg.h (moved) (moved from uspace/srv/net/inet/inetcfg.h )
-
net/inetsrv/inetping.c (moved) (moved from uspace/srv/net/inet/inetping.c ) (1 diff)
-
net/inetsrv/inetping.h (moved) (moved from uspace/srv/net/inet/inetping.h )
-
net/inetsrv/inetsrv.c (moved) (moved from uspace/srv/net/inet/inet.c ) (2 diffs)
-
net/inetsrv/inetsrv.h (moved) (moved from uspace/srv/net/inet/inet.h ) (2 diffs)
-
net/inetsrv/pdu.c (moved) (moved from uspace/srv/net/inet/pdu.c ) (1 diff)
-
net/inetsrv/pdu.h (moved) (moved from uspace/srv/net/inet/pdu.h ) (1 diff)
-
net/inetsrv/reass.c (moved) (moved from uspace/srv/net/inet/reass.c ) (1 diff)
-
net/inetsrv/reass.h (moved) (moved from uspace/srv/net/inet/reass.h ) (1 diff)
-
net/inetsrv/sroute.c (moved) (moved from uspace/srv/net/inet/sroute.c ) (1 diff)
-
net/inetsrv/sroute.h (moved) (moved from uspace/srv/net/inet/sroute.h ) (1 diff)
-
net/tcp/conn.c (modified) (6 diffs)
-
net/tcp/ncsim.c (modified) (4 diffs)
-
net/tcp/ncsim.h (modified) (1 diff)
-
net/tcp/rqueue.c (modified) (3 diffs)
-
net/tcp/rqueue.h (modified) (1 diff)
-
net/tcp/segment.c (modified) (1 diff)
-
net/tcp/sock.c (modified) (23 diffs)
-
net/tcp/tcp.c (modified) (1 diff)
-
net/tcp/tcp_type.h (modified) (3 diffs)
-
net/tcp/test.c (modified) (5 diffs)
-
net/udp/sock.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/locsrv/Makefile
ra8b8086 reb083ad 29 29 30 30 USPACE_PREFIX = ../.. 31 BINARY = loc 31 BINARY = locsrv 32 32 STATIC_NEEDED = y 33 33 34 34 SOURCES = \ 35 35 category.c \ 36 loc .c36 locsrv.c 37 37 38 38 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/locsrv/category.c
ra8b8086 reb083ad 40 40 41 41 #include "category.h" 42 #include "loc .h"42 #include "locsrv.h" 43 43 44 44 /** Initialize category directory. */ -
uspace/srv/locsrv/category.h
ra8b8086 reb083ad 37 37 38 38 #include <adt/list.h> 39 #include "loc .h"39 #include "locsrv.h" 40 40 41 41 typedef sysarg_t catid_t; -
uspace/srv/locsrv/locsrv.c
ra8b8086 reb083ad 51 51 52 52 #include "category.h" 53 #include "loc .h"53 #include "locsrv.h" 54 54 55 55 #define NAME "loc" -
uspace/srv/locsrv/locsrv.h
ra8b8086 reb083ad 33 33 */ 34 34 35 #ifndef LOC _H_36 #define LOC _H_35 #ifndef LOCSRV_H_ 36 #define LOCSRV_H_ 37 37 38 38 #include <ipc/loc.h> -
uspace/srv/net/inetsrv/Makefile
ra8b8086 reb083ad 28 28 29 29 USPACE_PREFIX = ../../.. 30 BINARY = inet 30 BINARY = inetsrv 31 31 32 32 SOURCES = \ 33 33 addrobj.c \ 34 34 icmp.c \ 35 inet .c \35 inetsrv.c \ 36 36 inet_link.c \ 37 37 inet_util.c \ -
uspace/srv/net/inetsrv/addrobj.c
ra8b8086 reb083ad 44 44 45 45 #include "addrobj.h" 46 #include "inet .h"46 #include "inetsrv.h" 47 47 #include "inet_link.h" 48 48 #include "inet_util.h" 49 50 static inet_addrobj_t *inet_addrobj_find_by_name_locked(const char *, inet_link_t *); 49 51 50 52 static FIBRIL_MUTEX_INITIALIZE(addr_list_lock); … … 77 79 } 78 80 79 void inet_addrobj_add(inet_addrobj_t *addr) 80 { 81 fibril_mutex_lock(&addr_list_lock); 81 int inet_addrobj_add(inet_addrobj_t *addr) 82 { 83 inet_addrobj_t *aobj; 84 85 fibril_mutex_lock(&addr_list_lock); 86 aobj = inet_addrobj_find_by_name_locked(addr->name, addr->ilink); 87 if (aobj != NULL) { 88 /* Duplicate address name */ 89 fibril_mutex_unlock(&addr_list_lock); 90 return EEXISTS; 91 } 92 82 93 list_append(&addr->addr_list, &addr_list); 83 94 fibril_mutex_unlock(&addr_list_lock); 95 96 return EOK; 84 97 } 85 98 … … 130 143 * @return Address object 131 144 */ 132 inet_addrobj_t *inet_addrobj_find_by_name(const char *name, inet_link_t *ilink) 133 { 134 log_msg(LVL_DEBUG, "inet_addrobj_find_by_name('%s', '%s')", 145 static inet_addrobj_t *inet_addrobj_find_by_name_locked(const char *name, inet_link_t *ilink) 146 { 147 assert(fibril_mutex_is_locked(&addr_list_lock)); 148 149 log_msg(LVL_DEBUG, "inet_addrobj_find_by_name_locked('%s', '%s')", 135 150 name, ilink->svc_name); 136 151 137 fibril_mutex_lock(&addr_list_lock);138 139 152 list_foreach(addr_list, link) { 140 153 inet_addrobj_t *naddr = list_get_instance(link, … … 142 155 143 156 if (naddr->ilink == ilink && str_cmp(naddr->name, name) == 0) { 144 fibril_mutex_unlock(&addr_list_lock); 145 log_msg(LVL_DEBUG, "inet_addrobj_find_by_name: found %p", 157 log_msg(LVL_DEBUG, "inet_addrobj_find_by_name_locked: found %p", 146 158 naddr); 147 159 return naddr; … … 149 161 } 150 162 151 log_msg(LVL_DEBUG, "inet_addrobj_find_by_name: Not found"); 152 fibril_mutex_unlock(&addr_list_lock); 163 log_msg(LVL_DEBUG, "inet_addrobj_find_by_name_locked: Not found"); 153 164 154 165 return NULL; 166 } 167 168 169 /** Find address object on a link, with a specific name. 170 * 171 * @param name Address object name 172 * @param ilink Inet link 173 * @return Address object 174 */ 175 inet_addrobj_t *inet_addrobj_find_by_name(const char *name, inet_link_t *ilink) 176 { 177 inet_addrobj_t *aobj; 178 179 log_msg(LVL_DEBUG, "inet_addrobj_find_by_name('%s', '%s')", 180 name, ilink->svc_name); 181 182 fibril_mutex_lock(&addr_list_lock); 183 aobj = inet_addrobj_find_by_name_locked(name, ilink); 184 fibril_mutex_unlock(&addr_list_lock); 185 186 return aobj; 155 187 } 156 188 -
uspace/srv/net/inetsrv/addrobj.h
ra8b8086 reb083ad 39 39 40 40 #include <sys/types.h> 41 #include "inet .h"41 #include "inetsrv.h" 42 42 43 43 typedef enum { … … 50 50 extern inet_addrobj_t *inet_addrobj_new(void); 51 51 extern void inet_addrobj_delete(inet_addrobj_t *); 52 extern voidinet_addrobj_add(inet_addrobj_t *);52 extern int inet_addrobj_add(inet_addrobj_t *); 53 53 extern void inet_addrobj_remove(inet_addrobj_t *); 54 54 extern inet_addrobj_t *inet_addrobj_find(inet_addr_t *, inet_addrobj_find_t); -
uspace/srv/net/inetsrv/icmp.c
ra8b8086 reb083ad 43 43 #include "icmp.h" 44 44 #include "icmp_std.h" 45 #include "inet .h"45 #include "inetsrv.h" 46 46 #include "inetping.h" 47 47 #include "pdu.h" -
uspace/srv/net/inetsrv/icmp.h
ra8b8086 reb083ad 38 38 #define ICMP_H_ 39 39 40 #include "inet .h"40 #include "inetsrv.h" 41 41 42 42 extern int icmp_recv(inet_dgram_t *); -
uspace/srv/net/inetsrv/inet_link.c
ra8b8086 reb083ad 45 45 46 46 #include "addrobj.h" 47 #include "inet .h"47 #include "inetsrv.h" 48 48 #include "inet_link.h" 49 49 #include "pdu.h" … … 207 207 addr->ilink = ilink; 208 208 addr->name = str_dup("v4a"); 209 inet_addrobj_add(addr); 209 rc = inet_addrobj_add(addr); 210 if (rc != EOK) { 211 log_msg(LVL_ERROR, "Failed setting IP address on internet link."); 212 inet_addrobj_delete(addr); 213 /* XXX Roll back */ 214 return rc; 215 } 210 216 211 217 iaddr.ipv4 = addr->naddr.ipv4; … … 213 219 if (rc != EOK) { 214 220 log_msg(LVL_ERROR, "Failed setting IP address on internet link."); 221 inet_addrobj_remove(addr); 222 inet_addrobj_delete(addr); 215 223 /* XXX Roll back */ 216 224 return rc; -
uspace/srv/net/inetsrv/inet_link.h
ra8b8086 reb083ad 39 39 40 40 #include <sys/types.h> 41 #include "inet .h"41 #include "inetsrv.h" 42 42 43 43 extern int inet_link_discovery_start(void); -
uspace/srv/net/inetsrv/inetcfg.c
ra8b8086 reb083ad 46 46 47 47 #include "addrobj.h" 48 #include "inet .h"48 #include "inetsrv.h" 49 49 #include "inet_link.h" 50 50 #include "inetcfg.h" … … 75 75 addr->ilink = ilink; 76 76 addr->name = str_dup(name); 77 inet_addrobj_add(addr); 77 rc = inet_addrobj_add(addr); 78 if (rc != EOK) { 79 log_msg(LVL_DEBUG, "Duplicate address name '%s'.", addr->name); 80 inet_addrobj_delete(addr); 81 return rc; 82 } 78 83 79 84 iaddr.ipv4 = addr->naddr.ipv4; -
uspace/srv/net/inetsrv/inetping.c
ra8b8086 reb083ad 46 46 #include "icmp.h" 47 47 #include "icmp_std.h" 48 #include "inet .h"48 #include "inetsrv.h" 49 49 #include "inetping.h" 50 50 -
uspace/srv/net/inetsrv/inetsrv.c
ra8b8086 reb083ad 50 50 #include "icmp.h" 51 51 #include "icmp_std.h" 52 #include "inet .h"52 #include "inetsrv.h" 53 53 #include "inetcfg.h" 54 54 #include "inetping.h" … … 57 57 #include "sroute.h" 58 58 59 #define NAME "inet "59 #define NAME "inetsrv" 60 60 61 61 static void inet_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg); -
uspace/srv/net/inetsrv/inetsrv.h
ra8b8086 reb083ad 27 27 */ 28 28 29 /** @addtogroup inet 29 /** @addtogroup inetsrv 30 30 * @{ 31 31 */ … … 35 35 */ 36 36 37 #ifndef INET _H_38 #define INET _H_37 #ifndef INETSRV_H_ 38 #define INETSRV_H_ 39 39 40 40 #include <adt/list.h> -
uspace/srv/net/inetsrv/pdu.c
ra8b8086 reb083ad 45 45 #include <stdlib.h> 46 46 47 #include "inet .h"47 #include "inetsrv.h" 48 48 #include "inet_std.h" 49 49 #include "pdu.h" -
uspace/srv/net/inetsrv/pdu.h
ra8b8086 reb083ad 39 39 40 40 #include <sys/types.h> 41 #include "inet .h"41 #include "inetsrv.h" 42 42 43 43 #define INET_CHECKSUM_INIT 0xffff -
uspace/srv/net/inetsrv/reass.c
ra8b8086 reb083ad 42 42 #include <stdlib.h> 43 43 44 #include "inet .h"44 #include "inetsrv.h" 45 45 #include "inet_std.h" 46 46 #include "reass.h" -
uspace/srv/net/inetsrv/reass.h
ra8b8086 reb083ad 39 39 40 40 #include <sys/types.h> 41 #include "inet .h"41 #include "inetsrv.h" 42 42 43 43 extern int inet_reass_queue_packet(inet_packet_t *); -
uspace/srv/net/inetsrv/sroute.c
ra8b8086 reb083ad 44 44 45 45 #include "sroute.h" 46 #include "inet .h"46 #include "inetsrv.h" 47 47 #include "inet_link.h" 48 48 #include "inet_util.h" -
uspace/srv/net/inetsrv/sroute.h
ra8b8086 reb083ad 39 39 40 40 #include <sys/types.h> 41 #include "inet .h"41 #include "inetsrv.h" 42 42 43 43 extern inet_sroute_t *inet_sroute_new(void); -
uspace/srv/net/tcp/conn.c
ra8b8086 reb083ad 184 184 void tcp_conn_addref(tcp_conn_t *conn) 185 185 { 186 log_msg(LVL_DEBUG , "%s: tcp_conn_addref(%p)", conn->name, conn);186 log_msg(LVL_DEBUG2, "%s: tcp_conn_addref(%p)", conn->name, conn); 187 187 atomic_inc(&conn->refcnt); 188 188 } … … 196 196 void tcp_conn_delref(tcp_conn_t *conn) 197 197 { 198 log_msg(LVL_DEBUG , "%s: tcp_conn_delref(%p)", conn->name, conn);198 log_msg(LVL_DEBUG2, "%s: tcp_conn_delref(%p)", conn->name, conn); 199 199 200 200 if (atomic_predec(&conn->refcnt) == 0) … … 312 312 static bool tcp_socket_match(tcp_sock_t *sock, tcp_sock_t *patt) 313 313 { 314 log_msg(LVL_DEBUG , "tcp_socket_match(sock=(%x,%u), pat=(%x,%u))",314 log_msg(LVL_DEBUG2, "tcp_socket_match(sock=(%x,%u), pat=(%x,%u))", 315 315 sock->addr.ipv4, sock->port, patt->addr.ipv4, patt->port); 316 316 … … 323 323 return false; 324 324 325 log_msg(LVL_DEBUG , " -> match");325 log_msg(LVL_DEBUG2, " -> match"); 326 326 327 327 return true; … … 331 331 static bool tcp_sockpair_match(tcp_sockpair_t *sp, tcp_sockpair_t *pattern) 332 332 { 333 log_msg(LVL_DEBUG , "tcp_sockpair_match(%p, %p)", sp, pattern);333 log_msg(LVL_DEBUG2, "tcp_sockpair_match(%p, %p)", sp, pattern); 334 334 335 335 if (!tcp_socket_match(&sp->local, &pattern->local)) … … 360 360 tcp_conn_t *conn = list_get_instance(link, tcp_conn_t, link); 361 361 tcp_sockpair_t *csp = &conn->ident; 362 log_msg(LVL_DEBUG , "compare with conn (f:(%x,%u), l:(%x,%u))",362 log_msg(LVL_DEBUG2, "compare with conn (f:(%x,%u), l:(%x,%u))", 363 363 csp->foreign.addr.ipv4, csp->foreign.port, 364 364 csp->local.addr.ipv4, csp->local.port); -
uspace/srv/net/tcp/ncsim.c
ra8b8086 reb083ad 44 44 #include <io/log.h> 45 45 #include <stdlib.h> 46 #include < thread.h>46 #include <fibril.h> 47 47 #include "conn.h" 48 48 #include "ncsim.h" … … 119 119 } 120 120 121 /** Network condition simulator handler thread. */122 static void tcp_ncsim_thread(void *arg)121 /** Network condition simulator handler fibril. */ 122 static int tcp_ncsim_fibril(void *arg) 123 123 { 124 124 link_t *link; … … 126 126 int rc; 127 127 128 log_msg(LVL_DEBUG, "tcp_ncsim_ thread()");128 log_msg(LVL_DEBUG, "tcp_ncsim_fibril()"); 129 129 130 130 … … 151 151 free(sqe); 152 152 } 153 154 /* Not reached */ 155 return 0; 153 156 } 154 157 155 /** Start simulator handler thread. */156 void tcp_ncsim_ thread_start(void)158 /** Start simulator handler fibril. */ 159 void tcp_ncsim_fibril_start(void) 157 160 { 158 thread_id_t tid; 159 int rc; 161 fid_t fid; 160 162 161 log_msg(LVL_DEBUG, "tcp_ncsim_ thread_start()");163 log_msg(LVL_DEBUG, "tcp_ncsim_fibril_start()"); 162 164 163 rc = thread_create(tcp_ncsim_thread, NULL, "ncsim", &tid);164 if ( rc != EOK) {165 log_msg(LVL_ERROR, "Failed creating ncsim thread.");165 fid = fibril_create(tcp_ncsim_fibril, NULL); 166 if (fid == 0) { 167 log_msg(LVL_ERROR, "Failed creating ncsim fibril."); 166 168 return; 167 169 } 170 171 fibril_add_ready(fid); 168 172 } 169 173 -
uspace/srv/net/tcp/ncsim.h
ra8b8086 reb083ad 40 40 extern void tcp_ncsim_init(void); 41 41 extern void tcp_ncsim_bounce_seg(tcp_sockpair_t *, tcp_segment_t *); 42 extern void tcp_ncsim_thread_start(void); 43 42 extern void tcp_ncsim_fibril_start(void); 44 43 45 44 #endif -
uspace/srv/net/tcp/rqueue.c
ra8b8086 reb083ad 39 39 #include <io/log.h> 40 40 #include <stdlib.h> 41 #include < thread.h>41 #include <fibril.h> 42 42 #include "conn.h" 43 43 #include "pdu.h" … … 128 128 } 129 129 130 /** Receive queue handler thread. */131 static void tcp_rqueue_thread(void *arg)130 /** Receive queue handler fibril. */ 131 static int tcp_rqueue_fibril(void *arg) 132 132 { 133 133 link_t *link; 134 134 tcp_rqueue_entry_t *rqe; 135 135 136 log_msg(LVL_DEBUG, "tcp_rqueue_ thread()");136 log_msg(LVL_DEBUG, "tcp_rqueue_fibril()"); 137 137 138 138 while (true) { … … 142 142 tcp_as_segment_arrived(&rqe->sp, rqe->seg); 143 143 } 144 145 /* Not reached */ 146 return 0; 144 147 } 145 148 146 /** Start receive queue handler thread. */147 void tcp_rqueue_ thread_start(void)149 /** Start receive queue handler fibril. */ 150 void tcp_rqueue_fibril_start(void) 148 151 { 149 thread_id_t tid; 150 int rc; 152 fid_t fid; 151 153 152 log_msg(LVL_DEBUG, "tcp_rqueue_ thread_start()");154 log_msg(LVL_DEBUG, "tcp_rqueue_fibril_start()"); 153 155 154 rc = thread_create(tcp_rqueue_thread, NULL, "rqueue", &tid);155 if ( rc != EOK) {156 log_msg(LVL_ERROR, "Failed creating rqueue thread.");156 fid = fibril_create(tcp_rqueue_fibril, NULL); 157 if (fid == 0) { 158 log_msg(LVL_ERROR, "Failed creating rqueue fibril."); 157 159 return; 158 160 } 161 162 fibril_add_ready(fid); 159 163 } 160 164 -
uspace/srv/net/tcp/rqueue.h
ra8b8086 reb083ad 42 42 extern void tcp_rqueue_insert_seg(tcp_sockpair_t *, tcp_segment_t *); 43 43 extern void tcp_rqueue_handler(void *); 44 extern void tcp_rqueue_ thread_start(void);44 extern void tcp_rqueue_fibril_start(void); 45 45 46 46 -
uspace/srv/net/tcp/segment.c
ra8b8086 reb083ad 248 248 void tcp_segment_dump(tcp_segment_t *seg) 249 249 { 250 log_msg(LVL_DEBUG , "Segment dump:");251 log_msg(LVL_DEBUG , " - ctrl = %u", (unsigned)seg->ctrl);252 log_msg(LVL_DEBUG , " - seq = % " PRIu32, seg->seq);253 log_msg(LVL_DEBUG , " - ack = % " PRIu32, seg->ack);254 log_msg(LVL_DEBUG , " - len = % " PRIu32, seg->len);255 log_msg(LVL_DEBUG , " - wnd = % " PRIu32, seg->wnd);256 log_msg(LVL_DEBUG , " - up = % " PRIu32, seg->up);250 log_msg(LVL_DEBUG2, "Segment dump:"); 251 log_msg(LVL_DEBUG2, " - ctrl = %u", (unsigned)seg->ctrl); 252 log_msg(LVL_DEBUG2, " - seq = % " PRIu32, seg->seq); 253 log_msg(LVL_DEBUG2, " - ack = % " PRIu32, seg->ack); 254 log_msg(LVL_DEBUG2, " - len = % " PRIu32, seg->len); 255 log_msg(LVL_DEBUG2, " - wnd = % " PRIu32, seg->wnd); 256 log_msg(LVL_DEBUG2, " - up = % " PRIu32, seg->up); 257 257 } 258 258 -
uspace/srv/net/tcp/sock.c
ra8b8086 reb083ad 42 42 #include <ipc/services.h> 43 43 #include <ipc/socket.h> 44 #include <net/modules.h>45 44 #include <net/socket.h> 46 45 #include <ns.h> … … 52 51 #include "ucall.h" 53 52 54 #define FRAGMENT_SIZE 102455 56 53 #define MAX_BACKLOG 128 57 54 … … 67 64 static void tcp_sock_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg); 68 65 static void tcp_sock_cstate_cb(tcp_conn_t *conn, void *arg); 66 static int tcp_sock_recv_fibril(void *arg); 69 67 70 68 int tcp_sock_init(void) … … 98 96 async_exch_t *exch = async_exchange_begin(sock_core->sess); 99 97 async_msg_5(exch, NET_SOCKET_RECEIVED, (sysarg_t)sock_core->socket_id, 100 FRAGMENT_SIZE, 0, 0, 1);98 TCP_SOCK_FRAGMENT_SIZE, 0, 0, 1); 101 99 async_exchange_end(exch); 102 100 } … … 107 105 async_exch_t *exch = async_exchange_begin(lsock_core->sess); 108 106 async_msg_5(exch, NET_SOCKET_ACCEPTED, (sysarg_t)lsock_core->socket_id, 109 FRAGMENT_SIZE, 0, 0, 0);107 TCP_SOCK_FRAGMENT_SIZE, 0, 0, 0); 110 108 async_exchange_end(exch); 111 109 } 112 110 111 static int tcp_sock_create(tcp_client_t *client, tcp_sockdata_t **rsock) 112 { 113 tcp_sockdata_t *sock; 114 115 log_msg(LVL_DEBUG, "tcp_sock_create()"); 116 *rsock = NULL; 117 118 sock = calloc(sizeof(tcp_sockdata_t), 1); 119 if (sock == NULL) 120 return ENOMEM; 121 122 fibril_mutex_initialize(&sock->lock); 123 sock->client = client; 124 125 sock->recv_buffer_used = 0; 126 sock->recv_error = TCP_EOK; 127 fibril_mutex_initialize(&sock->recv_buffer_lock); 128 fibril_condvar_initialize(&sock->recv_buffer_cv); 129 list_initialize(&sock->ready); 130 131 *rsock = sock; 132 return EOK; 133 } 134 135 static void tcp_sock_uncreate(tcp_sockdata_t *sock) 136 { 137 log_msg(LVL_DEBUG, "tcp_sock_uncreate()"); 138 free(sock); 139 } 140 141 static int tcp_sock_finish_setup(tcp_sockdata_t *sock, int *sock_id) 142 { 143 socket_core_t *sock_core; 144 int rc; 145 146 log_msg(LVL_DEBUG, "tcp_sock_finish_setup()"); 147 148 sock->recv_fibril = fibril_create(tcp_sock_recv_fibril, sock); 149 if (sock->recv_fibril == 0) 150 return ENOMEM; 151 152 rc = socket_create(&sock->client->sockets, sock->client->sess, 153 sock, sock_id); 154 155 if (rc != EOK) 156 return rc; 157 158 sock_core = socket_cores_find(&sock->client->sockets, *sock_id); 159 assert(sock_core != NULL); 160 sock->sock_core = sock_core; 161 162 return EOK; 163 } 164 113 165 static void tcp_sock_socket(tcp_client_t *client, ipc_callid_t callid, ipc_call_t call) 114 166 { 115 167 tcp_sockdata_t *sock; 116 socket_core_t *sock_core;117 168 int sock_id; 118 169 int rc; … … 120 171 121 172 log_msg(LVL_DEBUG, "tcp_sock_socket()"); 122 sock = calloc(sizeof(tcp_sockdata_t), 1); 123 if (sock == NULL) { 124 async_answer_0(callid, ENOMEM); 125 return; 126 } 127 128 fibril_mutex_initialize(&sock->lock); 129 sock->client = client; 173 174 rc = tcp_sock_create(client, &sock); 175 if (rc != EOK) { 176 async_answer_0(callid, rc); 177 return; 178 } 179 130 180 sock->laddr.ipv4 = TCP_IPV4_ANY; 131 181 sock->lconn = NULL; 132 182 sock->backlog = 0; 133 list_initialize(&sock->ready);134 183 135 184 sock_id = SOCKET_GET_SOCKET_ID(call); 136 rc = socket_create(&client->sockets, client->sess,sock, &sock_id);185 rc = tcp_sock_finish_setup(sock, &sock_id); 137 186 if (rc != EOK) { 187 tcp_sock_uncreate(sock); 138 188 async_answer_0(callid, rc); 139 189 return; 140 190 } 141 191 142 sock_core = socket_cores_find(&client->sockets, sock_id);143 assert(sock_core != NULL);144 sock->sock_core = sock_core;145 146 refresh_answer(&answer, NULL);147 192 SOCKET_SET_SOCKET_ID(answer, sock_id); 148 193 149 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, FRAGMENT_SIZE);194 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, TCP_SOCK_FRAGMENT_SIZE); 150 195 SOCKET_SET_HEADER_SIZE(answer, sizeof(tcp_header_t)); 151 answer_call(callid, EOK, &answer, 3); 196 197 async_answer_3(callid, EOK, IPC_GET_ARG1(answer), 198 IPC_GET_ARG2(answer), IPC_GET_ARG3(answer)); 152 199 } 153 200 … … 361 408 } 362 409 410 if (rc == EOK) 411 fibril_add_ready(socket->recv_fibril); 412 363 413 async_answer_0(callid, rc); 364 365 /* Push one fragment notification to client's queue */366 tcp_sock_notify_data(sock_core);367 log_msg(LVL_DEBUG, "tcp_sock_connect(): notify conn\n");368 414 } 369 415 … … 374 420 int asock_id; 375 421 socket_core_t *sock_core; 376 socket_core_t *asock_core;377 422 tcp_sockdata_t *socket; 378 423 tcp_sockdata_t *asocket; … … 444 489 /* Allocate socket for accepted connection */ 445 490 446 log_msg(LVL_DEBUG, "tcp_sock_accept(): allocate asocket\n"); 447 asocket = calloc(sizeof(tcp_sockdata_t), 1); 448 if (asocket == NULL) { 449 fibril_mutex_unlock(&socket->lock); 450 async_answer_0(callid, ENOMEM); 451 return; 452 } 453 454 fibril_mutex_initialize(&asocket->lock); 455 asocket->client = client; 491 rc = tcp_sock_create(client, &asocket); 492 if (rc != EOK) { 493 fibril_mutex_unlock(&socket->lock); 494 async_answer_0(callid, rc); 495 return; 496 } 497 456 498 asocket->conn = conn; 457 499 log_msg(LVL_DEBUG, "tcp_sock_accept():create asocket\n"); 458 500 459 rc = socket_create(&client->sockets, client->sess,asocket, &asock_id);501 rc = tcp_sock_finish_setup(asocket, &asock_id); 460 502 if (rc != EOK) { 503 tcp_sock_uncreate(asocket); 461 504 fibril_mutex_unlock(&socket->lock); 462 505 async_answer_0(callid, rc); 463 506 return; 464 507 } 508 509 fibril_add_ready(asocket->recv_fibril); 510 465 511 log_msg(LVL_DEBUG, "tcp_sock_accept(): find acore\n"); 466 512 467 asock_core = socket_cores_find(&client->sockets, asock_id); 468 assert(asock_core != NULL); 469 470 refresh_answer(&answer, NULL); 471 472 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, FRAGMENT_SIZE); 513 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, TCP_SOCK_FRAGMENT_SIZE); 473 514 SOCKET_SET_SOCKET_ID(answer, asock_id); 474 515 SOCKET_SET_ADDRESS_LENGTH(answer, sizeof(struct sockaddr_in)); 475 476 answer_call(callid, asock_core->socket_id, &answer, 3); 477 516 517 async_answer_3(callid, asocket->sock_core->socket_id, 518 IPC_GET_ARG1(answer), IPC_GET_ARG2(answer), 519 IPC_GET_ARG3(answer)); 520 478 521 /* Push one fragment notification to client's queue */ 479 522 log_msg(LVL_DEBUG, "tcp_sock_accept(): notify data\n"); 480 tcp_sock_notify_data(asock_core);481 523 fibril_mutex_unlock(&socket->lock); 482 524 } … … 492 534 ipc_callid_t wcallid; 493 535 size_t length; 494 uint8_t buffer[ FRAGMENT_SIZE];536 uint8_t buffer[TCP_SOCK_FRAGMENT_SIZE]; 495 537 tcp_error_t trc; 496 538 int rc; … … 523 565 } 524 566 525 if (length > FRAGMENT_SIZE)526 length = FRAGMENT_SIZE;567 if (length > TCP_SOCK_FRAGMENT_SIZE) 568 length = TCP_SOCK_FRAGMENT_SIZE; 527 569 528 570 rc = async_data_write_finalize(wcallid, buffer, length); … … 559 601 } 560 602 561 refresh_answer(&answer, NULL); 562 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, FRAGMENT_SIZE); 563 answer_call(callid, EOK, &answer, 2); 603 IPC_SET_ARG1(answer, 0); 604 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, TCP_SOCK_FRAGMENT_SIZE); 605 async_answer_2(callid, EOK, IPC_GET_ARG1(answer), 606 IPC_GET_ARG2(answer)); 564 607 fibril_mutex_unlock(&socket->lock); 565 608 } … … 580 623 ipc_call_t answer; 581 624 ipc_callid_t rcallid; 582 uint8_t buffer[FRAGMENT_SIZE];583 625 size_t data_len; 584 xflags_t xflags;585 tcp_error_t trc;586 626 struct sockaddr_in addr; 587 627 tcp_sock_t *rsock; … … 610 650 (void)flags; 611 651 612 trc = tcp_uc_receive(socket->conn, buffer, FRAGMENT_SIZE, &data_len, 613 &xflags); 614 log_msg(LVL_DEBUG, "**** tcp_uc_receive done"); 615 616 switch (trc) { 652 log_msg(LVL_DEBUG, "tcp_sock_recvfrom(): lock recv_buffer_lock"); 653 fibril_mutex_lock(&socket->recv_buffer_lock); 654 while (socket->recv_buffer_used == 0 && socket->recv_error == TCP_EOK) { 655 log_msg(LVL_DEBUG, "wait for recv_buffer_cv + recv_buffer_used != 0"); 656 fibril_condvar_wait(&socket->recv_buffer_cv, 657 &socket->recv_buffer_lock); 658 } 659 660 log_msg(LVL_DEBUG, "Got data in sock recv_buffer"); 661 662 data_len = socket->recv_buffer_used; 663 rc = socket->recv_error; 664 665 switch (socket->recv_error) { 617 666 case TCP_EOK: 618 667 rc = EOK; … … 629 678 } 630 679 631 log_msg(LVL_DEBUG, "**** tcp_uc_receive-> %d", rc);680 log_msg(LVL_DEBUG, "**** recv result -> %d", rc); 632 681 if (rc != EOK) { 682 fibril_mutex_unlock(&socket->recv_buffer_lock); 633 683 fibril_mutex_unlock(&socket->lock); 634 684 async_answer_0(callid, rc); … … 645 695 log_msg(LVL_DEBUG, "addr read receive"); 646 696 if (!async_data_read_receive(&rcallid, &addr_length)) { 697 fibril_mutex_unlock(&socket->recv_buffer_lock); 647 698 fibril_mutex_unlock(&socket->lock); 648 699 async_answer_0(callid, EINVAL); … … 656 707 rc = async_data_read_finalize(rcallid, &addr, addr_length); 657 708 if (rc != EOK) { 709 fibril_mutex_unlock(&socket->recv_buffer_lock); 658 710 fibril_mutex_unlock(&socket->lock); 659 711 async_answer_0(callid, EINVAL); … … 664 716 log_msg(LVL_DEBUG, "data read receive"); 665 717 if (!async_data_read_receive(&rcallid, &length)) { 718 fibril_mutex_unlock(&socket->recv_buffer_lock); 666 719 fibril_mutex_unlock(&socket->lock); 667 720 async_answer_0(callid, EINVAL); … … 673 726 674 727 log_msg(LVL_DEBUG, "data read finalize"); 675 rc = async_data_read_finalize(rcallid, buffer, length); 728 rc = async_data_read_finalize(rcallid, socket->recv_buffer, length); 729 730 socket->recv_buffer_used -= length; 731 log_msg(LVL_DEBUG, "tcp_sock_recvfrom: %zu left in buffer", 732 socket->recv_buffer_used); 733 if (socket->recv_buffer_used > 0) { 734 memmove(socket->recv_buffer, socket->recv_buffer + length, 735 socket->recv_buffer_used); 736 tcp_sock_notify_data(socket->sock_core); 737 } 738 739 fibril_condvar_broadcast(&socket->recv_buffer_cv); 676 740 677 741 if (length < data_len && rc == EOK) … … 679 743 680 744 SOCKET_SET_READ_DATA_LENGTH(answer, length); 681 answer_call(callid, EOK, &answer, 1); 682 683 /* Push one fragment notification to client's queue */ 684 tcp_sock_notify_data(sock_core); 745 async_answer_1(callid, EOK, IPC_GET_ARG1(answer)); 746 747 fibril_mutex_unlock(&socket->recv_buffer_lock); 685 748 fibril_mutex_unlock(&socket->lock); 686 749 } … … 693 756 tcp_error_t trc; 694 757 int rc; 695 uint8_t buffer[FRAGMENT_SIZE];696 size_t data_len;697 xflags_t xflags;698 758 699 759 log_msg(LVL_DEBUG, "tcp_sock_close()"); … … 716 776 return; 717 777 } 718 719 /* Drain incoming data. This should really be done in the background. */720 do {721 trc = tcp_uc_receive(socket->conn, buffer,722 FRAGMENT_SIZE, &data_len, &xflags);723 } while (trc == TCP_EOK);724 725 tcp_uc_delete(socket->conn);726 778 } 727 779 … … 775 827 tcp_sock_notify_aconn(socket->sock_core); 776 828 fibril_mutex_unlock(&socket->lock); 829 } 830 831 static int tcp_sock_recv_fibril(void *arg) 832 { 833 tcp_sockdata_t *sock = (tcp_sockdata_t *)arg; 834 size_t data_len; 835 xflags_t xflags; 836 tcp_error_t trc; 837 838 log_msg(LVL_DEBUG, "tcp_sock_recv_fibril()"); 839 840 while (true) { 841 log_msg(LVL_DEBUG, "call tcp_uc_receive()"); 842 fibril_mutex_lock(&sock->recv_buffer_lock); 843 while (sock->recv_buffer_used != 0) 844 fibril_condvar_wait(&sock->recv_buffer_cv, 845 &sock->recv_buffer_lock); 846 847 trc = tcp_uc_receive(sock->conn, sock->recv_buffer, 848 TCP_SOCK_FRAGMENT_SIZE, &data_len, &xflags); 849 850 if (trc != TCP_EOK) { 851 sock->recv_error = trc; 852 fibril_condvar_broadcast(&sock->recv_buffer_cv); 853 fibril_mutex_unlock(&sock->recv_buffer_lock); 854 tcp_sock_notify_data(sock->sock_core); 855 break; 856 } 857 858 log_msg(LVL_DEBUG, "got data - broadcast recv_buffer_cv"); 859 860 sock->recv_buffer_used = data_len; 861 fibril_condvar_broadcast(&sock->recv_buffer_cv); 862 fibril_mutex_unlock(&sock->recv_buffer_lock); 863 tcp_sock_notify_data(sock->sock_core); 864 } 865 866 tcp_uc_delete(sock->conn); 867 868 return 0; 777 869 } 778 870 -
uspace/srv/net/tcp/tcp.c
ra8b8086 reb083ad 180 180 181 181 tcp_rqueue_init(); 182 tcp_rqueue_ thread_start();182 tcp_rqueue_fibril_start(); 183 183 184 184 tcp_ncsim_init(); 185 tcp_ncsim_ thread_start();185 tcp_ncsim_fibril_start(); 186 186 187 187 if (0) tcp_test(); -
uspace/srv/net/tcp/tcp_type.h
ra8b8086 reb083ad 39 39 #include <async.h> 40 40 #include <bool.h> 41 #include <fibril.h> 41 42 #include <fibril_synch.h> 42 43 #include <socket_core.h> … … 331 332 } tcp_client_t; 332 333 334 #define TCP_SOCK_FRAGMENT_SIZE 1024 335 333 336 typedef struct tcp_sockdata { 334 337 /** Lock */ … … 348 351 /** List of connections (from lconn) that are ready to be accepted */ 349 352 list_t ready; 353 /** Receiving fibril */ 354 fid_t recv_fibril; 355 uint8_t recv_buffer[TCP_SOCK_FRAGMENT_SIZE]; 356 size_t recv_buffer_used; 357 fibril_mutex_t recv_buffer_lock; 358 fibril_condvar_t recv_buffer_cv; 359 tcp_error_t recv_error; 350 360 } tcp_sockdata_t; 351 361 -
uspace/srv/net/tcp/test.c
ra8b8086 reb083ad 38 38 #include <errno.h> 39 39 #include <stdio.h> 40 #include < thread.h>40 #include <fibril.h> 41 41 #include <str.h> 42 42 #include "tcp_type.h" … … 47 47 #define RCV_BUF_SIZE 64 48 48 49 static voidtest_srv(void *arg)49 static int test_srv(void *arg) 50 50 { 51 51 tcp_conn_t *conn; … … 84 84 85 85 printf("test_srv() terminating\n"); 86 return 0; 86 87 } 87 88 88 static voidtest_cli(void *arg)89 static int test_cli(void *arg) 89 90 { 90 91 tcp_conn_t *conn; … … 112 113 printf("C: User close...\n"); 113 114 tcp_uc_close(conn); 115 116 return 0; 114 117 } 115 118 116 119 void tcp_test(void) 117 120 { 118 thread_id_t srv_tid; 119 thread_id_t cli_tid; 120 int rc; 121 fid_t srv_fid; 122 fid_t cli_fid; 121 123 122 124 printf("tcp_test()\n"); … … 125 127 126 128 if (0) { 127 rc = thread_create(test_srv, NULL, "test_srv", &srv_tid);128 if ( rc != EOK) {129 printf("Failed to create server thread.\n");129 srv_fid = fibril_create(test_srv, NULL); 130 if (srv_fid == 0) { 131 printf("Failed to create server fibril.\n"); 130 132 return; 131 133 } 134 135 fibril_add_ready(srv_fid); 132 136 } 133 137 134 138 if (0) { 135 rc = thread_create(test_cli, NULL, "test_cli", &cli_tid);136 if ( rc != EOK) {137 printf("Failed to create client thread.\n");139 cli_fid = fibril_create(test_cli, NULL); 140 if (cli_fid == 0) { 141 printf("Failed to create client fibril.\n"); 138 142 return; 139 143 } 144 145 fibril_add_ready(cli_fid); 140 146 } 141 147 } -
uspace/srv/net/udp/sock.c
ra8b8086 reb083ad 43 43 #include <ipc/services.h> 44 44 #include <ipc/socket.h> 45 #include <net/modules.h>46 45 #include <net/socket.h> 47 46 #include <ns.h> … … 134 133 assert(sock_core != NULL); 135 134 sock->sock_core = sock_core; 136 137 138 refresh_answer(&answer, NULL); 135 139 136 SOCKET_SET_SOCKET_ID(answer, sock_id); 140 137 141 138 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, FRAGMENT_SIZE); 142 139 SOCKET_SET_HEADER_SIZE(answer, sizeof(udp_header_t)); 143 answer_call(callid, EOK, &answer, 3); 140 async_answer_3(callid, EOK, IPC_GET_ARG1(answer), 141 IPC_GET_ARG2(answer), IPC_GET_ARG3(answer)); 144 142 } 145 143 … … 369 367 } 370 368 } 371 372 refresh_answer(&answer, NULL);369 370 IPC_SET_ARG1(answer, 0); 373 371 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, FRAGMENT_SIZE); 374 answer_call(callid, EOK, &answer, 2); 372 async_answer_2(callid, EOK, IPC_GET_ARG1(answer), 373 IPC_GET_ARG2(answer)); 375 374 fibril_mutex_unlock(&socket->lock); 375 376 376 out: 377 377 if (addr != NULL) … … 486 486 487 487 log_msg(LVL_DEBUG, "read_data_length <- %zu", length); 488 IPC_SET_ARG2(answer, 0); 488 489 SOCKET_SET_READ_DATA_LENGTH(answer, length); 489 490 SOCKET_SET_ADDRESS_LENGTH(answer, sizeof(addr)); 490 answer_call(callid, EOK, &answer, 3); 491 491 async_answer_3(callid, EOK, IPC_GET_ARG1(answer), 492 IPC_GET_ARG2(answer), IPC_GET_ARG3(answer)); 493 492 494 /* Push one fragment notification to client's queue */ 493 495 udp_sock_notify_data(sock_core);
Note:
See TracChangeset
for help on using the changeset viewer.
