Changeset ff381a7 in mainline for uspace/lib/c/generic/inet/tcp.c


Ignore:
Timestamp:
2015-11-02T20:54:19Z (8 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d8513177
Parents:
3feeab2 (diff), 5265eea4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/inet/tcp.c

    r3feeab2 rff381a7  
    4444static int tcp_conn_fibril(void *);
    4545
    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 */
    4751typedef struct {
     52        /** Listener who received the connection */
    4853        tcp_listener_t *lst;
     54        /** Incoming connection */
    4955        tcp_conn_t *conn;
    5056} tcp_in_conn_t;
    5157
     58/** Create callback connection from TCP service.
     59 *
     60 * @param tcp TCP service
     61 * @return EOK on success or negative error code
     62 */
    5263static int tcp_callback_create(tcp_t *tcp)
    5364{
     
    5566
    5667        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       
    5873        async_exchange_end(exch);
    5974
     
    6782}
    6883
     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 */
    6990int tcp_create(tcp_t **rtcp)
    7091{
     
    91112        }
    92113
    93         tcp->sess = loc_service_connect(EXCHANGE_SERIALIZE, tcp_svcid,
     114        tcp->sess = loc_service_connect(tcp_svcid, INTERFACE_TCP,
    94115            IPC_FLAG_BLOCKING);
    95116        if (tcp->sess == NULL) {
     
    111132}
    112133
     134/** Destroy TCP client instance.
     135 *
     136 * @param tcp TCP client
     137 */
    113138void tcp_destroy(tcp_t *tcp)
    114139{
     
    126151}
    127152
     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 */
    128163static int tcp_conn_new(tcp_t *tcp, sysarg_t id, tcp_cb_t *cb, void *arg,
    129164    tcp_conn_t **rconn)
     
    150185}
    151186
     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 */
    152209int tcp_conn_create(tcp_t *tcp, inet_ep2_t *epp, tcp_cb_t *cb, void *arg,
    153210    tcp_conn_t **rconn)
     
    186243}
    187244
     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 */
    188252void tcp_conn_destroy(tcp_conn_t *conn)
    189253{
     
    203267}
    204268
     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 */
    205277static int tcp_conn_get(tcp_t *tcp, sysarg_t id, tcp_conn_t **rconn)
    206278{
     
    215287}
    216288
     289/** Get the user/callback argument for a connection.
     290 *
     291 * @param conn TCP connection
     292 * @return User argument associated with connection
     293 */
    217294void *tcp_conn_userptr(tcp_conn_t *conn)
    218295{
     
    220297}
    221298
     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 */
    222320int tcp_listener_create(tcp_t *tcp, inet_ep_t *ep, tcp_listen_cb_t *lcb,
    223321    void *larg, tcp_cb_t *cb, void *arg, tcp_listener_t **rlst)
     
    265363}
    266364
     365/** Destroy TCP connection listener.
     366 *
     367 * @param lst Listener
     368 */
    267369void tcp_listener_destroy(tcp_listener_t *lst)
    268370{
     
    282384}
    283385
     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 */
    284394static int tcp_listener_get(tcp_t *tcp, sysarg_t id, tcp_listener_t **rlst)
    285395{
     
    294404}
    295405
     406/** Get callback/user argument associated with listener.
     407 *
     408 * @param lst Listener
     409 * @return Callback/user argument
     410 */
    296411void *tcp_listener_userptr(tcp_listener_t *lst)
    297412{
     
    299414}
    300415
     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 */
    301426int tcp_conn_wait_connected(tcp_conn_t *conn)
    302427{
     
    315440}
    316441
     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 */
    317450int tcp_conn_send(tcp_conn_t *conn, const void *data, size_t bytes)
    318451{
     
    340473}
    341474
    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 */
    343482int tcp_conn_send_fin(tcp_conn_t *conn)
    344483{
     
    352491}
    353492
     493/** Push connection.
     494 *
     495 * @param conn Connection
     496 * @return EOK on success or negative error code
     497 */
    354498int tcp_conn_push(tcp_conn_t *conn)
    355499{
     
    363507}
    364508
     509/** Reset connection.
     510 *
     511 * @param conn Connection
     512 * @return EOK on success or negative error code
     513 */
    365514int tcp_conn_reset(tcp_conn_t *conn)
    366515{
     
    374523}
    375524
     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 */
    376542int tcp_conn_recv(tcp_conn_t *conn, void *buf, size_t bsize, size_t *nrecv)
    377543{
     
    408574}
    409575
    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 */
     590int tcp_conn_recv_wait(tcp_conn_t *conn, void *buf, size_t bsize,
     591    size_t *nrecv)
    411592{
    412593        async_exch_t *exch;
     
    450631}
    451632
     633/** Connection established event.
     634 *
     635 * @param tcp TCP client
     636 * @param iid Call ID
     637 * @param icall Call data
     638 */
    452639static void tcp_ev_connected(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall)
    453640{
     
    472659}
    473660
     661/** Connection failed event.
     662 *
     663 * @param tcp TCP client
     664 * @param iid Call ID
     665 * @param icall Call data
     666 */
    474667static void tcp_ev_conn_failed(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall)
    475668{
     
    494687}
    495688
     689/** Connection reset event.
     690 *
     691 * @param tcp TCP client
     692 * @param iid Call ID
     693 * @param icall Call data
     694 */
    496695static void tcp_ev_conn_reset(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall)
    497696{
     
    516715}
    517716
     717/** Data available event.
     718 *
     719 * @param tcp TCP client
     720 * @param iid Call ID
     721 * @param icall Call data
     722 */
    518723static void tcp_ev_data(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall)
    519724{
     
    539744}
    540745
     746/** Urgent data event.
     747 *
     748 * @param tcp TCP client
     749 * @param iid Call ID
     750 * @param icall Call data
     751 */
    541752static void tcp_ev_urg_data(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall)
    542753{
     
    544755}
    545756
     757/** New connection event.
     758 *
     759 * @param tcp TCP client
     760 * @param iid Call ID
     761 * @param icall Call data
     762 */
    546763static void tcp_ev_new_conn(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall)
    547764{
     
    590807}
    591808
     809/** Callback connection handler.
     810 *
     811 * @param iid Connect call ID
     812 * @param icall Connect call data
     813 * @param arg Argument, TCP client
     814 */
    592815static void tcp_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    593816{
     
    636859}
    637860
    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 */
    639865static int tcp_conn_fibril(void *arg)
    640866{
Note: See TracChangeset for help on using the changeset viewer.