Changes in uspace/srv/net/tcp/service.c [1f2b07a:1d03e86] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tcp/service.c
r1f2b07a r1d03e86 27 27 */ 28 28 29 /** @addtogroup udp29 /** @addtogroup tcp 30 30 * @{ 31 31 */ … … 44 44 #include <loc.h> 45 45 #include <macros.h> 46 #include <mem.h> 46 47 #include <stdlib.h> 47 48 … … 53 54 #define NAME "tcp" 54 55 56 /** Maximum amount of data transferred in one send call */ 55 57 #define MAX_MSG_SIZE DATA_XFER_LIMIT 56 58 … … 67 69 static int tcp_cconn_create(tcp_client_t *, tcp_conn_t *, tcp_cconn_t **); 68 70 71 /** Connection callbacks to tie us to lower layer */ 69 72 static tcp_cb_t tcp_service_cb = { 70 73 .cstate_change = tcp_service_cstate_change, … … 72 75 }; 73 76 77 /** Sentinel connection callbacks to tie us to lower layer */ 74 78 static tcp_cb_t tcp_service_lst_cb = { 75 79 .cstate_change = tcp_service_lst_cstate_change, … … 77 81 }; 78 82 83 /** Connection state has changed. 84 * 85 * @param conn Connection 86 * @param arg Argument (not used) 87 * @param old_state Previous connection state 88 */ 79 89 static void tcp_service_cstate_change(tcp_conn_t *conn, void *arg, 80 90 tcp_cstate_t old_state) … … 108 118 } 109 119 120 /** Sentinel connection state has changed. 121 * 122 * @param conn Connection 123 * @param arg Argument (not used) 124 * @param old_state Previous connection state 125 */ 110 126 static void tcp_service_lst_cstate_change(tcp_conn_t *conn, void *arg, 111 127 tcp_cstate_t old_state) … … 169 185 } 170 186 187 /** Received data became available on connection. 188 * 189 * @param conn Connection 190 * @param arg Client connection 191 */ 171 192 static void tcp_service_recv_data(tcp_conn_t *conn, void *arg) 172 193 { … … 176 197 } 177 198 199 /** Send 'data' event to client. 200 * 201 * @param cconn Client connection 202 */ 178 203 static void tcp_ev_data(tcp_cconn_t *cconn) 179 204 { … … 192 217 } 193 218 219 /** Send 'connected' event to client. 220 * 221 * @param cconn Client connection 222 */ 194 223 static void tcp_ev_connected(tcp_cconn_t *cconn) 195 224 { … … 205 234 } 206 235 236 /** Send 'conn_failed' event to client. 237 * 238 * @param cconn Client connection 239 */ 207 240 static void tcp_ev_conn_failed(tcp_cconn_t *cconn) 208 241 { … … 218 251 } 219 252 253 /** Send 'conn_reset' event to client. 254 * 255 * @param cconn Client connection 256 */ 220 257 static void tcp_ev_conn_reset(tcp_cconn_t *cconn) 221 258 { … … 231 268 } 232 269 233 /** New incoming connection */ 270 /** Send 'new_conn' event to client. 271 * 272 * @param clst Client listener that received the connection 273 * @param cconn New client connection 274 */ 234 275 static void tcp_ev_new_conn(tcp_clst_t *clst, tcp_cconn_t *cconn) 235 276 { … … 246 287 } 247 288 289 /** Create client connection. 290 * 291 * This effectively adds a connection into a client's namespace. 292 * 293 * @param client TCP client 294 * @param conn Connection 295 * @param rcconn Place to store pointer to new client connection 296 * 297 * @return EOK on success or ENOMEM if out of memory 298 */ 248 299 static int tcp_cconn_create(tcp_client_t *client, tcp_conn_t *conn, 249 300 tcp_cconn_t **rcconn) … … 272 323 } 273 324 325 /** Destroy client connection. 326 * 327 * @param cconn Client connection 328 */ 274 329 static void tcp_cconn_destroy(tcp_cconn_t *cconn) 275 330 { … … 278 333 } 279 334 335 /** Create client listener. 336 * 337 * Create client listener based on sentinel connection. 338 * XXX Implement actual listener in protocol core 339 * 340 * @param client TCP client 341 * @param conn Sentinel connection 342 * @param rclst Place to store pointer to new client listener 343 * 344 * @return EOK on success or ENOMEM if out of memory 345 */ 280 346 static int tcp_clistener_create(tcp_client_t *client, tcp_conn_t *conn, 281 347 tcp_clst_t **rclst) … … 304 370 } 305 371 372 /** Destroy client listener. 373 * 374 * @param clst Client listener 375 */ 306 376 static void tcp_clistener_destroy(tcp_clst_t *clst) 307 377 { … … 310 380 } 311 381 382 /** Get client connection by ID. 383 * 384 * @param client Client 385 * @param id Client connection ID 386 * @param rcconn Place to store pointer to client connection 387 * 388 * @return EOK on success, ENOENT if no client connection with the given ID 389 * is found. 390 */ 312 391 static int tcp_cconn_get(tcp_client_t *client, sysarg_t id, 313 392 tcp_cconn_t **rcconn) … … 323 402 } 324 403 404 /** Get client listener by ID. 405 * 406 * @param client Client 407 * @param id Client connection ID 408 * @param rclst Place to store pointer to client listener 409 * 410 * @return EOK on success, ENOENT if no client listener with the given ID 411 * is found. 412 */ 325 413 static int tcp_clistener_get(tcp_client_t *client, sysarg_t id, 326 414 tcp_clst_t **rclst) … … 336 424 } 337 425 338 426 /** Create connection. 427 * 428 * Handle client request to create connection (with parameters unmarshalled). 429 * 430 * @param client TCP client 431 * @param epp Endpoint pair 432 * @param rconn_id Place to store ID of new connection 433 * 434 * @return EOK on success or negative error code 435 */ 339 436 static int tcp_conn_create_impl(tcp_client_t *client, inet_ep2_t *epp, 340 437 sysarg_t *rconn_id) … … 376 473 } 377 474 475 /** Destroy connection. 476 * 477 * Handle client request to destroy connection (with parameters unmarshalled). 478 * 479 * @param client TCP client 480 * @param conn_id Connection ID 481 * @return EOK on success, ENOENT if no such connection is found 482 */ 378 483 static int tcp_conn_destroy_impl(tcp_client_t *client, sysarg_t conn_id) 379 484 { … … 393 498 } 394 499 500 /** Create listener. 501 * 502 * Handle client request to create listener (with parameters unmarshalled). 503 * 504 * @param client TCP client 505 * @param ep Endpoint 506 * @param rlst_id Place to store ID of new listener 507 * 508 * @return EOK on success or negative error code 509 */ 395 510 static int tcp_listener_create_impl(tcp_client_t *client, inet_ep_t *ep, 396 511 sysarg_t *rlst_id) … … 430 545 } 431 546 547 /** Destroy listener. 548 * 549 * Handle client request to destroy listener (with parameters unmarshalled). 550 * 551 * @param client TCP client 552 * @param lst_id Listener ID 553 * 554 * @return EOK on success, ENOENT if no such listener is found 555 */ 432 556 static int tcp_listener_destroy_impl(tcp_client_t *client, sysarg_t lst_id) 433 557 { … … 446 570 } 447 571 572 /** Send FIN. 573 * 574 * Handle client request to send FIN (with parameters unmarshalled). 575 * 576 * @param client TCP client 577 * @param conn_id Connection ID 578 * 579 * @return EOK on success or negative error code 580 */ 448 581 static int tcp_conn_send_fin_impl(tcp_client_t *client, sysarg_t conn_id) 449 582 { … … 462 595 } 463 596 597 /** Push connection. 598 * 599 * Handle client request to push connection (with parameters unmarshalled). 600 * 601 * @param client TCP client 602 * @param conn_id Connection ID 603 * 604 * @return EOK on success or negative error code 605 */ 464 606 static int tcp_conn_push_impl(tcp_client_t *client, sysarg_t conn_id) 465 607 { … … 478 620 } 479 621 622 /** Reset connection. 623 * 624 * Handle client request to reset connection (with parameters unmarshalled). 625 * 626 * @param client TCP client 627 * @param conn_id Connection ID 628 * 629 * @return EOK on success or negative error code 630 */ 480 631 static int tcp_conn_reset_impl(tcp_client_t *client, sysarg_t conn_id) 481 632 { … … 493 644 } 494 645 646 /** Send data over connection.. 647 * 648 * Handle client request to send data (with parameters unmarshalled). 649 * 650 * @param client TCP client 651 * @param conn_id Connection ID 652 * @param data Data buffer 653 * @param size Data size in bytes 654 * 655 * @return EOK on success or negative error code 656 */ 495 657 static int tcp_conn_send_impl(tcp_client_t *client, sysarg_t conn_id, 496 658 void *data, size_t size) … … 510 672 } 511 673 674 /** Receive data from connection. 675 * 676 * Handle client request to receive data (with parameters unmarshalled). 677 * 678 * @param client TCP client 679 * @param conn_id Connection ID 680 * @param data Data buffer 681 * @param size Buffer size in bytes 682 * @param nrecv Place to store actual number of bytes received 683 * 684 * @return EOK on success or negative error code 685 */ 512 686 static int tcp_conn_recv_impl(tcp_client_t *client, sysarg_t conn_id, 513 687 void *data, size_t size, size_t *nrecv) … … 540 714 } 541 715 716 /** Create client callback session. 717 * 718 * Handle client request to create callback session. 719 * 720 * @param client TCP client 721 * @param iid Async request ID 722 * @param icall Async request data 723 */ 542 724 static void tcp_callback_create_srv(tcp_client_t *client, ipc_callid_t iid, 543 725 ipc_call_t *icall) … … 555 737 } 556 738 739 /** Create connection. 740 * 741 * Handle client request to create connection. 742 * 743 * @param client TCP client 744 * @param iid Async request ID 745 * @param icall Async request data 746 */ 557 747 static void tcp_conn_create_srv(tcp_client_t *client, ipc_callid_t iid, 558 748 ipc_call_t *icall) … … 594 784 } 595 785 786 /** Destroy connection. 787 * 788 * Handle client request to destroy connection. 789 * 790 * @param client TCP client 791 * @param iid Async request ID 792 * @param icall Async request data 793 */ 596 794 static void tcp_conn_destroy_srv(tcp_client_t *client, ipc_callid_t iid, 597 795 ipc_call_t *icall) … … 607 805 } 608 806 807 /** Create listener. 808 * 809 * Handle client request to create listener. 810 * 811 * @param client TCP client 812 * @param iid Async request ID 813 * @param icall Async request data 814 */ 609 815 static void tcp_listener_create_srv(tcp_client_t *client, ipc_callid_t iid, 610 816 ipc_call_t *icall) … … 646 852 } 647 853 854 /** Destroy listener. 855 * 856 * Handle client request to destroy listener. 857 * 858 * @param client TCP client 859 * @param iid Async request ID 860 * @param icall Async request data 861 */ 648 862 static void tcp_listener_destroy_srv(tcp_client_t *client, ipc_callid_t iid, 649 863 ipc_call_t *icall) … … 659 873 } 660 874 875 /** Send FIN. 876 * 877 * Handle client request to send FIN. 878 * 879 * @param client TCP client 880 * @param iid Async request ID 881 * @param icall Async request data 882 */ 661 883 static void tcp_conn_send_fin_srv(tcp_client_t *client, ipc_callid_t iid, 662 884 ipc_call_t *icall) … … 672 894 } 673 895 896 /** Push connection. 897 * 898 * Handle client request to push connection. 899 * 900 * @param client TCP client 901 * @param iid Async request ID 902 * @param icall Async request data 903 */ 674 904 static void tcp_conn_push_srv(tcp_client_t *client, ipc_callid_t iid, 675 905 ipc_call_t *icall) … … 685 915 } 686 916 917 /** Reset connection. 918 * 919 * Handle client request to reset connection. 920 * 921 * @param client TCP client 922 * @param iid Async request ID 923 * @param icall Async request data 924 */ 687 925 static void tcp_conn_reset_srv(tcp_client_t *client, ipc_callid_t iid, 688 926 ipc_call_t *icall) … … 698 936 } 699 937 938 /** Send data via connection.. 939 * 940 * Handle client request to send data via connection. 941 * 942 * @param client TCP client 943 * @param iid Async request ID 944 * @param icall Async request data 945 */ 700 946 static void tcp_conn_send_srv(tcp_client_t *client, ipc_callid_t iid, 701 947 ipc_call_t *icall) … … 750 996 } 751 997 998 /** Read received data from connection without blocking. 999 * 1000 * Handle client request to read received data via connection without blocking. 1001 * 1002 * @param client TCP client 1003 * @param iid Async request ID 1004 * @param icall Async request data 1005 */ 752 1006 static void tcp_conn_recv_srv(tcp_client_t *client, ipc_callid_t iid, 753 1007 ipc_call_t *icall) … … 798 1052 } 799 1053 1054 /** Read received data from connection with blocking. 1055 * 1056 * Handle client request to read received data via connection with blocking. 1057 * 1058 * @param client TCP client 1059 * @param iid Async request ID 1060 * @param icall Async request data 1061 */ 800 1062 static void tcp_conn_recv_wait_srv(tcp_client_t *client, ipc_callid_t iid, 801 1063 ipc_call_t *icall) … … 851 1113 } 852 1114 853 #include <mem.h> 854 1115 /** Initialize TCP client structure. 1116 * 1117 * @param client TCP client 1118 */ 855 1119 static void tcp_client_init(tcp_client_t *client) 856 1120 { … … 861 1125 } 862 1126 1127 /** Finalize TCP client structure. 1128 * 1129 * @param client TCP client 1130 */ 863 1131 static void tcp_client_fini(tcp_client_t *client) 864 1132 { 865 1133 tcp_cconn_t *cconn; 866 size_tn;1134 unsigned long n; 867 1135 868 1136 n = list_count(&client->cconn); 869 1137 if (n != 0) { 870 log_msg(LOG_DEFAULT, LVL_WARN, "Client with % zu active "1138 log_msg(LOG_DEFAULT, LVL_WARN, "Client with %lu active " 871 1139 "connections closed session", n); 872 1140 … … 882 1150 n = list_count(&client->clst); 883 1151 if (n != 0) { 884 log_msg(LOG_DEFAULT, LVL_WARN, "Client with % zu active "1152 log_msg(LOG_DEFAULT, LVL_WARN, "Client with %lu active " 885 1153 "listeners closed session", n); 886 1154 /* XXX Destroy listeners */ … … 891 1159 } 892 1160 1161 /** Handle TCP client connection. 1162 * 1163 * @param iid Connect call ID 1164 * @param icall Connect call data 1165 * @param arg Connection argument 1166 */ 893 1167 static void tcp_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 894 1168 { … … 961 1235 } 962 1236 1237 /** Initialize TCP service. 1238 * 1239 * @return EOK on success or negative error code. 1240 */ 963 1241 int tcp_service_init(void) 964 1242 { … … 966 1244 service_id_t sid; 967 1245 968 async_set_ client_connection(tcp_client_conn);1246 async_set_fallback_port_handler(tcp_client_conn, NULL); 969 1247 970 1248 rc = loc_server_register(NAME);
Note:
See TracChangeset
for help on using the changeset viewer.