Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/tcp/service.c

    r1d03e86 r1f2b07a  
    2727 */
    2828
    29 /** @addtogroup tcp
     29/** @addtogroup udp
    3030 * @{
    3131 */
     
    4444#include <loc.h>
    4545#include <macros.h>
    46 #include <mem.h>
    4746#include <stdlib.h>
    4847
     
    5453#define NAME "tcp"
    5554
    56 /** Maximum amount of data transferred in one send call */
    5755#define MAX_MSG_SIZE DATA_XFER_LIMIT
    5856
     
    6967static int tcp_cconn_create(tcp_client_t *, tcp_conn_t *, tcp_cconn_t **);
    7068
    71 /** Connection callbacks to tie us to lower layer */
    7269static tcp_cb_t tcp_service_cb = {
    7370        .cstate_change = tcp_service_cstate_change,
     
    7572};
    7673
    77 /** Sentinel connection callbacks to tie us to lower layer */
    7874static tcp_cb_t tcp_service_lst_cb = {
    7975        .cstate_change = tcp_service_lst_cstate_change,
     
    8177};
    8278
    83 /** Connection state has changed.
    84  *
    85  * @param conn      Connection
    86  * @param arg       Argument (not used)
    87  * @param old_state Previous connection state
    88  */
    8979static void tcp_service_cstate_change(tcp_conn_t *conn, void *arg,
    9080    tcp_cstate_t old_state)
     
    118108}
    119109
    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  */
    126110static void tcp_service_lst_cstate_change(tcp_conn_t *conn, void *arg,
    127111    tcp_cstate_t old_state)
     
    185169}
    186170
    187 /** Received data became available on connection.
    188  *
    189  * @param conn Connection
    190  * @param arg  Client connection
    191  */
    192171static void tcp_service_recv_data(tcp_conn_t *conn, void *arg)
    193172{
     
    197176}
    198177
    199 /** Send 'data' event to client.
    200  *
    201  * @param cconn Client connection
    202  */
    203178static void tcp_ev_data(tcp_cconn_t *cconn)
    204179{
     
    217192}
    218193
    219 /** Send 'connected' event to client.
    220  *
    221  * @param cconn Client connection
    222  */
    223194static void tcp_ev_connected(tcp_cconn_t *cconn)
    224195{
     
    234205}
    235206
    236 /** Send 'conn_failed' event to client.
    237  *
    238  * @param cconn Client connection
    239  */
    240207static void tcp_ev_conn_failed(tcp_cconn_t *cconn)
    241208{
     
    251218}
    252219
    253 /** Send 'conn_reset' event to client.
    254  *
    255  * @param cconn Client connection
    256  */
    257220static void tcp_ev_conn_reset(tcp_cconn_t *cconn)
    258221{
     
    268231}
    269232
    270 /** Send 'new_conn' event to client.
    271  *
    272  * @param clst Client listener that received the connection
    273  * @param cconn New client connection
    274  */
     233/** New incoming connection */
    275234static void tcp_ev_new_conn(tcp_clst_t *clst, tcp_cconn_t *cconn)
    276235{
     
    287246}
    288247
    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  */
    299248static int tcp_cconn_create(tcp_client_t *client, tcp_conn_t *conn,
    300249    tcp_cconn_t **rcconn)
     
    323272}
    324273
    325 /** Destroy client connection.
    326  *
    327  * @param cconn Client connection
    328  */
    329274static void tcp_cconn_destroy(tcp_cconn_t *cconn)
    330275{
     
    333278}
    334279
    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  */
    346280static int tcp_clistener_create(tcp_client_t *client, tcp_conn_t *conn,
    347281    tcp_clst_t **rclst)
     
    370304}
    371305
    372 /** Destroy client listener.
    373  *
    374  * @param clst Client listener
    375  */
    376306static void tcp_clistener_destroy(tcp_clst_t *clst)
    377307{
     
    380310}
    381311
    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  */
    391312static int tcp_cconn_get(tcp_client_t *client, sysarg_t id,
    392313    tcp_cconn_t **rcconn)
     
    402323}
    403324
    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  */
    413325static int tcp_clistener_get(tcp_client_t *client, sysarg_t id,
    414326    tcp_clst_t **rclst)
     
    424336}
    425337
    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  */
     338
    436339static int tcp_conn_create_impl(tcp_client_t *client, inet_ep2_t *epp,
    437340    sysarg_t *rconn_id)
     
    473376}
    474377
    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  */
    483378static int tcp_conn_destroy_impl(tcp_client_t *client, sysarg_t conn_id)
    484379{
     
    498393}
    499394
    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 */
    510395static int tcp_listener_create_impl(tcp_client_t *client, inet_ep_t *ep,
    511396    sysarg_t *rlst_id)
     
    545430}
    546431
    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  */
    556432static int tcp_listener_destroy_impl(tcp_client_t *client, sysarg_t lst_id)
    557433{
     
    570446}
    571447
    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  */
    581448static int tcp_conn_send_fin_impl(tcp_client_t *client, sysarg_t conn_id)
    582449{
     
    595462}
    596463
    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  */
    606464static int tcp_conn_push_impl(tcp_client_t *client, sysarg_t conn_id)
    607465{
     
    620478}
    621479
    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  */
    631480static int tcp_conn_reset_impl(tcp_client_t *client, sysarg_t conn_id)
    632481{
     
    644493}
    645494
    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  */
    657495static int tcp_conn_send_impl(tcp_client_t *client, sysarg_t conn_id,
    658496    void *data, size_t size)
     
    672510}
    673511
    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  */
    686512static int tcp_conn_recv_impl(tcp_client_t *client, sysarg_t conn_id,
    687513    void *data, size_t size, size_t *nrecv)
     
    714540}
    715541
    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  */
    724542static void tcp_callback_create_srv(tcp_client_t *client, ipc_callid_t iid,
    725543    ipc_call_t *icall)
     
    737555}
    738556
    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  */
    747557static void tcp_conn_create_srv(tcp_client_t *client, ipc_callid_t iid,
    748558    ipc_call_t *icall)
     
    784594}
    785595
    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  */
    794596static void tcp_conn_destroy_srv(tcp_client_t *client, ipc_callid_t iid,
    795597    ipc_call_t *icall)
     
    805607}
    806608
    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  */
    815609static void tcp_listener_create_srv(tcp_client_t *client, ipc_callid_t iid,
    816610    ipc_call_t *icall)
     
    852646}
    853647
    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  */
    862648static void tcp_listener_destroy_srv(tcp_client_t *client, ipc_callid_t iid,
    863649    ipc_call_t *icall)
     
    873659}
    874660
    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  */
    883661static void tcp_conn_send_fin_srv(tcp_client_t *client, ipc_callid_t iid,
    884662    ipc_call_t *icall)
     
    894672}
    895673
    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  */
    904674static void tcp_conn_push_srv(tcp_client_t *client, ipc_callid_t iid,
    905675    ipc_call_t *icall)
     
    915685}
    916686
    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  */
    925687static void tcp_conn_reset_srv(tcp_client_t *client, ipc_callid_t iid,
    926688    ipc_call_t *icall)
     
    936698}
    937699
    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  */
    946700static void tcp_conn_send_srv(tcp_client_t *client, ipc_callid_t iid,
    947701    ipc_call_t *icall)
     
    996750}
    997751
    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  */
    1006752static void tcp_conn_recv_srv(tcp_client_t *client, ipc_callid_t iid,
    1007753    ipc_call_t *icall)
     
    1052798}
    1053799
    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  */
    1062800static void tcp_conn_recv_wait_srv(tcp_client_t *client, ipc_callid_t iid,
    1063801    ipc_call_t *icall)
     
    1113851}
    1114852
    1115 /** Initialize TCP client structure.
    1116  *
    1117  * @param client TCP client
    1118  */
     853#include <mem.h>
     854
    1119855static void tcp_client_init(tcp_client_t *client)
    1120856{
     
    1125861}
    1126862
    1127 /** Finalize TCP client structure.
    1128  *
    1129  * @param client TCP client
    1130  */
    1131863static void tcp_client_fini(tcp_client_t *client)
    1132864{
    1133865        tcp_cconn_t *cconn;
    1134         unsigned long n;
     866        size_t n;
    1135867
    1136868        n = list_count(&client->cconn);
    1137869        if (n != 0) {
    1138                 log_msg(LOG_DEFAULT, LVL_WARN, "Client with %lu active "
     870                log_msg(LOG_DEFAULT, LVL_WARN, "Client with %zu active "
    1139871                    "connections closed session", n);
    1140872
     
    1150882        n = list_count(&client->clst);
    1151883        if (n != 0) {
    1152                 log_msg(LOG_DEFAULT, LVL_WARN, "Client with %lu active "
     884                log_msg(LOG_DEFAULT, LVL_WARN, "Client with %zu active "
    1153885                    "listeners closed session", n);
    1154886                /* XXX Destroy listeners */
     
    1159891}
    1160892
    1161 /** Handle TCP client connection.
    1162  *
    1163  * @param iid   Connect call ID
    1164  * @param icall Connect call data
    1165  * @param arg   Connection argument
    1166  */
    1167893static void tcp_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    1168894{
     
    1235961}
    1236962
    1237 /** Initialize TCP service.
    1238  *
    1239  * @return EOK on success or negative error code.
    1240  */
    1241963int tcp_service_init(void)
    1242964{
     
    1244966        service_id_t sid;
    1245967
    1246         async_set_fallback_port_handler(tcp_client_conn, NULL);
     968        async_set_client_connection(tcp_client_conn);
    1247969
    1248970        rc = loc_server_register(NAME);
Note: See TracChangeset for help on using the changeset viewer.