Changes in uspace/lib/c/generic/inet/tcp.c [1f2b07a:f9b2cb4c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/inet/tcp.c
r1f2b07a rf9b2cb4c 44 44 static int tcp_conn_fibril(void *); 45 45 46 /** Incoming TCP connection info */ 46 /** Incoming TCP connection info 47 * 48 * Used to pass information about incoming TCP connection to the connection 49 * fibril 50 */ 47 51 typedef struct { 52 /** Listener who received the connection */ 48 53 tcp_listener_t *lst; 54 /** Incoming connection */ 49 55 tcp_conn_t *conn; 50 56 } tcp_in_conn_t; 51 57 58 /** Create callback connection from TCP service. 59 * 60 * @param tcp TCP service 61 * @return EOK on success or negative error code 62 */ 52 63 static int tcp_callback_create(tcp_t *tcp) 53 64 { … … 55 66 56 67 aid_t req = async_send_0(exch, TCP_CALLBACK_CREATE, NULL); 57 int rc = async_connect_to_me(exch, 0, 0, 0, tcp_cb_conn, tcp); 68 69 port_id_t port; 70 int rc = async_create_callback_port(exch, INTERFACE_TCP_CB, 0, 0, 71 tcp_cb_conn, tcp, &port); 72 58 73 async_exchange_end(exch); 59 74 … … 67 82 } 68 83 84 /** Create TCP client instance. 85 * 86 * @param rtcp Place to store pointer to new TCP client 87 * @return EOK on success, ENOMEM if out of memory, EIO if service 88 * cannot be contacted 89 */ 69 90 int tcp_create(tcp_t **rtcp) 70 91 { … … 91 112 } 92 113 93 tcp->sess = loc_service_connect( EXCHANGE_SERIALIZE, tcp_svcid,114 tcp->sess = loc_service_connect(tcp_svcid, INTERFACE_TCP, 94 115 IPC_FLAG_BLOCKING); 95 116 if (tcp->sess == NULL) { … … 111 132 } 112 133 134 /** Destroy TCP client instance. 135 * 136 * @param tcp TCP client 137 */ 113 138 void tcp_destroy(tcp_t *tcp) 114 139 { … … 126 151 } 127 152 153 /** Create new TCP connection 154 * 155 * @param tcp TCP client instance 156 * @param id Connection ID 157 * @param cb Callbacks 158 * @param arg Callback argument 159 * @param rconn Place to store pointer to new connection 160 * 161 * @return EOK on success, ENOMEM if out of memory 162 */ 128 163 static int tcp_conn_new(tcp_t *tcp, sysarg_t id, tcp_cb_t *cb, void *arg, 129 164 tcp_conn_t **rconn) … … 150 185 } 151 186 187 /** Create new TCP connection. 188 * 189 * Open a connection to the specified destination. This function returns 190 * even before the connection is established (or not). When the connection 191 * is established, @a cb->connected is called. If the connection fails, 192 * @a cb->conn_failed is called. Alternatively, the caller can call 193 * @c tcp_conn_wait_connected() to wait for connection to complete or fail. 194 * Other callbacks are available to monitor the changes in connection state. 195 * 196 * @a epp must specify the remote address and port. Both local address and 197 * port are optional. If local address is not specified, address selection 198 * will take place. If local port number is not specified, a suitable 199 * free dynamic port number will be allocated. 200 * 201 * @param tcp TCP client 202 * @param epp Internet endpoint pair 203 * @param cb Callbacks 204 * @param arg Argument to callbacks 205 * @param rconn Place to store pointer to new connection 206 * 207 * @return EOK on success or negative error code. 208 */ 152 209 int tcp_conn_create(tcp_t *tcp, inet_ep2_t *epp, tcp_cb_t *cb, void *arg, 153 210 tcp_conn_t **rconn) … … 186 243 } 187 244 245 /** Destroy TCP connection. 246 * 247 * Destroy TCP connection. The caller should destroy all connections 248 * he created before destroying the TCP client and before terminating. 249 * 250 * @param conn TCP connection 251 */ 188 252 void tcp_conn_destroy(tcp_conn_t *conn) 189 253 { … … 203 267 } 204 268 269 /** Get connection based on its ID. 270 * 271 * @param tcp TCP client 272 * @param id Connection ID 273 * @param rconn Place to store pointer to connection 274 * 275 * @return EOK on success, EINVAL if no connection with the given ID exists 276 */ 205 277 static int tcp_conn_get(tcp_t *tcp, sysarg_t id, tcp_conn_t **rconn) 206 278 { … … 215 287 } 216 288 289 /** Get the user/callback argument for a connection. 290 * 291 * @param conn TCP connection 292 * @return User argument associated with connection 293 */ 217 294 void *tcp_conn_userptr(tcp_conn_t *conn) 218 295 { … … 220 297 } 221 298 299 /** Create a TCP connection listener. 300 * 301 * A listener listens for connections on the set of endpoints specified 302 * by @a ep. Each time a new incoming connection is established, 303 * @a lcb->new_conn is called (and passed @a larg). Also, the new connection 304 * will have callbacks set to @a cb and argument to @a arg. 305 * 306 * @a ep must specify a valid port number. @a ep may specify an address 307 * or link to listen on. If it does not, the listener will listen on 308 * all links/addresses. 309 * 310 * @param tcp TCP client 311 * @param ep Internet endpoint 312 * @param lcb Listener callbacks 313 * @param larg Listener callback argument 314 * @param cb Connection callbacks for every new connection 315 * @param arg Connection argument for every new connection 316 * @param rlst Place to store pointer to new listener 317 * 318 * @return EOK on success or negative error code 319 */ 222 320 int tcp_listener_create(tcp_t *tcp, inet_ep_t *ep, tcp_listen_cb_t *lcb, 223 321 void *larg, tcp_cb_t *cb, void *arg, tcp_listener_t **rlst) … … 265 363 } 266 364 365 /** Destroy TCP connection listener. 366 * 367 * @param lst Listener 368 */ 267 369 void tcp_listener_destroy(tcp_listener_t *lst) 268 370 { … … 282 384 } 283 385 386 /** Get TCP connection listener based on its ID. 387 * 388 * @param tcp TCP client 389 * @param id Listener ID 390 * @param rlst Place to store pointer to listener 391 * 392 * @return EOK on success, EINVAL if no listener with the given ID is found 393 */ 284 394 static int tcp_listener_get(tcp_t *tcp, sysarg_t id, tcp_listener_t **rlst) 285 395 { … … 294 404 } 295 405 406 /** Get callback/user argument associated with listener. 407 * 408 * @param lst Listener 409 * @return Callback/user argument 410 */ 296 411 void *tcp_listener_userptr(tcp_listener_t *lst) 297 412 { … … 299 414 } 300 415 416 /** Wait until connection is either established or connection fails. 417 * 418 * Can be called after calling tcp_conn_create() to block until connection 419 * either completes or fails. If the connection fails, EIO is returned. 420 * In this case the connection still exists, but is in a failed 421 * state. 422 * 423 * @param conn Connection 424 * @return EOK if connection is established, EIO otherwise 425 */ 301 426 int tcp_conn_wait_connected(tcp_conn_t *conn) 302 427 { … … 315 440 } 316 441 442 /** Send data over TCP connection. 443 * 444 * @param conn Connection 445 * @param data Data 446 * @param bytes Data size in bytes 447 * 448 * @return EOK on success or negative error code 449 */ 317 450 int tcp_conn_send(tcp_conn_t *conn, const void *data, size_t bytes) 318 451 { … … 340 473 } 341 474 342 475 /** Send FIN. 476 * 477 * Send FIN, indicating no more data will be send over the connection. 478 * 479 * @param conn Connection 480 * @return EOK on success or negative error code 481 */ 343 482 int tcp_conn_send_fin(tcp_conn_t *conn) 344 483 { … … 352 491 } 353 492 493 /** Push connection. 494 * 495 * @param conn Connection 496 * @return EOK on success or negative error code 497 */ 354 498 int tcp_conn_push(tcp_conn_t *conn) 355 499 { … … 363 507 } 364 508 509 /** Reset connection. 510 * 511 * @param conn Connection 512 * @return EOK on success or negative error code 513 */ 365 514 int tcp_conn_reset(tcp_conn_t *conn) 366 515 { … … 374 523 } 375 524 525 /** Read received data from connection without blocking. 526 * 527 * If any received data is pending on the connection, up to @a bsize bytes 528 * are copied to @a buf and the acutal number is stored in @a *nrecv. 529 * The entire buffer of @a bsize bytes is filled except when less data 530 * is currently available or FIN is received. EOK is returned. 531 * 532 * If no received data is pending, returns EAGAIN. 533 * 534 * @param conn Connection 535 * @param buf Buffer 536 * @param bsize Buffer size 537 * @param nrecv Place to store actual number of received bytes 538 * 539 * @return EOK on success, EAGAIN if no received data is pending, or other 540 * negative error code in case of other error 541 */ 376 542 int tcp_conn_recv(tcp_conn_t *conn, void *buf, size_t bsize, size_t *nrecv) 377 543 { … … 408 574 } 409 575 410 int tcp_conn_recv_wait(tcp_conn_t *conn, void *buf, size_t bsize, size_t *nrecv) 576 /** Read received data from connection with blocking. 577 * 578 * Wait for @a bsize bytes of data to be received and copy them to 579 * @a buf. Less data may be returned if FIN is received on the connection. 580 * The actual If any received data is written to @a *nrecv and EOK 581 * is returned on success. 582 * 583 * @param conn Connection 584 * @param buf Buffer 585 * @param bsize Buffer size 586 * @param nrecv Place to store actual number of received bytes 587 * 588 * @return EOK on success or negative error code 589 */ 590 int tcp_conn_recv_wait(tcp_conn_t *conn, void *buf, size_t bsize, 591 size_t *nrecv) 411 592 { 412 593 async_exch_t *exch; … … 450 631 } 451 632 633 /** Connection established event. 634 * 635 * @param tcp TCP client 636 * @param iid Call ID 637 * @param icall Call data 638 */ 452 639 static void tcp_ev_connected(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 453 640 { … … 472 659 } 473 660 661 /** Connection failed event. 662 * 663 * @param tcp TCP client 664 * @param iid Call ID 665 * @param icall Call data 666 */ 474 667 static void tcp_ev_conn_failed(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 475 668 { … … 494 687 } 495 688 689 /** Connection reset event. 690 * 691 * @param tcp TCP client 692 * @param iid Call ID 693 * @param icall Call data 694 */ 496 695 static void tcp_ev_conn_reset(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 497 696 { … … 516 715 } 517 716 717 /** Data available event. 718 * 719 * @param tcp TCP client 720 * @param iid Call ID 721 * @param icall Call data 722 */ 518 723 static void tcp_ev_data(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 519 724 { … … 539 744 } 540 745 746 /** Urgent data event. 747 * 748 * @param tcp TCP client 749 * @param iid Call ID 750 * @param icall Call data 751 */ 541 752 static void tcp_ev_urg_data(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 542 753 { … … 544 755 } 545 756 757 /** New connection event. 758 * 759 * @param tcp TCP client 760 * @param iid Call ID 761 * @param icall Call data 762 */ 546 763 static void tcp_ev_new_conn(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 547 764 { … … 590 807 } 591 808 809 /** Callback connection handler. 810 * 811 * @param iid Connect call ID 812 * @param icall Connect call data 813 * @param arg Argument, TCP client 814 */ 592 815 static void tcp_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 593 816 { … … 636 859 } 637 860 638 /** Fibril for handling incoming TCP connection in background */ 861 /** Fibril for handling incoming TCP connection in background. 862 * 863 * @param arg Argument, incoming connection information (@c tcp_in_conn_t) 864 */ 639 865 static int tcp_conn_fibril(void *arg) 640 866 {
Note:
See TracChangeset
for help on using the changeset viewer.