Changes in uspace/lib/c/generic/inet/tcp.c [f9b2cb4c:1f2b07a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/inet/tcp.c
rf9b2cb4c r1f2b07a 44 44 static int tcp_conn_fibril(void *); 45 45 46 /** Incoming TCP connection info 47 * 48 * Used to pass information about incoming TCP connection to the connection 49 * fibril 50 */ 46 /** Incoming TCP connection info */ 51 47 typedef struct { 52 /** Listener who received the connection */53 48 tcp_listener_t *lst; 54 /** Incoming connection */55 49 tcp_conn_t *conn; 56 50 } tcp_in_conn_t; 57 51 58 /** Create callback connection from TCP service.59 *60 * @param tcp TCP service61 * @return EOK on success or negative error code62 */63 52 static int tcp_callback_create(tcp_t *tcp) 64 53 { … … 66 55 67 56 aid_t req = async_send_0(exch, TCP_CALLBACK_CREATE, NULL); 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 57 int rc = async_connect_to_me(exch, 0, 0, 0, tcp_cb_conn, tcp); 73 58 async_exchange_end(exch); 74 59 … … 82 67 } 83 68 84 /** Create TCP client instance.85 *86 * @param rtcp Place to store pointer to new TCP client87 * @return EOK on success, ENOMEM if out of memory, EIO if service88 * cannot be contacted89 */90 69 int tcp_create(tcp_t **rtcp) 91 70 { … … 112 91 } 113 92 114 tcp->sess = loc_service_connect( tcp_svcid, INTERFACE_TCP,93 tcp->sess = loc_service_connect(EXCHANGE_SERIALIZE, tcp_svcid, 115 94 IPC_FLAG_BLOCKING); 116 95 if (tcp->sess == NULL) { … … 132 111 } 133 112 134 /** Destroy TCP client instance.135 *136 * @param tcp TCP client137 */138 113 void tcp_destroy(tcp_t *tcp) 139 114 { … … 151 126 } 152 127 153 /** Create new TCP connection154 *155 * @param tcp TCP client instance156 * @param id Connection ID157 * @param cb Callbacks158 * @param arg Callback argument159 * @param rconn Place to store pointer to new connection160 *161 * @return EOK on success, ENOMEM if out of memory162 */163 128 static int tcp_conn_new(tcp_t *tcp, sysarg_t id, tcp_cb_t *cb, void *arg, 164 129 tcp_conn_t **rconn) … … 185 150 } 186 151 187 /** Create new TCP connection.188 *189 * Open a connection to the specified destination. This function returns190 * even before the connection is established (or not). When the connection191 * is established, @a cb->connected is called. If the connection fails,192 * @a cb->conn_failed is called. Alternatively, the caller can call193 * @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 and197 * port are optional. If local address is not specified, address selection198 * will take place. If local port number is not specified, a suitable199 * free dynamic port number will be allocated.200 *201 * @param tcp TCP client202 * @param epp Internet endpoint pair203 * @param cb Callbacks204 * @param arg Argument to callbacks205 * @param rconn Place to store pointer to new connection206 *207 * @return EOK on success or negative error code.208 */209 152 int tcp_conn_create(tcp_t *tcp, inet_ep2_t *epp, tcp_cb_t *cb, void *arg, 210 153 tcp_conn_t **rconn) … … 243 186 } 244 187 245 /** Destroy TCP connection.246 *247 * Destroy TCP connection. The caller should destroy all connections248 * he created before destroying the TCP client and before terminating.249 *250 * @param conn TCP connection251 */252 188 void tcp_conn_destroy(tcp_conn_t *conn) 253 189 { … … 267 203 } 268 204 269 /** Get connection based on its ID.270 *271 * @param tcp TCP client272 * @param id Connection ID273 * @param rconn Place to store pointer to connection274 *275 * @return EOK on success, EINVAL if no connection with the given ID exists276 */277 205 static int tcp_conn_get(tcp_t *tcp, sysarg_t id, tcp_conn_t **rconn) 278 206 { … … 287 215 } 288 216 289 /** Get the user/callback argument for a connection.290 *291 * @param conn TCP connection292 * @return User argument associated with connection293 */294 217 void *tcp_conn_userptr(tcp_conn_t *conn) 295 218 { … … 297 220 } 298 221 299 /** Create a TCP connection listener.300 *301 * A listener listens for connections on the set of endpoints specified302 * 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 connection304 * 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 address307 * or link to listen on. If it does not, the listener will listen on308 * all links/addresses.309 *310 * @param tcp TCP client311 * @param ep Internet endpoint312 * @param lcb Listener callbacks313 * @param larg Listener callback argument314 * @param cb Connection callbacks for every new connection315 * @param arg Connection argument for every new connection316 * @param rlst Place to store pointer to new listener317 *318 * @return EOK on success or negative error code319 */320 222 int tcp_listener_create(tcp_t *tcp, inet_ep_t *ep, tcp_listen_cb_t *lcb, 321 223 void *larg, tcp_cb_t *cb, void *arg, tcp_listener_t **rlst) … … 363 265 } 364 266 365 /** Destroy TCP connection listener.366 *367 * @param lst Listener368 */369 267 void tcp_listener_destroy(tcp_listener_t *lst) 370 268 { … … 384 282 } 385 283 386 /** Get TCP connection listener based on its ID.387 *388 * @param tcp TCP client389 * @param id Listener ID390 * @param rlst Place to store pointer to listener391 *392 * @return EOK on success, EINVAL if no listener with the given ID is found393 */394 284 static int tcp_listener_get(tcp_t *tcp, sysarg_t id, tcp_listener_t **rlst) 395 285 { … … 404 294 } 405 295 406 /** Get callback/user argument associated with listener.407 *408 * @param lst Listener409 * @return Callback/user argument410 */411 296 void *tcp_listener_userptr(tcp_listener_t *lst) 412 297 { … … 414 299 } 415 300 416 /** Wait until connection is either established or connection fails.417 *418 * Can be called after calling tcp_conn_create() to block until connection419 * either completes or fails. If the connection fails, EIO is returned.420 * In this case the connection still exists, but is in a failed421 * state.422 *423 * @param conn Connection424 * @return EOK if connection is established, EIO otherwise425 */426 301 int tcp_conn_wait_connected(tcp_conn_t *conn) 427 302 { … … 440 315 } 441 316 442 /** Send data over TCP connection.443 *444 * @param conn Connection445 * @param data Data446 * @param bytes Data size in bytes447 *448 * @return EOK on success or negative error code449 */450 317 int tcp_conn_send(tcp_conn_t *conn, const void *data, size_t bytes) 451 318 { … … 473 340 } 474 341 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 */ 342 482 343 int tcp_conn_send_fin(tcp_conn_t *conn) 483 344 { … … 491 352 } 492 353 493 /** Push connection.494 *495 * @param conn Connection496 * @return EOK on success or negative error code497 */498 354 int tcp_conn_push(tcp_conn_t *conn) 499 355 { … … 507 363 } 508 364 509 /** Reset connection.510 *511 * @param conn Connection512 * @return EOK on success or negative error code513 */514 365 int tcp_conn_reset(tcp_conn_t *conn) 515 366 { … … 523 374 } 524 375 525 /** Read received data from connection without blocking.526 *527 * If any received data is pending on the connection, up to @a bsize bytes528 * 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 data530 * is currently available or FIN is received. EOK is returned.531 *532 * If no received data is pending, returns EAGAIN.533 *534 * @param conn Connection535 * @param buf Buffer536 * @param bsize Buffer size537 * @param nrecv Place to store actual number of received bytes538 *539 * @return EOK on success, EAGAIN if no received data is pending, or other540 * negative error code in case of other error541 */542 376 int tcp_conn_recv(tcp_conn_t *conn, void *buf, size_t bsize, size_t *nrecv) 543 377 { … … 574 408 } 575 409 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) 410 int tcp_conn_recv_wait(tcp_conn_t *conn, void *buf, size_t bsize, size_t *nrecv) 592 411 { 593 412 async_exch_t *exch; … … 631 450 } 632 451 633 /** Connection established event.634 *635 * @param tcp TCP client636 * @param iid Call ID637 * @param icall Call data638 */639 452 static void tcp_ev_connected(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 640 453 { … … 659 472 } 660 473 661 /** Connection failed event.662 *663 * @param tcp TCP client664 * @param iid Call ID665 * @param icall Call data666 */667 474 static void tcp_ev_conn_failed(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 668 475 { … … 687 494 } 688 495 689 /** Connection reset event.690 *691 * @param tcp TCP client692 * @param iid Call ID693 * @param icall Call data694 */695 496 static void tcp_ev_conn_reset(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 696 497 { … … 715 516 } 716 517 717 /** Data available event.718 *719 * @param tcp TCP client720 * @param iid Call ID721 * @param icall Call data722 */723 518 static void tcp_ev_data(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 724 519 { … … 744 539 } 745 540 746 /** Urgent data event.747 *748 * @param tcp TCP client749 * @param iid Call ID750 * @param icall Call data751 */752 541 static void tcp_ev_urg_data(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 753 542 { … … 755 544 } 756 545 757 /** New connection event.758 *759 * @param tcp TCP client760 * @param iid Call ID761 * @param icall Call data762 */763 546 static void tcp_ev_new_conn(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 764 547 { … … 807 590 } 808 591 809 /** Callback connection handler.810 *811 * @param iid Connect call ID812 * @param icall Connect call data813 * @param arg Argument, TCP client814 */815 592 static void tcp_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 816 593 { … … 859 636 } 860 637 861 /** Fibril for handling incoming TCP connection in background. 862 * 863 * @param arg Argument, incoming connection information (@c tcp_in_conn_t) 864 */ 638 /** Fibril for handling incoming TCP connection in background */ 865 639 static int tcp_conn_fibril(void *arg) 866 640 {
Note:
See TracChangeset
for help on using the changeset viewer.