Changes in uspace/srv/net/udp/sock.c [f4a27304:db81577] in mainline
- File:
-
- 1 edited
-
uspace/srv/net/udp/sock.c (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/udp/sock.c
rf4a27304 rdb81577 88 88 static void udp_sock_notify_data(socket_core_t *sock_core) 89 89 { 90 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_sock_notify_data(%d)", sock_core->socket_id);90 log_msg(LVL_DEBUG, "udp_sock_notify_data(%d)", sock_core->socket_id); 91 91 async_exch_t *exch = async_exchange_begin(sock_core->sess); 92 async_msg_5(exch, NET_SOCKET_RECEIVED, (sysarg_t) sock_core->socket_id,92 async_msg_5(exch, NET_SOCKET_RECEIVED, (sysarg_t)sock_core->socket_id, 93 93 UDP_FRAGMENT_SIZE, 0, 0, 1); 94 94 async_exchange_end(exch); … … 103 103 ipc_call_t answer; 104 104 105 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_sock_socket()");105 log_msg(LVL_DEBUG, "udp_sock_socket()"); 106 106 sock = calloc(1, sizeof(udp_sockdata_t)); 107 107 if (sock == NULL) { … … 159 159 static void udp_sock_bind(udp_client_t *client, ipc_callid_t callid, ipc_call_t call) 160 160 { 161 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_bind()"); 162 log_msg(LOG_DEFAULT, LVL_DEBUG, " - async_data_write_accept"); 163 164 struct sockaddr_in6 *addr6 = NULL; 165 size_t addr_len; 166 int rc = async_data_write_accept((void **) &addr6, false, 0, 0, 0, &addr_len); 161 int rc; 162 struct sockaddr_in *addr; 163 size_t addr_size; 164 socket_core_t *sock_core; 165 udp_sockdata_t *socket; 166 udp_sock_t fsock; 167 udp_error_t urc; 168 169 log_msg(LVL_DEBUG, "udp_sock_bind()"); 170 log_msg(LVL_DEBUG, " - async_data_write_accept"); 171 172 addr = NULL; 173 174 rc = async_data_write_accept((void **) &addr, false, 0, 0, 0, &addr_size); 167 175 if (rc != EOK) { 168 176 async_answer_0(callid, rc); 169 return;170 }171 172 if ((addr_len != sizeof(struct sockaddr_in)) &&173 (addr_len != sizeof(struct sockaddr_in6))) {174 async_answer_0(callid, EINVAL);175 177 goto out; 176 178 } 177 178 struct sockaddr_in *addr = (struct sockaddr_in *) addr6; 179 180 log_msg(LOG_DEFAULT, LVL_DEBUG, " - call socket_bind"); 181 179 180 log_msg(LVL_DEBUG, " - call socket_bind"); 182 181 rc = socket_bind(&client->sockets, &gsock, SOCKET_GET_SOCKET_ID(call), 183 addr 6, addr_len, UDP_FREE_PORTS_START, UDP_FREE_PORTS_END,182 addr, addr_size, UDP_FREE_PORTS_START, UDP_FREE_PORTS_END, 184 183 last_used_port); 185 184 if (rc != EOK) { … … 187 186 goto out; 188 187 } 189 190 log_msg(LOG_DEFAULT, LVL_DEBUG, " - call socket_cores_find"); 191 192 socket_core_t *sock_core = socket_cores_find(&client->sockets, 193 SOCKET_GET_SOCKET_ID(call)); 188 189 if (addr_size != sizeof(struct sockaddr_in)) { 190 async_answer_0(callid, EINVAL); 191 goto out; 192 } 193 194 log_msg(LVL_DEBUG, " - call socket_cores_find"); 195 sock_core = socket_cores_find(&client->sockets, SOCKET_GET_SOCKET_ID(call)); 194 196 if (sock_core == NULL) { 195 197 async_answer_0(callid, ENOENT); 196 198 goto out; 197 199 } 198 199 udp_sockdata_t *socket = 200 (udp_sockdata_t *) sock_core->specific_data; 201 202 udp_sock_t fsocket; 203 204 fsocket.port = sock_core->port; 205 206 switch (addr->sin_family) { 207 case AF_INET: 208 inet_sockaddr_in_addr(addr, &fsocket.addr); 209 break; 210 case AF_INET6: 211 inet_sockaddr_in6_addr(addr6, &fsocket.addr); 212 break; 213 default: 214 async_answer_0(callid, EINVAL); 215 goto out; 216 } 217 218 udp_error_t urc = udp_uc_set_local(socket->assoc, &fsocket); 219 200 201 socket = (udp_sockdata_t *)sock_core->specific_data; 202 203 fsock.addr.ipv4 = uint32_t_be2host(addr->sin_addr.s_addr); 204 fsock.port = sock_core->port; 205 urc = udp_uc_set_local(socket->assoc, &fsock); 206 220 207 switch (urc) { 221 208 case UDP_EOK: … … 234 221 assert(false); 235 222 } 236 237 log_msg(L OG_DEFAULT, LVL_DEBUG, " - success");223 224 log_msg(LVL_DEBUG, " - success"); 238 225 async_answer_0(callid, rc); 239 240 226 out: 241 if (addr 6!= NULL)242 free(addr 6);227 if (addr != NULL) 228 free(addr); 243 229 } 244 230 245 231 static void udp_sock_listen(udp_client_t *client, ipc_callid_t callid, ipc_call_t call) 246 232 { 247 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_sock_listen()");233 log_msg(LVL_DEBUG, "udp_sock_listen()"); 248 234 async_answer_0(callid, ENOTSUP); 249 235 } … … 251 237 static void udp_sock_connect(udp_client_t *client, ipc_callid_t callid, ipc_call_t call) 252 238 { 253 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_sock_connect()");239 log_msg(LVL_DEBUG, "udp_sock_connect()"); 254 240 async_answer_0(callid, ENOTSUP); 255 241 } … … 257 243 static void udp_sock_accept(udp_client_t *client, ipc_callid_t callid, ipc_call_t call) 258 244 { 259 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_sock_accept()");245 log_msg(LVL_DEBUG, "udp_sock_accept()"); 260 246 async_answer_0(callid, ENOTSUP); 261 247 } … … 263 249 static void udp_sock_sendto(udp_client_t *client, ipc_callid_t callid, ipc_call_t call) 264 250 { 265 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_send()"); 266 267 uint8_t *buffer = calloc(UDP_FRAGMENT_SIZE, 1); 268 if (buffer == NULL) { 269 async_answer_0(callid, ENOMEM); 270 return; 271 } 272 273 struct sockaddr_in6 *addr6 = NULL; 251 int socket_id; 252 int fragments; 253 int index; 274 254 struct sockaddr_in *addr; 275 udp_sock_t fsocket; 276 udp_sock_t *fsocket_ptr; 277 255 size_t addr_size; 256 socket_core_t *sock_core; 257 udp_sockdata_t *socket; 258 udp_sock_t fsock, *fsockp; 259 ipc_call_t answer; 260 ipc_callid_t wcallid; 261 size_t length; 262 uint8_t buffer[UDP_FRAGMENT_SIZE]; 263 udp_error_t urc; 264 int rc; 265 266 log_msg(LVL_DEBUG, "udp_sock_send()"); 267 268 addr = NULL; 269 278 270 if (IPC_GET_IMETHOD(call) == NET_SOCKET_SENDTO) { 279 size_t addr_len; 280 int rc = async_data_write_accept((void **) &addr6, false, 281 0, 0, 0, &addr_len); 271 rc = async_data_write_accept((void **) &addr, false, 272 0, 0, 0, &addr_size); 282 273 if (rc != EOK) { 283 274 async_answer_0(callid, rc); 284 275 goto out; 285 276 } 286 287 if ((addr_len != sizeof(struct sockaddr_in)) && 288 (addr_len != sizeof(struct sockaddr_in6))) { 277 278 if (addr_size != sizeof(struct sockaddr_in)) { 289 279 async_answer_0(callid, EINVAL); 290 280 goto out; 291 281 } 292 293 addr = (struct sockaddr_in *) addr6; 294 295 switch (addr->sin_family) { 296 case AF_INET: 297 inet_sockaddr_in_addr(addr, &fsocket.addr); 298 break; 299 case AF_INET6: 300 inet_sockaddr_in6_addr(addr6, &fsocket.addr); 301 break; 302 default: 303 async_answer_0(callid, EINVAL); 304 goto out; 305 } 306 307 fsocket.port = uint16_t_be2host(addr->sin_port); 308 fsocket_ptr = &fsocket; 309 } else 310 fsocket_ptr = NULL; 311 312 int socket_id = SOCKET_GET_SOCKET_ID(call); 313 282 283 fsock.addr.ipv4 = uint32_t_be2host(addr->sin_addr.s_addr); 284 fsock.port = uint16_t_be2host(addr->sin_port); 285 fsockp = &fsock; 286 } else { 287 fsockp = NULL; 288 } 289 290 socket_id = SOCKET_GET_SOCKET_ID(call); 291 fragments = SOCKET_GET_DATA_FRAGMENTS(call); 314 292 SOCKET_GET_FLAGS(call); 315 316 socket_core_t *sock_core = 317 socket_cores_find(&client->sockets, socket_id); 293 294 sock_core = socket_cores_find(&client->sockets, socket_id); 318 295 if (sock_core == NULL) { 319 296 async_answer_0(callid, ENOTSOCK); 320 297 goto out; 321 298 } 322 323 udp_sockdata_t *socket = 324 (udp_sockdata_t *) sock_core->specific_data; 325 326 if (sock_core->port <= 0) { 299 300 if (sock_core->port == 0) { 327 301 /* Implicitly bind socket to port */ 328 int rc = socket_bind_free_port(&gsock, sock_core, 329 UDP_FREE_PORTS_START, UDP_FREE_PORTS_END, last_used_port); 302 rc = socket_bind(&client->sockets, &gsock, SOCKET_GET_SOCKET_ID(call), 303 addr, addr_size, UDP_FREE_PORTS_START, UDP_FREE_PORTS_END, 304 last_used_port); 330 305 if (rc != EOK) { 331 306 async_answer_0(callid, rc); 332 307 goto out; 333 308 } 334 335 assert(sock_core->port > 0); 336 337 udp_error_t urc = udp_uc_set_local_port(socket->assoc, 338 sock_core->port); 339 340 if (urc != UDP_EOK) { 341 // TODO: better error handling 342 async_answer_0(callid, EINTR); 343 goto out; 344 } 345 346 last_used_port = sock_core->port; 347 } 348 309 } 310 311 socket = (udp_sockdata_t *)sock_core->specific_data; 349 312 fibril_mutex_lock(&socket->lock); 350 351 if ( inet_addr_is_any(&socket->assoc->ident.local.addr)) {313 314 if (socket->assoc->ident.local.addr.ipv4 == UDP_IPV4_ANY) { 352 315 /* Determine local IP address */ 353 inet_addr_t loc_addr; 354 inet_addr_t rem_addr; 355 356 rem_addr = fsocket_ptr ? fsocket.addr : 357 socket->assoc->ident.foreign.addr; 358 359 int rc = inet_get_srcaddr(&rem_addr, 0, &loc_addr); 316 inet_addr_t loc_addr, rem_addr; 317 318 rem_addr.ipv4 = fsockp ? fsock.addr.ipv4 : 319 socket->assoc->ident.foreign.addr.ipv4; 320 321 rc = inet_get_srcaddr(&rem_addr, 0, &loc_addr); 360 322 if (rc != EOK) { 361 323 fibril_mutex_unlock(&socket->lock); 362 324 async_answer_0(callid, rc); 363 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_sock_sendto: Failed to "325 log_msg(LVL_DEBUG, "udp_sock_sendto: Failed to " 364 326 "determine local address."); 365 goto out; 366 } 367 368 socket->assoc->ident.local.addr = loc_addr; 369 } 370 327 return; 328 } 329 330 socket->assoc->ident.local.addr.ipv4 = loc_addr.ipv4; 331 log_msg(LVL_DEBUG, "Local IP address is %x", 332 socket->assoc->ident.local.addr.ipv4); 333 } 334 335 371 336 assert(socket->assoc != NULL); 372 373 int fragments = SOCKET_GET_DATA_FRAGMENTS(call); 374 for (int index = 0; index < fragments; index++) { 375 ipc_callid_t wcallid; 376 size_t length; 377 337 338 for (index = 0; index < fragments; index++) { 378 339 if (!async_data_write_receive(&wcallid, &length)) { 379 340 fibril_mutex_unlock(&socket->lock); … … 381 342 goto out; 382 343 } 383 344 384 345 if (length > UDP_FRAGMENT_SIZE) 385 346 length = UDP_FRAGMENT_SIZE; 386 387 intrc = async_data_write_finalize(wcallid, buffer, length);347 348 rc = async_data_write_finalize(wcallid, buffer, length); 388 349 if (rc != EOK) { 389 350 fibril_mutex_unlock(&socket->lock); … … 391 352 goto out; 392 353 } 393 394 udp_error_t urc = 395 udp_uc_send(socket->assoc, fsocket_ptr, buffer, length, 0); 396 354 355 urc = udp_uc_send(socket->assoc, fsockp, buffer, length, 0); 356 397 357 switch (urc) { 398 358 case UDP_EOK: 399 359 rc = EOK; 400 360 break; 401 case UDP_ENORES:402 rc = ENO MEM;403 break; 404 case UDP_EUNSPEC:405 rc = E INVAL;406 break; 407 case UDP_ENOROUTE:408 rc = E IO;409 break; 361 /* case TCP_ENOTEXIST: 362 rc = ENOTCONN; 363 break; 364 case TCP_ECLOSING: 365 rc = ENOTCONN; 366 break; 367 case TCP_ERESET: 368 rc = ECONNABORTED; 369 break;*/ 410 370 default: 411 371 assert(false); 412 372 } 413 373 414 374 if (rc != EOK) { 415 375 fibril_mutex_unlock(&socket->lock); … … 418 378 } 419 379 } 420 421 ipc_call_t answer;422 380 423 381 IPC_SET_ARG1(answer, 0); … … 428 386 429 387 out: 430 if (addr6 != NULL) 431 free(addr6); 432 433 free(buffer); 388 if (addr != NULL) 389 free(addr); 434 390 } 435 391 436 392 static void udp_sock_recvfrom(udp_client_t *client, ipc_callid_t callid, ipc_call_t call) 437 393 { 438 log_msg(LOG_DEFAULT, LVL_DEBUG, "%p: udp_sock_recv[from]()", client); 439 440 int socket_id = SOCKET_GET_SOCKET_ID(call); 441 442 socket_core_t *sock_core = 443 socket_cores_find(&client->sockets, socket_id); 394 int socket_id; 395 int flags; 396 size_t addr_length, length; 397 socket_core_t *sock_core; 398 udp_sockdata_t *socket; 399 ipc_call_t answer; 400 ipc_callid_t rcallid; 401 size_t data_len; 402 udp_error_t urc; 403 udp_sock_t rsock; 404 struct sockaddr_in addr; 405 int rc; 406 407 log_msg(LVL_DEBUG, "%p: udp_sock_recv[from]()", client); 408 409 socket_id = SOCKET_GET_SOCKET_ID(call); 410 flags = SOCKET_GET_FLAGS(call); 411 412 sock_core = socket_cores_find(&client->sockets, socket_id); 444 413 if (sock_core == NULL) { 445 414 async_answer_0(callid, ENOTSOCK); 446 415 return; 447 416 } 448 449 udp_sockdata_t *socket = 450 (udp_sockdata_t *) sock_core->specific_data; 451 417 418 socket = (udp_sockdata_t *)sock_core->specific_data; 452 419 fibril_mutex_lock(&socket->lock); 453 420 454 421 if (socket->assoc == NULL) { 455 422 fibril_mutex_unlock(&socket->lock); … … 457 424 return; 458 425 } 459 460 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_recvfrom(): lock recv_buffer lock"); 461 426 427 (void)flags; 428 429 log_msg(LVL_DEBUG, "udp_sock_recvfrom(): lock recv_buffer lock"); 462 430 fibril_mutex_lock(&socket->recv_buffer_lock); 463 464 while ((socket->recv_buffer_used == 0) && 465 (socket->recv_error == UDP_EOK)) { 466 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_recvfrom(): wait for cv"); 431 while (socket->recv_buffer_used == 0 && socket->recv_error == UDP_EOK) { 432 log_msg(LVL_DEBUG, "udp_sock_recvfrom(): wait for cv"); 467 433 fibril_condvar_wait(&socket->recv_buffer_cv, 468 434 &socket->recv_buffer_lock); 469 435 } 470 471 log_msg(LOG_DEFAULT, LVL_DEBUG, "Got data in sock recv_buffer"); 472 473 size_t data_len = socket->recv_buffer_used; 474 udp_error_t urc = socket->recv_error; 475 476 log_msg(LOG_DEFAULT, LVL_DEBUG, "**** recv data_len=%zu", data_len); 477 478 int rc; 479 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); 444 480 445 switch (urc) { 481 446 case UDP_EOK: … … 492 457 assert(false); 493 458 } 494 495 log_msg(LOG_DEFAULT, LVL_DEBUG, "**** udp_uc_receive -> %d", rc); 496 459 460 log_msg(LVL_DEBUG, "**** udp_uc_receive -> %d", rc); 497 461 if (rc != EOK) { 498 462 fibril_mutex_unlock(&socket->recv_buffer_lock); … … 501 465 return; 502 466 } 503 504 ipc_callid_t rcallid; 505 size_t addr_size = 0; 506 467 507 468 if (IPC_GET_IMETHOD(call) == NET_SOCKET_RECVFROM) { 508 /* Fill address */ 509 udp_sock_t *rsock = &socket->recv_fsock; 510 struct sockaddr_in addr; 511 struct sockaddr_in6 addr6; 512 size_t addr_length; 513 514 uint16_t addr_af = inet_addr_sockaddr_in(&rsock->addr, &addr, 515 &addr6); 516 517 switch (addr_af) { 518 case AF_INET: 519 addr.sin_port = host2uint16_t_be(rsock->port); 520 521 log_msg(LOG_DEFAULT, LVL_DEBUG, "addr read receive"); 522 if (!async_data_read_receive(&rcallid, &addr_length)) { 523 fibril_mutex_unlock(&socket->recv_buffer_lock); 524 fibril_mutex_unlock(&socket->lock); 525 async_answer_0(callid, EINVAL); 526 return; 527 } 528 529 if (addr_length > sizeof(addr)) 530 addr_length = sizeof(addr); 531 532 addr_size = sizeof(addr); 533 534 log_msg(LOG_DEFAULT, LVL_DEBUG, "addr read finalize"); 535 rc = async_data_read_finalize(rcallid, &addr, addr_length); 536 if (rc != EOK) { 537 fibril_mutex_unlock(&socket->recv_buffer_lock); 538 fibril_mutex_unlock(&socket->lock); 539 async_answer_0(callid, EINVAL); 540 return; 541 } 542 543 break; 544 case AF_INET6: 545 addr6.sin6_port = host2uint16_t_be(rsock->port); 546 547 log_msg(LOG_DEFAULT, LVL_DEBUG, "addr6 read receive"); 548 if (!async_data_read_receive(&rcallid, &addr_length)) { 549 fibril_mutex_unlock(&socket->recv_buffer_lock); 550 fibril_mutex_unlock(&socket->lock); 551 async_answer_0(callid, EINVAL); 552 return; 553 } 554 555 if (addr_length > sizeof(addr6)) 556 addr_length = sizeof(addr6); 557 558 addr_size = sizeof(addr6); 559 560 log_msg(LOG_DEFAULT, LVL_DEBUG, "addr6 read finalize"); 561 rc = async_data_read_finalize(rcallid, &addr6, addr_length); 562 if (rc != EOK) { 563 fibril_mutex_unlock(&socket->recv_buffer_lock); 564 fibril_mutex_unlock(&socket->lock); 565 async_answer_0(callid, EINVAL); 566 return; 567 } 568 569 break; 570 default: 469 /* Fill addr */ 470 addr.sin_family = AF_INET; 471 addr.sin_addr.s_addr = host2uint32_t_be(rsock.addr.ipv4); 472 addr.sin_port = host2uint16_t_be(rsock.port); 473 474 log_msg(LVL_DEBUG, "addr read receive"); 475 if (!async_data_read_receive(&rcallid, &addr_length)) { 571 476 fibril_mutex_unlock(&socket->recv_buffer_lock); 572 477 fibril_mutex_unlock(&socket->lock); … … 574 479 return; 575 480 } 576 } 577 578 log_msg(LOG_DEFAULT, LVL_DEBUG, "data read receive"); 579 580 size_t length; 481 482 if (addr_length > sizeof(addr)) 483 addr_length = sizeof(addr); 484 485 log_msg(LVL_DEBUG, "addr read finalize"); 486 rc = async_data_read_finalize(rcallid, &addr, addr_length); 487 if (rc != EOK) { 488 fibril_mutex_unlock(&socket->recv_buffer_lock); 489 fibril_mutex_unlock(&socket->lock); 490 async_answer_0(callid, EINVAL); 491 return; 492 } 493 } 494 495 log_msg(LVL_DEBUG, "data read receive"); 581 496 if (!async_data_read_receive(&rcallid, &length)) { 582 497 fibril_mutex_unlock(&socket->recv_buffer_lock); … … 585 500 return; 586 501 } 587 502 588 503 if (length > data_len) 589 504 length = data_len; 590 591 log_msg(LOG_DEFAULT, LVL_DEBUG, "data read finalize"); 592 505 506 log_msg(LVL_DEBUG, "data read finalize"); 593 507 rc = async_data_read_finalize(rcallid, socket->recv_buffer, length); 594 595 if ( (length < data_len) && (rc == EOK))508 509 if (length < data_len && rc == EOK) 596 510 rc = EOVERFLOW; 597 598 log_msg(LOG_DEFAULT, LVL_DEBUG, "read_data_length <- %zu", length); 599 600 ipc_call_t answer; 601 511 512 log_msg(LVL_DEBUG, "read_data_length <- %zu", length); 602 513 IPC_SET_ARG2(answer, 0); 603 514 SOCKET_SET_READ_DATA_LENGTH(answer, length); 604 SOCKET_SET_ADDRESS_LENGTH(answer, addr_size);515 SOCKET_SET_ADDRESS_LENGTH(answer, sizeof(addr)); 605 516 async_answer_3(callid, EOK, IPC_GET_ARG1(answer), 606 517 IPC_GET_ARG2(answer), IPC_GET_ARG3(answer)); 607 518 608 519 socket->recv_buffer_used = 0; 609 520 610 521 fibril_condvar_broadcast(&socket->recv_buffer_cv); 611 522 fibril_mutex_unlock(&socket->recv_buffer_lock); … … 615 526 static void udp_sock_close(udp_client_t *client, ipc_callid_t callid, ipc_call_t call) 616 527 { 617 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_sock_close()"); 618 int socket_id = SOCKET_GET_SOCKET_ID(call); 619 620 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_sock_close() - find core"); 621 socket_core_t *sock_core = 622 socket_cores_find(&client->sockets, socket_id); 528 int socket_id; 529 socket_core_t *sock_core; 530 udp_sockdata_t *socket; 531 int rc; 532 533 log_msg(LVL_DEBUG, "tcp_sock_close()"); 534 socket_id = SOCKET_GET_SOCKET_ID(call); 535 536 sock_core = socket_cores_find(&client->sockets, socket_id); 623 537 if (sock_core == NULL) { 624 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_sock_close() - core not found");625 538 async_answer_0(callid, ENOTSOCK); 626 539 return; 627 540 } 628 541 629 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_sock_close() - spec data"); 630 udp_sockdata_t *socket = 631 (udp_sockdata_t *) sock_core->specific_data; 632 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_sock_close() - lock socket"); 542 socket = (udp_sockdata_t *)sock_core->specific_data; 633 543 fibril_mutex_lock(&socket->lock); 634 544 635 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_sock_close() - lock socket buffer"); 636 fibril_mutex_lock(&socket->recv_buffer_lock); 637 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_close - set socket->sock_core = NULL"); 638 socket->sock_core = NULL; 639 fibril_mutex_unlock(&socket->recv_buffer_lock); 640 641 udp_uc_reset(socket->assoc); 642 643 int rc = socket_destroy(NULL, socket_id, &client->sockets, &gsock, 545 rc = socket_destroy(NULL, socket_id, &client->sockets, &gsock, 644 546 udp_free_sock_data); 645 547 if (rc != EOK) { 646 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_close - socket_destroy failed");647 548 fibril_mutex_unlock(&socket->lock); 648 549 async_answer_0(callid, rc); … … 650 551 } 651 552 652 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_close - broadcast recv_buffer_cv");653 fibril_condvar_broadcast(&socket->recv_buffer_cv);654 655 553 fibril_mutex_unlock(&socket->lock); 656 554 async_answer_0(callid, EOK); … … 659 557 static void udp_sock_getsockopt(udp_client_t *client, ipc_callid_t callid, ipc_call_t call) 660 558 { 661 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_sock_getsockopt()");559 log_msg(LVL_DEBUG, "udp_sock_getsockopt()"); 662 560 async_answer_0(callid, ENOTSUP); 663 561 } … … 665 563 static void udp_sock_setsockopt(udp_client_t *client, ipc_callid_t callid, ipc_call_t call) 666 564 { 667 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_sock_setsockopt()");565 log_msg(LVL_DEBUG, "udp_sock_setsockopt()"); 668 566 async_answer_0(callid, ENOTSUP); 669 567 } … … 676 574 size_t rcvd; 677 575 678 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_recv_fibril()"); 679 680 fibril_mutex_lock(&sock->recv_buffer_lock); 576 log_msg(LVL_DEBUG, "udp_sock_recv_fibril()"); 681 577 682 578 while (true) { 683 log_msg(LOG_DEFAULT, LVL_DEBUG, "[] wait for rcv buffer empty()"); 684 while ((sock->recv_buffer_used != 0) && (sock->sock_core != NULL)) { 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) { 685 582 fibril_condvar_wait(&sock->recv_buffer_cv, 686 583 &sock->recv_buffer_lock); 687 584 } 688 585 689 fibril_mutex_unlock(&sock->recv_buffer_lock); 690 691 log_msg(LOG_DEFAULT, LVL_DEBUG, "[] call udp_uc_receive()"); 586 log_msg(LVL_DEBUG, "[] call udp_uc_receive()"); 692 587 urc = udp_uc_receive(sock->assoc, sock->recv_buffer, 693 588 UDP_FRAGMENT_SIZE, &rcvd, &xflags, &sock->recv_fsock); 694 fibril_mutex_lock(&sock->recv_buffer_lock);695 589 sock->recv_error = urc; 696 590 697 log_msg(LOG_DEFAULT, LVL_DEBUG, "[] udp_uc_receive -> %d", urc); 698 699 if (sock->sock_core != NULL) 700 udp_sock_notify_data(sock->sock_core); 591 udp_sock_notify_data(sock->sock_core); 701 592 702 593 if (urc != UDP_EOK) { 703 log_msg(LOG_DEFAULT, LVL_DEBUG, "[] urc != UDP_EOK, break");704 594 fibril_condvar_broadcast(&sock->recv_buffer_cv); 705 595 fibril_mutex_unlock(&sock->recv_buffer_lock); … … 707 597 } 708 598 709 log_msg(L OG_DEFAULT, LVL_DEBUG, "[] got data - broadcast recv_buffer_cv");599 log_msg(LVL_DEBUG, "[] got data - broadcast recv_buffer_cv"); 710 600 711 601 sock->recv_buffer_used = rcvd; 602 fibril_mutex_unlock(&sock->recv_buffer_lock); 712 603 fibril_condvar_broadcast(&sock->recv_buffer_cv); 713 604 } 714 605 715 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_recv_fibril() exited loop");716 fibril_mutex_unlock(&sock->recv_buffer_lock);717 606 udp_uc_destroy(sock->assoc); 718 719 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_recv_fibril() terminated");720 607 721 608 return 0; … … 735 622 736 623 while (true) { 737 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_sock_connection: wait");624 log_msg(LVL_DEBUG, "udp_sock_connection: wait"); 738 625 callid = async_get_call(&call); 739 626 if (!IPC_GET_IMETHOD(call)) 740 627 break; 741 628 742 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_sock_connection: METHOD=%d",629 log_msg(LVL_DEBUG, "udp_sock_connection: METHOD=%d", 743 630 (int)IPC_GET_IMETHOD(call)); 744 631 … … 783 670 784 671 /* Clean up */ 785 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_sock_connection: Clean up");672 log_msg(LVL_DEBUG, "udp_sock_connection: Clean up"); 786 673 async_hangup(client.sess); 787 674 socket_cores_release(NULL, &client.sockets, &gsock, udp_free_sock_data);
Note:
See TracChangeset
for help on using the changeset viewer.
