Changeset 7fc092a in mainline for uspace/srv/net/tl/tcp/tcp.c


Ignore:
Timestamp:
2011-01-27T22:09:29Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
db7ed07
Parents:
9ee87f6 (diff), 6265a2b (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:

Changes from development branch

File:
1 edited

Legend:

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

    r9ee87f6 r7fc092a  
    3636 */
    3737
    38 #include "tcp.h"
    39 #include "tcp_header.h"
    40 #include "tcp_module.h"
    41 
    4238#include <assert.h>
    4339#include <async.h>
     
    6864#include <ip_interface.h>
    6965#include <icmp_client.h>
    70 #include <icmp_interface.h>
     66#include <icmp_remote.h>
    7167#include <net_interface.h>
    7268#include <socket_core.h>
    7369#include <tl_common.h>
    74 #include <tl_local.h>
    75 #include <tl_interface.h>
     70#include <tl_remote.h>
     71#include <tl_skel.h>
     72
     73#include "tcp.h"
     74#include "tcp_header.h"
    7675
    7776/** TCP module name. */
    78 #define NAME    "TCP protocol"
     77#define NAME  "tcp"
    7978
    8079/** The TCP window default value. */
     
    220219/** TCP global data. */
    221220tcp_globals_t tcp_globals;
    222 
    223 /** Initializes the TCP module.
    224  *
    225  * @param[in] client_connection The client connection processing function. The
    226  *                      module skeleton propagates its own one.
    227  * @return              EOK on success.
    228  * @return              ENOMEM if there is not enough memory left.
    229  */
    230 int tcp_initialize(async_client_conn_t client_connection)
    231 {
    232         int rc;
    233 
    234         assert(client_connection);
    235 
    236         fibril_rwlock_initialize(&tcp_globals.lock);
    237         fibril_rwlock_write_lock(&tcp_globals.lock);
    238 
    239         tcp_globals.icmp_phone = icmp_connect_module(SERVICE_ICMP,
    240             ICMP_CONNECT_TIMEOUT);
    241         tcp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_TCP,
    242             SERVICE_TCP, client_connection);
    243         if (tcp_globals.ip_phone < 0) {
    244                 fibril_rwlock_write_unlock(&tcp_globals.lock);
    245                 return tcp_globals.ip_phone;
    246         }
    247        
    248         rc = socket_ports_initialize(&tcp_globals.sockets);
    249         if (rc != EOK)
    250                 goto out;
    251 
    252         rc = packet_dimensions_initialize(&tcp_globals.dimensions);
    253         if (rc != EOK) {
    254                 socket_ports_destroy(&tcp_globals.sockets);
    255                 goto out;
    256         }
    257 
    258         tcp_globals.last_used_port = TCP_FREE_PORTS_START - 1;
    259 
    260 out:
    261         fibril_rwlock_write_unlock(&tcp_globals.lock);
    262         return rc;
    263 }
    264221
    265222int tcp_received_msg(device_id_t device_id, packet_t *packet,
     
    12471204}
    12481205
     1206/** Per-connection initialization
     1207 *
     1208 */
     1209void tl_connection(void)
     1210{
     1211}
     1212
    12491213/** Processes the TCP message.
    12501214 *
     
    12601224 * @see IS_NET_TCP_MESSAGE()
    12611225 */
    1262 int
    1263 tcp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     1226int tl_message(ipc_callid_t callid, ipc_call_t *call,
    12641227    ipc_call_t *answer, size_t *answer_count)
    12651228{
    1266         packet_t *packet;
    1267         int rc;
    1268 
    12691229        assert(call);
    12701230        assert(answer);
     
    12731233        *answer_count = 0;
    12741234        switch (IPC_GET_IMETHOD(*call)) {
    1275         case NET_TL_RECEIVED:
    1276 //              fibril_rwlock_read_lock(&tcp_globals.lock);
    1277                 rc = packet_translate_remote(tcp_globals.net_phone, &packet,
    1278                     IPC_GET_PACKET(*call));
    1279                 if (rc != EOK) {
    1280 //                      fibril_rwlock_read_unlock(&tcp_globals.lock);
    1281                         return rc;
    1282                 }
    1283                 rc = tcp_received_msg(IPC_GET_DEVICE(*call), packet, SERVICE_TCP,
    1284                     IPC_GET_ERROR(*call));
    1285 //              fibril_rwlock_read_unlock(&tcp_globals.lock);
    1286                 return rc;
    12871235        case IPC_M_CONNECT_TO_ME:
    12881236                return tcp_process_client_messages(callid, *call);
     
    24862434}
    24872435
    2488 /** Default thread for new connections.
     2436/** Process IPC messages from the IP module
    24892437 *
    2490  * @param[in] iid       The initial message identifier.
    2491  * @param[in] icall     The initial message call structure.
     2438 * @param[in]     iid   Message identifier.
     2439 * @param[in,out] icall Message parameters.
    24922440 *
    24932441 */
    2494 static void tl_client_connection(ipc_callid_t iid, ipc_call_t * icall)
    2495 {
    2496         /*
    2497          * Accept the connection
    2498          *  - Answer the first IPC_M_CONNECT_ME_TO call.
    2499          */
    2500         ipc_answer_0(iid, EOK);
    2501 
     2442static void tcp_receiver(ipc_callid_t iid, ipc_call_t *icall)
     2443{
     2444        packet_t *packet;
     2445        int rc;
     2446       
    25022447        while (true) {
    2503                 ipc_call_t answer;
    2504                 size_t answer_count;
    2505 
    2506                 /* Clear the answer structure */
    2507                 refresh_answer(&answer, &answer_count);
    2508 
    2509                 /* Fetch the next message */
    2510                 ipc_call_t call;
    2511                 ipc_callid_t callid = async_get_call(&call);
    2512 
    2513                 /* Process the message */
    2514                 int res = tl_module_message_standalone(callid, &call, &answer,
    2515                     &answer_count);
    2516 
    2517                 /*
    2518                  * End if told to either by the message or the processing
    2519                  * result.
    2520                  */
    2521                 if ((IPC_GET_IMETHOD(call) == IPC_M_PHONE_HUNGUP) ||
    2522                     (res == EHANGUP))
    2523                         return;
    2524 
    2525                 /*
    2526                  * Answer the message
    2527                  */
    2528                 answer_call(callid, res, &answer, answer_count);
    2529         }
    2530 }
    2531 
    2532 /** Starts the module.
     2448                switch (IPC_GET_IMETHOD(*icall)) {
     2449                case NET_TL_RECEIVED:
     2450                        rc = packet_translate_remote(tcp_globals.net_phone, &packet,
     2451                            IPC_GET_PACKET(*icall));
     2452                        if (rc == EOK)
     2453                                rc = tcp_received_msg(IPC_GET_DEVICE(*icall), packet,
     2454                                    SERVICE_TCP, IPC_GET_ERROR(*icall));
     2455                       
     2456                        ipc_answer_0(iid, (sysarg_t) rc);
     2457                        break;
     2458                default:
     2459                        ipc_answer_0(iid, (sysarg_t) ENOTSUP);
     2460                }
     2461               
     2462                iid = async_get_call(icall);
     2463        }
     2464}
     2465
     2466/** Initialize the TCP module.
    25332467 *
    2534  * @return              EOK on success.
    2535  * @return              Other error codes as defined for each specific module
    2536  *                      start function.
     2468 * @param[in] net_phone Network module phone.
     2469 *
     2470 * @return EOK on success.
     2471 * @return ENOMEM if there is not enough memory left.
     2472 *
    25372473 */
    2538 int
    2539 main(int argc, char *argv[])
    2540 {
    2541         int rc;
    2542 
    2543         rc = tl_module_start_standalone(tl_client_connection);
     2474int tl_initialize(int net_phone)
     2475{
     2476        fibril_rwlock_initialize(&tcp_globals.lock);
     2477        fibril_rwlock_write_lock(&tcp_globals.lock);
     2478       
     2479        tcp_globals.net_phone = net_phone;
     2480       
     2481        tcp_globals.icmp_phone = icmp_connect_module(ICMP_CONNECT_TIMEOUT);
     2482        tcp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_TCP,
     2483            SERVICE_TCP, tcp_receiver);
     2484        if (tcp_globals.ip_phone < 0) {
     2485                fibril_rwlock_write_unlock(&tcp_globals.lock);
     2486                return tcp_globals.ip_phone;
     2487        }
     2488       
     2489        int rc = socket_ports_initialize(&tcp_globals.sockets);
     2490        if (rc != EOK)
     2491                goto out;
     2492
     2493        rc = packet_dimensions_initialize(&tcp_globals.dimensions);
     2494        if (rc != EOK) {
     2495                socket_ports_destroy(&tcp_globals.sockets);
     2496                goto out;
     2497        }
     2498
     2499        tcp_globals.last_used_port = TCP_FREE_PORTS_START - 1;
     2500
     2501out:
     2502        fibril_rwlock_write_unlock(&tcp_globals.lock);
    25442503        return rc;
     2504}
     2505
     2506int main(int argc, char *argv[])
     2507{
     2508        return tl_module_start(SERVICE_TCP);
    25452509}
    25462510
Note: See TracChangeset for help on using the changeset viewer.