Changeset 59157eb in mainline


Ignore:
Timestamp:
2012-02-02T15:18:46Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f834f90d
Parents:
ecff3d9
Message:

Implement INET_EV_RECV IPC.

Location:
uspace
Files:
1 added
3 edited

Legend:

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

    recff3d9 r59157eb  
    148148}
    149149
     150static void inet_ev_recv(ipc_callid_t callid, ipc_call_t *call)
     151{
     152        int rc;
     153        inet_dgram_t dgram;
     154
     155        dgram.src.ipv4 = IPC_GET_ARG1(*call);
     156        dgram.dest.ipv4 = IPC_GET_ARG2(*call);
     157        dgram.tos = IPC_GET_ARG3(*call);
     158
     159        rc = async_data_write_accept(&dgram.data, false, 0, 0, 0, &dgram.size);
     160        if (rc != EOK) {
     161                async_answer_0(callid, rc);
     162                return;
     163        }
     164
     165        rc = inet_ev_ops->recv(&dgram);
     166        async_answer_0(callid, rc);
     167}
     168
    150169static void inet_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    151170{
     
    153172                ipc_call_t call;
    154173                ipc_callid_t callid = async_get_call(&call);
    155                
     174
    156175                if (!IPC_GET_IMETHOD(call)) {
    157176                        /* TODO: Handle hangup */
    158177                        return;
    159178                }
    160                
     179
    161180                switch (IPC_GET_IMETHOD(call)) {
    162181                case INET_EV_RECV:
    163                         async_answer_0(callid, EOK);
     182                        inet_ev_recv(callid, &call);
    164183                        break;
    165184                default:
  • uspace/srv/inet/inet.c

    recff3d9 r59157eb  
    4747#include <sys/types.h>
    4848
     49#include "inet.h"
     50
    4951#define NAME "inet"
    50 
    51 /** Inet Client */
    52 typedef struct {
    53         async_sess_t *sess;
    54         uint8_t protocol;
    55         link_t client_list;
    56 } inet_client_t;
    5752
    5853static void inet_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg);
     
    111106    ipc_call_t *call)
    112107{
    113         uint32_t src_ipv4;
    114         uint32_t dest_ipv4;
    115         uint8_t tos;
     108        inet_dgram_t dgram;
    116109        uint8_t ttl;
    117110        int df;
    118         void *data;
    119         size_t size;
    120111        int rc;
    121112
    122113        log_msg(LVL_DEBUG, "inet_send()");
    123114
    124         src_ipv4 = IPC_GET_ARG1(*call);
    125         dest_ipv4 = IPC_GET_ARG2(*call);
    126         tos = IPC_GET_ARG3(*call);
     115        dgram.src.ipv4 = IPC_GET_ARG1(*call);
     116        dgram.dest.ipv4 = IPC_GET_ARG2(*call);
     117        dgram.tos = IPC_GET_ARG3(*call);
    127118        ttl = IPC_GET_ARG4(*call);
    128119        df = IPC_GET_ARG5(*call);
    129120
    130         (void)src_ipv4;
    131         (void)dest_ipv4;
    132         (void)tos;
    133121        (void)ttl;
    134122        (void)df;
    135123
    136         rc = async_data_write_accept(&data, false, 0, 0, 0, &size);
     124        rc = async_data_write_accept(&dgram.data, false, 0, 0, 0, &dgram.size);
    137125        if (rc != EOK) {
    138126                async_answer_0(callid, rc);
     
    140128        }
    141129
    142         free(data);
     130        free(dgram.data);
    143131        async_answer_0(callid, ENOTSUP);
    144132}
     
    223211}
    224212
     213int inet_ev_recv(inet_client_t *client, inet_dgram_t *dgram)
     214{
     215        async_exch_t *exch = async_exchange_begin(client->sess);
     216
     217        ipc_call_t answer;
     218        aid_t req = async_send_3(exch, INET_EV_RECV, dgram->src.ipv4,
     219            dgram->dest.ipv4, dgram->tos, &answer);
     220        int rc = async_data_write_start(exch, dgram->data, dgram->size);
     221        async_exchange_end(exch);
     222
     223        if (rc != EOK) {
     224                async_wait_for(req, NULL);
     225                return rc;
     226        }
     227
     228        sysarg_t retval;
     229        async_wait_for(req, &retval);
     230        if (retval != EOK)
     231                return retval;
     232
     233        return EOK;
     234}
     235
    225236int main(int argc, char *argv[])
    226237{
  • uspace/srv/tcp/tcp.c

    recff3d9 r59157eb  
    5454#define NAME       "tcp"
    5555
     56#define IP_PROTO_TCP 6
     57
    5658static int tcp_inet_ev_recv(inet_dgram_t *dgram);
    5759static void tcp_received_pdu(tcp_pdu_t *pdu);
     
    185187        if (0) tcp_test();
    186188
    187         rc = inet_init(42, &tcp_inet_ev_ops);
     189        rc = inet_init(IP_PROTO_TCP, &tcp_inet_ev_ops);
    188190        if (rc != EOK) {
    189191                log_msg(LVL_ERROR, "Failed connecting to internet service.");
Note: See TracChangeset for help on using the changeset viewer.