Changes in uspace/srv/net/udp/sock.c [32d19f7:1038a9c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/udp/sock.c
r32d19f7 r1038a9c 51 51 #include "ucall.h" 52 52 53 #define FRAGMENT_SIZE 1024 54 53 55 /** Free ports pool start. */ 54 56 #define UDP_FREE_PORTS_START 1025 … … 61 63 62 64 static void udp_sock_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg); 63 static int udp_sock_recv_fibril(void *arg);64 65 65 66 int udp_sock_init(void) … … 81 82 82 83 socket = (udp_sockdata_t *)sock_core->specific_data; 83 (void)socket; 84 85 /* XXX We need to force the receive fibril to quit */ 84 assert(socket->assoc != NULL); 85 udp_uc_destroy(socket->assoc); 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 UDP_FRAGMENT_SIZE, 0, 0, 1);93 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 120 115 rc = udp_uc_create(&sock->assoc); 121 116 if (rc != EOK) { 117 udp_uc_destroy(sock->assoc); 122 118 free(sock); 123 119 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 120 return; 133 121 } … … 136 124 rc = socket_create(&client->sockets, client->sess, sock, &sock_id); 137 125 if (rc != EOK) { 138 fibril_destroy(sock->recv_fibril);139 udp_uc_destroy(sock->assoc);140 free(sock);141 126 async_answer_0(callid, rc); 142 127 return; 143 128 } 144 145 fibril_add_ready(sock->recv_fibril);146 129 147 130 sock_core = socket_cores_find(&client->sockets, sock_id); … … 151 134 SOCKET_SET_SOCKET_ID(answer, sock_id); 152 135 153 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, UDP_FRAGMENT_SIZE);136 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, FRAGMENT_SIZE); 154 137 SOCKET_SET_HEADER_SIZE(answer, sizeof(udp_header_t)); 155 138 async_answer_3(callid, EOK, IPC_GET_ARG1(answer), … … 222 205 } 223 206 207 udp_sock_notify_data(sock_core); 208 224 209 log_msg(LVL_DEBUG, " - success"); 225 210 async_answer_0(callid, rc); … … 260 245 ipc_callid_t wcallid; 261 246 size_t length; 262 uint8_t buffer[ UDP_FRAGMENT_SIZE];247 uint8_t buffer[FRAGMENT_SIZE]; 263 248 udp_error_t urc; 264 249 int rc; … … 307 292 goto out; 308 293 } 294 295 udp_sock_notify_data(sock_core); 309 296 } 310 297 … … 343 330 } 344 331 345 if (length > UDP_FRAGMENT_SIZE)346 length = UDP_FRAGMENT_SIZE;332 if (length > FRAGMENT_SIZE) 333 length = FRAGMENT_SIZE; 347 334 348 335 rc = async_data_write_finalize(wcallid, buffer, length); … … 380 367 381 368 IPC_SET_ARG1(answer, 0); 382 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, UDP_FRAGMENT_SIZE);369 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, FRAGMENT_SIZE); 383 370 async_answer_2(callid, EOK, IPC_GET_ARG1(answer), 384 371 IPC_GET_ARG2(answer)); … … 399 386 ipc_call_t answer; 400 387 ipc_callid_t rcallid; 388 uint8_t buffer[FRAGMENT_SIZE]; 401 389 size_t data_len; 390 xflags_t xflags; 402 391 udp_error_t urc; 392 struct sockaddr_in addr; 403 393 udp_sock_t rsock; 404 struct sockaddr_in addr;405 394 int rc; 406 395 … … 427 416 (void)flags; 428 417 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); 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); 444 421 445 422 switch (urc) { … … 460 437 log_msg(LVL_DEBUG, "**** udp_uc_receive -> %d", rc); 461 438 if (rc != EOK) { 462 fibril_mutex_unlock(&socket->recv_buffer_lock);463 439 fibril_mutex_unlock(&socket->lock); 464 440 async_answer_0(callid, rc); … … 474 450 log_msg(LVL_DEBUG, "addr read receive"); 475 451 if (!async_data_read_receive(&rcallid, &addr_length)) { 476 fibril_mutex_unlock(&socket->recv_buffer_lock);477 452 fibril_mutex_unlock(&socket->lock); 478 453 async_answer_0(callid, EINVAL); … … 486 461 rc = async_data_read_finalize(rcallid, &addr, addr_length); 487 462 if (rc != EOK) { 488 fibril_mutex_unlock(&socket->recv_buffer_lock);489 463 fibril_mutex_unlock(&socket->lock); 490 464 async_answer_0(callid, EINVAL); … … 495 469 log_msg(LVL_DEBUG, "data read receive"); 496 470 if (!async_data_read_receive(&rcallid, &length)) { 497 fibril_mutex_unlock(&socket->recv_buffer_lock);498 471 fibril_mutex_unlock(&socket->lock); 499 472 async_answer_0(callid, EINVAL); … … 505 478 506 479 log_msg(LVL_DEBUG, "data read finalize"); 507 rc = async_data_read_finalize(rcallid, socket->recv_buffer, length);480 rc = async_data_read_finalize(rcallid, buffer, length); 508 481 509 482 if (length < data_len && rc == EOK) … … 516 489 async_answer_3(callid, EOK, IPC_GET_ARG1(answer), 517 490 IPC_GET_ARG2(answer), IPC_GET_ARG3(answer)); 518 519 socket->recv_buffer_used = 0; 520 521 fibril_condvar_broadcast(&socket->recv_buffer_cv); 522 fibril_mutex_unlock(&socket->recv_buffer_lock); 491 492 /* Push one fragment notification to client's queue */ 493 udp_sock_notify_data(sock_core); 523 494 fibril_mutex_unlock(&socket->lock); 524 495 } … … 567 538 } 568 539 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 611 540 static void udp_sock_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 612 541 {
Note:
See TracChangeset
for help on using the changeset viewer.