Changeset f2b3d3e in mainline for uspace/srv/net/tcp/sock.c


Ignore:
Timestamp:
2012-05-04T10:57:48Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
35a35651
Parents:
90924df (diff), d21e935c (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 moved

Legend:

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

    r90924df rf2b3d3e  
    3838#include <async.h>
    3939#include <errno.h>
     40#include <inet/inet.h>
    4041#include <io/log.h>
    41 #include <ip_client.h>
     42#include <ipc/services.h>
    4243#include <ipc/socket.h>
    43 #include <net/modules.h>
    4444#include <net/socket.h>
     45#include <ns.h>
    4546
    4647#include "sock.h"
     
    6364static socket_ports_t gsock;
    6465
     66static void tcp_sock_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg);
    6567static void tcp_sock_cstate_cb(tcp_conn_t *conn, void *arg);
    6668
    67 void tcp_sock_init(void)
    68 {
     69int tcp_sock_init(void)
     70{
     71        int rc;
     72
    6973        socket_ports_initialize(&gsock);
     74
     75        async_set_client_connection(tcp_sock_connection);
     76
     77        rc = service_register(SERVICE_TCP);
     78        if (rc != EOK)
     79                return EEXIST;
     80
     81        return EOK;
    7082}
    7183
     
    7688        socket = (tcp_sockdata_t *)sock_core->specific_data;
    7789        (void)socket;
     90
     91        /* XXX We need to initiate connection cleanup here */
    7892}
    7993
     
    129143        sock->sock_core = sock_core;
    130144
    131         refresh_answer(&answer, NULL);
    132145        SOCKET_SET_SOCKET_ID(answer, sock_id);
    133146
    134147        SOCKET_SET_DATA_FRAGMENT_SIZE(answer, FRAGMENT_SIZE);
    135148        SOCKET_SET_HEADER_SIZE(answer, sizeof(tcp_header_t));
    136         answer_call(callid, EOK, &answer, 3);
     149       
     150        async_answer_3(callid, EOK, IPC_GET_ARG1(answer),
     151            IPC_GET_ARG2(answer), IPC_GET_ARG3(answer));
    137152}
    138153
     
    273288        tcp_sock_t lsocket;
    274289        tcp_sock_t fsocket;
    275         nic_device_id_t dev_id;
    276         tcp_phdr_t *phdr;
    277         size_t phdr_len;
    278290
    279291        log_msg(LVL_DEBUG, "tcp_sock_connect()");
     
    309321
    310322        if (socket->laddr.ipv4 == TCP_IPV4_ANY) {
    311                 /* Find route to determine local IP address. */
    312                 rc = ip_get_route_req(ip_sess, IPPROTO_TCP,
    313                     (struct sockaddr *)addr, sizeof(*addr), &dev_id,
    314                     (void **)&phdr, &phdr_len);
     323                /* Determine local IP address */
     324                inet_addr_t loc_addr, rem_addr;
     325
     326                rem_addr.ipv4 = uint32_t_be2host(addr->sin_addr.s_addr);
     327                rc = inet_get_srcaddr(&rem_addr, 0, &loc_addr);
    315328                if (rc != EOK) {
    316329                        fibril_mutex_unlock(&socket->lock);
    317330                        async_answer_0(callid, rc);
    318                         log_msg(LVL_DEBUG, "tcp_transmit_connect: Failed to find route.");
    319                         return;
    320                 }
    321 
    322                 socket->laddr.ipv4 = uint32_t_be2host(phdr->src_addr);
     331                        log_msg(LVL_DEBUG, "tcp_sock_connect: Failed to "
     332                            "determine local address.");
     333                        return;
     334                }
     335
     336                socket->laddr.ipv4 = loc_addr.ipv4;
    323337                log_msg(LVL_DEBUG, "Local IP address is %x", socket->laddr.ipv4);
    324                 free(phdr);
    325338        }
    326339
     
    455468        assert(asock_core != NULL);
    456469
    457         refresh_answer(&answer, NULL);
    458 
    459470        SOCKET_SET_DATA_FRAGMENT_SIZE(answer, FRAGMENT_SIZE);
    460471        SOCKET_SET_SOCKET_ID(answer, asock_id);
    461472        SOCKET_SET_ADDRESS_LENGTH(answer, sizeof(struct sockaddr_in));
    462 
    463         answer_call(callid, asock_core->socket_id, &answer, 3);
    464 
     473       
     474        async_answer_3(callid, asock_core->socket_id,
     475            IPC_GET_ARG1(answer), IPC_GET_ARG2(answer),
     476            IPC_GET_ARG3(answer));
     477       
    465478        /* Push one fragment notification to client's queue */
    466479        log_msg(LVL_DEBUG, "tcp_sock_accept(): notify data\n");
     
    546559        }
    547560
    548         refresh_answer(&answer, NULL);
     561        IPC_SET_ARG1(answer, 0);
    549562        SOCKET_SET_DATA_FRAGMENT_SIZE(answer, FRAGMENT_SIZE);
    550         answer_call(callid, EOK, &answer, 2);
     563        async_answer_2(callid, EOK, IPC_GET_ARG1(answer),
     564            IPC_GET_ARG2(answer));
    551565        fibril_mutex_unlock(&socket->lock);
    552566}
     
    666680
    667681        SOCKET_SET_READ_DATA_LENGTH(answer, length);
    668         answer_call(callid, EOK, &answer, 1);
    669 
     682        async_answer_1(callid, EOK, IPC_GET_ARG1(answer));
     683       
    670684        /* Push one fragment notification to client's queue */
    671685        tcp_sock_notify_data(sock_core);
     
    713727        }
    714728
    715         rc = socket_destroy(net_sess, socket_id, &client->sockets, &gsock,
     729        rc = socket_destroy(NULL, socket_id, &client->sockets, &gsock,
    716730            tcp_free_sock_data);
    717731        if (rc != EOK) {
     
    764778}
    765779
    766 int tcp_sock_connection(async_sess_t *sess, ipc_callid_t iid, ipc_call_t icall)
     780static void tcp_sock_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    767781{
    768782        ipc_callid_t callid;
     
    773787        async_answer_0(iid, EOK);
    774788
    775         client.sess = sess;
     789        client.sess = async_callback_receive(EXCHANGE_SERIALIZE);
    776790        socket_cores_initialize(&client.sockets);
    777791
     
    825839        }
    826840
    827         return EOK;
     841        /* Clean up */
     842        log_msg(LVL_DEBUG, "tcp_sock_connection: Clean up");
     843        async_hangup(client.sess);
     844        socket_cores_release(NULL, &client.sockets, &gsock, tcp_free_sock_data);
    828845}
    829846
Note: See TracChangeset for help on using the changeset viewer.