Changes in uspace/srv/net/udp/sock.c [1038a9c:32d19f7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/udp/sock.c
r1038a9c 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 {
Note:
See TracChangeset
for help on using the changeset viewer.