Fork us on GitHub Follow us on Google+ Follow us on Facebook Follow us on Twitter

Changes between Version 1 and Version 2 of AsyncSessions


Ignore:
Timestamp:
2010-12-26T22:05:18Z (8 years ago)
Author:
Jiri Svoboda
Comment:

Complete code samples

Legend:

Unmodified
Added
Removed
Modified
  • AsyncSessions

    v1 v2  
    88
    99{{{
    10 int cd_phone;
     10int my_phone;
    1111
    12 int chardev_connect()
     12int mysrv_connect(void)
    1313{
    14     // connect phone to the character device
     14    /* Connect phone to the service */
     15    my_phone = async_connect_me_to(PHONE_NS, SERVICE_MYSRV, 0);
    1516}
    1617
    17 int chardev_read()
     18int mysrv_read(int arg, void *buf, size_t bufsize)
    1819{
    19     // R1:send CHARDEV_READ
    20     // R2:send IPC_READ
    21     // wait for R1
    22     // wait for R2
     20    /* Send first request R1 (including operation code). */
     21    req = async_send_1(my_phone, MYSRV_READ, arg);
     22
     23    /* Send second request (IPC_READ) and wait for result. */
     24    rc = async_data_read_start(my_phone, buf, bufsize);
     25    if (rc != EOK) {
     26        /* handle error */
     27    }
     28
     29    /* Wait for R1 reply. */
     30    async_wait_for(req, &rc);
     31    if (rc != EOK) {
     32        /* handle error */
     33    }
    2334}
    2435}}}
     
    3748
    3849{{{
    39 async_sess_t cd_session;
     50async_sess_t my_session;
    4051
    41 int chardev_connect()
     52int mysrv_connect()
    4253{
    43     // connect phone to the character device
    44     // create session
     54    int phone;
     55
     56    /* Connect phone to the service */
     57    phone = async_connect_me_to(PHONE_NS, SERVICE_MYSRV, 0);
     58
     59    /* Create session */
     60    async_session_create(&my_session, phone);
    4561}
    4662
    47 int chardev_read()
     63int mysrv_read(int arg, void *buf, size_t bufsize)
    4864{
    49     // begin exchange
    50     // R1:send CHARDEV_READ
    51     // R2:send IPC_READ
    52     // wait for R1
    53     // wait for R2
    54     // end exchange
     65    int phone;
     66
     67    /* Begin exchange */
     68    phone = async_exchange_begin(&my_session);
     69
     70    /* Send first request R1 (including operation code). */
     71    req = async_send_1(my_phone, MYSRV_READ, arg);
     72
     73    /* Send second request (IPC_READ) and wait for result. */
     74    rc = async_data_read_start(my_phone, buf, bufsize);
     75    if (rc != EOK) {
     76        /* handle error */
     77    }
     78
     79    /* Wait for R1 reply. */
     80    async_wait_for(req, &rc);
     81    if (rc != EOK) {
     82        /* handle error */
     83    }
     84
     85    /* End exchange */
     86    async_exchange_end(&my_session, phone);
    5587}
    5688}}}