Changeset c3f7d37 in mainline for uspace/lib/c/generic/inet/tcp.c
- Timestamp:
- 2015-06-07T12:36:44Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 048cd69
- Parents:
- 5a5b087
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/inet/tcp.c
r5a5b087 rc3f7d37 41 41 #include <stdlib.h> 42 42 43 #include <stdio.h>44 45 43 static void tcp_cb_conn(ipc_callid_t, ipc_call_t *, void *); 46 44 static int tcp_conn_fibril(void *); … … 56 54 async_exch_t *exch = async_exchange_begin(tcp->sess); 57 55 58 printf("tcp_callback_create()\n");59 60 56 aid_t req = async_send_0(exch, TCP_CALLBACK_CREATE, NULL); 61 57 int rc = async_connect_to_me(exch, 0, 0, 0, tcp_cb_conn, tcp); … … 76 72 service_id_t tcp_svcid; 77 73 int rc; 78 79 printf("tcp_create()\n");80 74 81 75 tcp = calloc(1, sizeof(tcp_t)); … … 129 123 tcp_conn_t *conn; 130 124 131 printf("tcp_conn_new()\n");132 133 125 conn = calloc(1, sizeof(tcp_conn_t)); 134 126 if (conn == NULL) … … 157 149 sysarg_t conn_id; 158 150 159 printf("tcp_conn_create()\n");160 161 151 exch = async_exchange_begin(tcp->sess); 162 152 aid_t req = async_send_0(exch, TCP_CONN_CREATE, &answer); … … 192 182 async_exch_t *exch; 193 183 194 printf("tcp_conn_destroy()\n");195 196 184 if (conn == NULL) 197 185 return; … … 230 218 tcp_listener_t *lst; 231 219 ipc_call_t answer; 232 233 printf("tcp_listener_create()\n");234 220 235 221 lst = calloc(1, sizeof(tcp_listener_t)); … … 274 260 { 275 261 async_exch_t *exch; 276 277 printf("tcp_listener_destroy()\n");278 262 279 263 if (lst == NULL) … … 328 312 sysarg_t rc; 329 313 330 printf("tcp_conn_send()\n");331 332 314 exch = async_exchange_begin(conn->tcp->sess); 333 315 aid_t req = async_send_1(exch, TCP_CONN_SEND, conn->id, NULL); … … 355 337 async_exch_t *exch; 356 338 357 printf("tcp_conn_send_fin()\n");358 359 339 exch = async_exchange_begin(conn->tcp->sess); 360 340 sysarg_t rc = async_req_1_0(exch, TCP_CONN_SEND_FIN, conn->id); … … 368 348 async_exch_t *exch; 369 349 370 printf("tcp_conn_push()\n");371 372 350 exch = async_exchange_begin(conn->tcp->sess); 373 351 sysarg_t rc = async_req_1_0(exch, TCP_CONN_PUSH, conn->id); … … 381 359 async_exch_t *exch; 382 360 383 printf("tcp_conn_reset()\n");384 385 361 exch = async_exchange_begin(conn->tcp->sess); 386 362 sysarg_t rc = async_req_1_0(exch, TCP_CONN_RESET, conn->id); … … 395 371 ipc_call_t answer; 396 372 397 printf("tcp_conn_recv() bsize=%zu\n", bsize);398 399 373 fibril_mutex_lock(&conn->lock); 400 374 if (!conn->data_avail) { 401 printf("returning EAGAIN\n");402 375 fibril_mutex_unlock(&conn->lock); 403 376 return EAGAIN; … … 410 383 411 384 if (rc != EOK) { 412 printf("got rc = %d\n", rc);413 385 async_forget(req); 414 386 fibril_mutex_unlock(&conn->lock); … … 419 391 async_wait_for(req, &retval); 420 392 if (retval != EOK) { 421 printf("got rc = %d\n", rc);422 393 fibril_mutex_unlock(&conn->lock); 423 394 return retval; … … 434 405 ipc_call_t answer; 435 406 436 printf("tcp_conn_recv_wait() bsize=%zu\n", bsize);437 407 again: 438 408 fibril_mutex_lock(&conn->lock); 439 409 while (!conn->data_avail) { 440 printf("wait for data to be avail\n");441 410 fibril_condvar_wait(&conn->cv, &conn->lock); 442 411 } 443 412 444 printf("tcp_conn_recv_wait - get data\n");445 413 exch = async_exchange_begin(conn->tcp->sess); 446 414 aid_t req = async_send_1(exch, TCP_CONN_RECV_WAIT, conn->id, &answer); 447 415 int rc = async_data_read_start(exch, buf, bsize); 448 printf("tcp_conn_recv_wait - rc = %d\n", rc); 449 async_exchange_end(exch); 450 451 if (rc != EOK) { 452 printf("got rc=%d\n", rc); 416 async_exchange_end(exch); 417 418 if (rc != EOK) { 453 419 async_forget(req); 454 420 if (rc == EAGAIN) { … … 464 430 async_wait_for(req, &retval); 465 431 if (retval != EOK) { 466 printf("got retval != EOK\n");467 432 if (rc == EAGAIN) { 468 printf("rc == EAGAIN\n");469 433 conn->data_avail = false; 470 434 } … … 475 439 *nrecv = IPC_GET_ARG1(answer); 476 440 fibril_mutex_unlock(&conn->lock); 477 printf("tcp_conn_recv_wait: nrecv=%zu\n", *nrecv);478 printf("received: '");479 size_t i;480 for (i = 0; i < *nrecv; i++) {481 putchar((char)((char *)buf)[i]);482 }483 printf("'\n");484 441 return EOK; 485 442 } … … 491 448 int rc; 492 449 493 printf("tcp_ev_connected()\n");494 450 conn_id = IPC_GET_ARG1(*icall); 495 451 496 452 rc = tcp_conn_get(tcp, conn_id, &conn); 497 453 if (rc != EOK) { 498 printf("conn ID %zu not found\n",499 conn_id);500 454 async_answer_0(iid, ENOENT); 501 455 return; … … 516 470 int rc; 517 471 518 printf("tcp_ev_conn_failed()\n");519 472 conn_id = IPC_GET_ARG1(*icall); 520 473 521 474 rc = tcp_conn_get(tcp, conn_id, &conn); 522 475 if (rc != EOK) { 523 printf("conn ID %zu not found\n",524 conn_id);525 476 async_answer_0(iid, ENOENT); 526 477 return; … … 541 492 int rc; 542 493 543 printf("tcp_ev_conn_reset()\n");544 494 conn_id = IPC_GET_ARG1(*icall); 545 495 546 496 rc = tcp_conn_get(tcp, conn_id, &conn); 547 497 if (rc != EOK) { 548 printf("conn ID %zu not found\n",549 conn_id);550 498 async_answer_0(iid, ENOENT); 551 499 return; … … 566 514 int rc; 567 515 568 printf("tcp_ev_data()\n");569 516 conn_id = IPC_GET_ARG1(*icall); 570 517 571 518 rc = tcp_conn_get(tcp, conn_id, &conn); 572 519 if (rc != EOK) { 573 printf("conn ID %zu not found\n",574 conn_id);575 520 async_answer_0(iid, ENOENT); 576 521 return; … … 585 530 static void tcp_ev_urg_data(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 586 531 { 587 printf("tcp_ev_urg_data()\n");588 532 async_answer_0(iid, ENOTSUP); 589 533 } … … 599 543 int rc; 600 544 601 printf("tcp_ev_new_conn()\n");602 545 lst_id = IPC_GET_ARG1(*icall); 603 546 conn_id = IPC_GET_ARG2(*icall); 604 547 605 printf("new conn: lst_id=%zu conn_id=%zu\n", lst_id, conn_id);606 607 548 rc = tcp_listener_get(tcp, lst_id, &lst); 608 549 if (rc != EOK) { 609 printf("listener ID %zu not found\n",610 lst_id);611 550 async_answer_0(iid, ENOENT); 612 551 return; … … 615 554 rc = tcp_conn_new(tcp, conn_id, lst->cb, lst->cb_arg, &conn); 616 555 if (rc != EOK) { 617 printf("Failed creating new incoming connection.\n");618 556 async_answer_0(iid, ENOMEM); 619 557 return; … … 621 559 622 560 if (lst->lcb != NULL && lst->lcb->new_conn != NULL) { 623 printf("Creating connection fibril\n");624 561 cinfo = calloc(1, sizeof(tcp_in_conn_t)); 625 562 if (cinfo == NULL) { 626 printf("Failed creating new incoming connection info.\n");627 563 async_answer_0(iid, ENOMEM); 628 564 return; … … 634 570 fid = fibril_create(tcp_conn_fibril, cinfo); 635 571 if (fid == 0) { 636 printf("Error creating connection fibril.\n");637 572 async_answer_0(iid, ENOMEM); 638 573 } … … 649 584 650 585 async_answer_0(iid, EOK); 651 652 printf("tcp_cb_conn()\n");653 586 654 587 while (true) { … … 656 589 ipc_callid_t callid = async_get_call(&call); 657 590 658 printf("tcp_cb_conn() - msg %d\n",659 (int)IPC_GET_IMETHOD(call));660 591 if (!IPC_GET_IMETHOD(call)) { 661 592 /* TODO: Handle hangup */ … … 694 625 tcp_in_conn_t *cinfo = (tcp_in_conn_t *)arg; 695 626 696 printf("tcp_conn_fibril: begin\n");697 627 cinfo->lst->lcb->new_conn(cinfo->lst, cinfo->conn); 698 printf("tcp_conn_fibril: end\n");699 628 tcp_conn_destroy(cinfo->conn); 700 629
Note:
See TracChangeset
for help on using the changeset viewer.