Changeset 32d19f7 in mainline
- Timestamp:
- 2012-06-12T22:09:11Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- faba839
- Parents:
- 2689a0b
- Location:
- uspace
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/fibril.c
r2689a0b r32d19f7 286 286 } 287 287 288 /** Delete a fibril that has never run. 289 * 290 * Free resources of a fibril that has been created with fibril_create() 291 * but never readied using fibril_add_ready(). 292 * 293 * @param fid Pointer to the fibril structure of the fibril to be 294 * added. 295 */ 296 void fibril_destroy(fid_t fid) 297 { 298 fibril_t *fibril = (fibril_t *) fid; 299 300 free(fibril->stack); 301 fibril_teardown(fibril); 302 } 303 288 304 /** Add a fibril to the ready list. 289 305 * -
uspace/lib/c/include/fibril.h
r2689a0b r32d19f7 87 87 88 88 extern fid_t fibril_create(int (*func)(void *), void *arg); 89 extern void fibril_destroy(fid_t fid); 89 90 extern fibril_t *fibril_setup(void); 90 91 extern void fibril_teardown(fibril_t *f); -
uspace/srv/net/tcp/sock.c
r2689a0b r32d19f7 151 151 sock, sock_id); 152 152 153 if (rc != EOK) 153 if (rc != EOK) { 154 fibril_destroy(sock->recv_fibril); 155 sock->recv_fibril = 0; 154 156 return rc; 157 } 155 158 156 159 sock_core = socket_cores_find(&sock->client->sockets, *sock_id); -
uspace/srv/net/udp/sock.c
r2689a0b r32d19f7 51 51 #include "ucall.h" 52 52 53 #define FRAGMENT_SIZE 102454 55 53 /** Free ports pool start. */ 56 54 #define UDP_FREE_PORTS_START 1025 … … 63 61 64 62 static void udp_sock_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg); 63 static int udp_sock_recv_fibril(void *arg); 65 64 66 65 int udp_sock_init(void) … … 82 81 83 82 socket = (udp_sockdata_t *)sock_core->specific_data; 84 assert(socket->assoc != NULL); 85 udp_uc_destroy(socket->assoc); 83 (void)socket; 84 85 /* XXX We need to force the receive fibril to quit */ 86 86 } 87 87 … … 91 91 async_exch_t *exch = async_exchange_begin(sock_core->sess); 92 92 async_msg_5(exch, NET_SOCKET_RECEIVED, (sysarg_t)sock_core->socket_id, 93 FRAGMENT_SIZE, 0, 0, 1);93 UDP_FRAGMENT_SIZE, 0, 0, 1); 94 94 async_exchange_end(exch); 95 95 } … … 113 113 sock->client = client; 114 114 115 sock->recv_buffer_used = 0; 116 sock->recv_error = UDP_EOK; 117 fibril_mutex_initialize(&sock->recv_buffer_lock); 118 fibril_condvar_initialize(&sock->recv_buffer_cv); 119 115 120 rc = udp_uc_create(&sock->assoc); 116 121 if (rc != EOK) { 122 free(sock); 123 async_answer_0(callid, rc); 124 return; 125 } 126 127 sock->recv_fibril = fibril_create(udp_sock_recv_fibril, sock); 128 if (sock->recv_fibril == 0) { 129 udp_uc_destroy(sock->assoc); 130 free(sock); 131 async_answer_0(callid, ENOMEM); 132 return; 133 } 134 135 sock_id = SOCKET_GET_SOCKET_ID(call); 136 rc = socket_create(&client->sockets, client->sess, sock, &sock_id); 137 if (rc != EOK) { 138 fibril_destroy(sock->recv_fibril); 117 139 udp_uc_destroy(sock->assoc); 118 140 free(sock); … … 121 143 } 122 144 123 sock_id = SOCKET_GET_SOCKET_ID(call); 124 rc = socket_create(&client->sockets, client->sess, sock, &sock_id); 125 if (rc != EOK) { 126 async_answer_0(callid, rc); 127 return; 128 } 145 fibril_add_ready(sock->recv_fibril); 129 146 130 147 sock_core = socket_cores_find(&client->sockets, sock_id); … … 134 151 SOCKET_SET_SOCKET_ID(answer, sock_id); 135 152 136 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, FRAGMENT_SIZE);153 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, UDP_FRAGMENT_SIZE); 137 154 SOCKET_SET_HEADER_SIZE(answer, sizeof(udp_header_t)); 138 155 async_answer_3(callid, EOK, IPC_GET_ARG1(answer), … … 205 222 } 206 223 207 udp_sock_notify_data(sock_core);208 209 224 log_msg(LVL_DEBUG, " - success"); 210 225 async_answer_0(callid, rc); … … 245 260 ipc_callid_t wcallid; 246 261 size_t length; 247 uint8_t buffer[ FRAGMENT_SIZE];262 uint8_t buffer[UDP_FRAGMENT_SIZE]; 248 263 udp_error_t urc; 249 264 int rc; … … 292 307 goto out; 293 308 } 294 295 udp_sock_notify_data(sock_core);296 309 } 297 310 … … 330 343 } 331 344 332 if (length > FRAGMENT_SIZE)333 length = FRAGMENT_SIZE;345 if (length > UDP_FRAGMENT_SIZE) 346 length = UDP_FRAGMENT_SIZE; 334 347 335 348 rc = async_data_write_finalize(wcallid, buffer, length); … … 367 380 368 381 IPC_SET_ARG1(answer, 0); 369 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, FRAGMENT_SIZE);382 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, UDP_FRAGMENT_SIZE); 370 383 async_answer_2(callid, EOK, IPC_GET_ARG1(answer), 371 384 IPC_GET_ARG2(answer)); … … 386 399 ipc_call_t answer; 387 400 ipc_callid_t rcallid; 388 uint8_t buffer[FRAGMENT_SIZE];389 401 size_t data_len; 390 xflags_t xflags;391 402 udp_error_t urc; 403 udp_sock_t rsock; 392 404 struct sockaddr_in addr; 393 udp_sock_t rsock;394 405 int rc; 395 406 … … 416 427 (void)flags; 417 428 418 urc = udp_uc_receive(socket->assoc, buffer, FRAGMENT_SIZE, &data_len, 419 &xflags, &rsock); 420 log_msg(LVL_DEBUG, "**** udp_uc_receive done, data_len=%zu", data_len); 429 log_msg(LVL_DEBUG, "udp_sock_recvfrom(): lock recv_buffer lock"); 430 fibril_mutex_lock(&socket->recv_buffer_lock); 431 while (socket->recv_buffer_used == 0 && socket->recv_error == UDP_EOK) { 432 log_msg(LVL_DEBUG, "udp_sock_recvfrom(): wait for cv"); 433 fibril_condvar_wait(&socket->recv_buffer_cv, 434 &socket->recv_buffer_lock); 435 } 436 437 log_msg(LVL_DEBUG, "Got data in sock recv_buffer"); 438 439 rsock = socket->recv_fsock; 440 data_len = socket->recv_buffer_used; 441 urc = socket->recv_error; 442 443 log_msg(LVL_DEBUG, "**** recv data_len=%zu", data_len); 421 444 422 445 switch (urc) { … … 437 460 log_msg(LVL_DEBUG, "**** udp_uc_receive -> %d", rc); 438 461 if (rc != EOK) { 462 fibril_mutex_unlock(&socket->recv_buffer_lock); 439 463 fibril_mutex_unlock(&socket->lock); 440 464 async_answer_0(callid, rc); … … 450 474 log_msg(LVL_DEBUG, "addr read receive"); 451 475 if (!async_data_read_receive(&rcallid, &addr_length)) { 476 fibril_mutex_unlock(&socket->recv_buffer_lock); 452 477 fibril_mutex_unlock(&socket->lock); 453 478 async_answer_0(callid, EINVAL); … … 461 486 rc = async_data_read_finalize(rcallid, &addr, addr_length); 462 487 if (rc != EOK) { 488 fibril_mutex_unlock(&socket->recv_buffer_lock); 463 489 fibril_mutex_unlock(&socket->lock); 464 490 async_answer_0(callid, EINVAL); … … 469 495 log_msg(LVL_DEBUG, "data read receive"); 470 496 if (!async_data_read_receive(&rcallid, &length)) { 497 fibril_mutex_unlock(&socket->recv_buffer_lock); 471 498 fibril_mutex_unlock(&socket->lock); 472 499 async_answer_0(callid, EINVAL); … … 478 505 479 506 log_msg(LVL_DEBUG, "data read finalize"); 480 rc = async_data_read_finalize(rcallid, buffer, length);507 rc = async_data_read_finalize(rcallid, socket->recv_buffer, length); 481 508 482 509 if (length < data_len && rc == EOK) … … 489 516 async_answer_3(callid, EOK, IPC_GET_ARG1(answer), 490 517 IPC_GET_ARG2(answer), IPC_GET_ARG3(answer)); 491 492 /* Push one fragment notification to client's queue */ 493 udp_sock_notify_data(sock_core); 518 519 socket->recv_buffer_used = 0; 520 521 fibril_condvar_broadcast(&socket->recv_buffer_cv); 522 fibril_mutex_unlock(&socket->recv_buffer_lock); 494 523 fibril_mutex_unlock(&socket->lock); 495 524 } … … 538 567 } 539 568 569 static int udp_sock_recv_fibril(void *arg) 570 { 571 udp_sockdata_t *sock = (udp_sockdata_t *)arg; 572 udp_error_t urc; 573 xflags_t xflags; 574 size_t rcvd; 575 576 log_msg(LVL_DEBUG, "udp_sock_recv_fibril()"); 577 578 while (true) { 579 log_msg(LVL_DEBUG, "[] wait for rcv buffer empty()"); 580 fibril_mutex_lock(&sock->recv_buffer_lock); 581 while (sock->recv_buffer_used != 0) { 582 fibril_condvar_wait(&sock->recv_buffer_cv, 583 &sock->recv_buffer_lock); 584 } 585 586 log_msg(LVL_DEBUG, "[] call udp_uc_receive()"); 587 urc = udp_uc_receive(sock->assoc, sock->recv_buffer, 588 UDP_FRAGMENT_SIZE, &rcvd, &xflags, &sock->recv_fsock); 589 sock->recv_error = urc; 590 591 udp_sock_notify_data(sock->sock_core); 592 593 if (urc != UDP_EOK) { 594 fibril_condvar_broadcast(&sock->recv_buffer_cv); 595 fibril_mutex_unlock(&sock->recv_buffer_lock); 596 break; 597 } 598 599 log_msg(LVL_DEBUG, "[] got data - broadcast recv_buffer_cv"); 600 601 sock->recv_buffer_used = rcvd; 602 fibril_mutex_unlock(&sock->recv_buffer_lock); 603 fibril_condvar_broadcast(&sock->recv_buffer_cv); 604 } 605 606 udp_uc_destroy(sock->assoc); 607 608 return 0; 609 } 610 540 611 static void udp_sock_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 541 612 { -
uspace/srv/net/udp/udp.c
r2689a0b r32d19f7 73 73 printf(NAME ": UDP (User Datagram Protocol) service\n"); 74 74 75 rc = log_init(NAME, LVL_ WARN);75 rc = log_init(NAME, LVL_DEBUG); 76 76 if (rc != EOK) { 77 77 printf(NAME ": Failed to initialize log.\n"); -
uspace/srv/net/udp/udp_type.h
r2689a0b r32d19f7 36 36 #define UDP_TYPE_H 37 37 38 #include <fibril.h> 38 39 #include <fibril_synch.h> 39 40 #include <socket_core.h> 40 41 #include <sys/types.h> 42 43 #define UDP_FRAGMENT_SIZE 4096 44 41 45 42 46 typedef enum { … … 141 145 /** Connection */ 142 146 udp_assoc_t *assoc; 147 /** Receiving fibril */ 148 fid_t recv_fibril; 149 uint8_t recv_buffer[UDP_FRAGMENT_SIZE]; 150 size_t recv_buffer_used; 151 udp_sock_t recv_fsock; 152 fibril_mutex_t recv_buffer_lock; 153 fibril_condvar_t recv_buffer_cv; 154 udp_error_t recv_error; 143 155 } udp_sockdata_t; 144 156
Note:
See TracChangeset
for help on using the changeset viewer.