Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/tl/socket_core.c

    r5fe7692 rccca251  
    9191        int packet_id;
    9292
    93         // if bound
     93        /* If bound */
    9494        if (socket->port) {
    95                 // release the port
     95                /* Release the port */
    9696                socket_port_release(global_sockets, socket);
    9797        }
    9898       
    99         // release all received packets
     99        /* Release all received packets */
    100100        while ((packet_id = dyn_fifo_pop(&socket->received)) >= 0)
    101101                pq_release_remote(packet_phone, packet_id);
     
    166166        int rc;
    167167
    168         // create a wrapper
     168        /* Create a wrapper */
    169169        socket_ref = malloc(sizeof(*socket_ref));
    170170        if (!socket_ref)
     
    172172
    173173        *socket_ref = socket;
    174         // add the wrapper
     174        /* Add the wrapper */
    175175        rc = socket_port_map_add(&socket_port->map, key, key_length,
    176176            socket_ref);
     
    206206        int rc;
    207207
    208         // create a wrapper
     208        /* Create a wrapper */
    209209        socket_port = malloc(sizeof(*socket_port));
    210210        if (!socket_port)
     
    221221                goto fail;
    222222       
    223         // register the incomming port
     223        /* Register the incoming port */
    224224        rc = socket_ports_add(global_sockets, port, socket_port);
    225225        if (rc < 0)
     
    277277               
    278278                address_in = (struct sockaddr_in *) addr;
    279                 // find the socket
     279                /* Find the socket */
    280280                socket = socket_cores_find(local_sockets, socket_id);
    281281                if (!socket)
    282282                        return ENOTSOCK;
    283283               
    284                 // bind a free port?
     284                /* Bind a free port? */
    285285                if (address_in->sin_port <= 0)
    286286                        return socket_bind_free_port(global_sockets, socket,
    287287                             free_ports_start, free_ports_end, last_used_port);
    288288               
    289                 // try to find the port
     289                /* Try to find the port */
    290290                socket_port = socket_ports_find(global_sockets,
    291291                    ntohs(address_in->sin_port));
    292292                if (socket_port) {
    293                         // already used
     293                        /* Already used */
    294294                        return EADDRINUSE;
    295295                }
    296296               
    297                 // if bound
     297                /* If bound */
    298298                if (socket->port) {
    299                         // release the port
     299                        /* Release the port */
    300300                        socket_port_release(global_sockets, socket);
    301301                }
     
    333333        int index;
    334334
    335         // from the last used one
     335        /* From the last used one */
    336336        index = last_used_port;
    337337       
     
    339339                ++index;
    340340               
    341                 // til the range end
     341                /* Till the range end */
    342342                if (index >= free_ports_end) {
    343                         // start from the range beginning
     343                        /* Start from the range beginning */
    344344                        index = free_ports_start - 1;
    345345                        do {
    346346                                ++index;
    347                                 // til the last used one
     347                                /* Till the last used one */
    348348                                if (index >= last_used_port) {
    349                                         // none found
     349                                        /* None found */
    350350                                        return ENOTCONN;
    351351                                }
    352352                        } while (socket_ports_find(global_sockets, index));
    353353                       
    354                         // found, break immediately
     354                        /* Found, break immediately */
    355355                        break;
    356356                }
     
    376376
    377377        count = 0;
    378 //      socket_id = socket_globals.last_id;
     378#if 0
     379        socket_id = socket_globals.last_id;
     380#endif
    379381        do {
    380382                if (count < SOCKET_ID_TRIES) {
     
    384386                        socket_id = 1;
    385387                        ++count;
    386                 // only this branch for last_id
     388                /* Only this branch for last_id */
    387389                } else {
    388390                        if (socket_id < INT_MAX) {
    389391                                ++ socket_id;
    390 /*                      } else if(socket_globals.last_id) {
    391 *                               socket_globals.last_id = 0;
    392 *                               socket_id = 1;
    393 */                      } else {
     392#if 0
     393                        } else if(socket_globals.last_id) {
     394                                socket_globals.last_id = 0;
     395                                socket_id = 1;
     396#endif
     397                        } else {
    394398                                return ELIMIT;
    395399                        }
     
    425429                return EINVAL;
    426430       
    427         // store the socket
     431        /* Store the socket */
    428432        if (*socket_id <= 0) {
    429433                positive = (*socket_id == 0);
     
    441445                return ENOMEM;
    442446       
    443         // initialize
     447        /* Initialize */
    444448        socket->phone = app_phone;
    445449        socket->port = -1;
     
    493497        int accepted_id;
    494498
    495         // find the socket
     499        /* Find the socket */
    496500        socket = socket_cores_find(local_sockets, socket_id);
    497501        if (!socket)
    498502                return ENOTSOCK;
    499503       
    500         // destroy all accepted sockets
     504        /* Destroy all accepted sockets */
    501505        while ((accepted_id = dyn_fifo_pop(&socket->accepted)) >= 0)
    502506                socket_destroy(packet_phone, accepted_id, local_sockets,
     
    535539        next_packet = pq_next(packet);
    536540        if (!next_packet) {
    537                 // write all if only one fragment
     541                /* Write all if only one fragment */
    538542                rc = data_reply(packet_get_data(packet),
    539543                    packet_get_data_length(packet));
    540544                if (rc != EOK)
    541545                        return rc;
    542                 // store the total length
     546                /* Store the total length */
    543547                *length = packet_get_data_length(packet);
    544548        } else {
    545                 // count the packet fragments
     549                /* Count the packet fragments */
    546550                fragments = 1;
    547551                next_packet = pq_next(packet);
     
    549553                        ++fragments;
    550554               
    551                 // compute and store the fragment lengths
     555                /* Compute and store the fragment lengths */
    552556                lengths = (size_t *) malloc(sizeof(size_t) * fragments +
    553557                    sizeof(size_t));
     
    565569                }
    566570               
    567                 // write the fragment lengths
     571                /* Write the fragment lengths */
    568572                rc = data_reply(lengths, sizeof(int) * (fragments + 1));
    569573                if (rc != EOK) {
     
    573577                next_packet = packet;
    574578               
    575                 // write the fragments
     579                /* Write the fragments */
    576580                for (index = 0; index < fragments; ++index) {
    577581                        rc = data_reply(packet_get_data(next_packet),
     
    584588                }
    585589               
    586                 // store the total length
     590                /* Store the total length */
    587591                *length = lengths[fragments];
    588592                free(lengths);
     
    636640                return;
    637641       
    638         // find ports
     642        /* Find ports */
    639643        socket_port = socket_ports_find(global_sockets, socket->port);
    640644        if (socket_port) {
    641                 // find the socket
     645                /* Find the socket */
    642646                socket_ref = socket_port_map_find(&socket_port->map,
    643647                    socket->key, socket->key_length);
     
    646650                        --socket_port->count;
    647651                       
    648                         // release if empty
     652                        /* Release if empty */
    649653                        if (socket_port->count <= 0) {
    650                                 // destroy the map
     654                                /* Destroy the map */
    651655                                socket_port_map_destroy(&socket_port->map, free);
    652                                 // release the port
     656                                /* Release the port */
    653657                                socket_ports_exclude(global_sockets,
    654658                                    socket->port, free);
    655659                        } else {
    656                                 // remove
     660                                /* Remove */
    657661                                socket_port_map_exclude(&socket_port->map,
    658662                                    socket->key, socket->key_length, free);
     
    685689        int rc;
    686690
    687         // find ports
     691        /* Find ports */
    688692        socket_port = socket_ports_find(global_sockets, port);
    689693        if (!socket_port)
    690694                return ENOENT;
    691695       
    692         // add the socket
     696        /* Add the socket */
    693697        rc = socket_port_add_core(socket_port, socket, key, key_length);
    694698        if (rc != EOK)
Note: See TracChangeset for help on using the changeset viewer.