Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 677cad5 in mainline


Ignore:
Timestamp:
2017-11-20T20:29:03Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
b2f542a
Parents:
19ea61d
Message:

Chardev server-side error reporting should match client side.

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/char/i8042/i8042.c

    r19ea61d r677cad5  
    6767
    6868static void i8042_char_conn(ipc_callid_t, ipc_call_t *, void *);
    69 static int i8042_read(chardev_srv_t *, void *, size_t);
    70 static int i8042_write(chardev_srv_t *, const void *, size_t);
     69static int i8042_read(chardev_srv_t *, void *, size_t, size_t *);
     70static int i8042_write(chardev_srv_t *, const void *, size_t, size_t *);
    7171
    7272static chardev_ops_t i8042_chardev_ops = {
     
    333333 * @param buffer Data source
    334334 * @param size   Data size
    335  *
    336  * @return Bytes written.
    337  *
    338  */
    339 static int i8042_write(chardev_srv_t *srv, const void *data, size_t size)
     335 * @param nwr    Place to store number of bytes successfully written
     336 *
     337 * @return EOK on success or non-zero error code
     338 *
     339 */
     340static int i8042_write(chardev_srv_t *srv, const void *data, size_t size,
     341    size_t *nwr)
    340342{
    341343        i8042_port_t *port = (i8042_port_t *)srv->srvs->sarg;
     
    357359       
    358360        fibril_mutex_unlock(&i8042->write_guard);
    359         return size;
     361        *nwr = size;
     362        return EOK;
    360363}
    361364
     
    365368 * @param buffer Data place
    366369 * @param size   Data place size
    367  *
    368  * @return Bytes read.
    369  *
    370  */
    371 static int i8042_read(chardev_srv_t *srv, void *dest, size_t size)
     370 * @param nread  Place to store number of bytes successfully read
     371 *
     372 * @return EOK on success or non-zero error code
     373 *
     374 */
     375static int i8042_read(chardev_srv_t *srv, void *dest, size_t size,
     376    size_t *nread)
    372377{
    373378        i8042_port_t *port = (i8042_port_t *)srv->srvs->sarg;
     
    387392        }
    388393       
    389         return i;
     394        *nread = i;
     395        return EOK;
    390396}
    391397
  • uspace/drv/char/pl050/pl050.c

    r19ea61d r677cad5  
    5454static int pl050_fun_offline(ddf_fun_t *);
    5555static void pl050_char_conn(ipc_callid_t, ipc_call_t *, void *);
    56 static int pl050_read(chardev_srv_t *, void *, size_t);
    57 static int pl050_write(chardev_srv_t *, const void *, size_t);
     56static int pl050_read(chardev_srv_t *, void *, size_t, size_t *);
     57static int pl050_write(chardev_srv_t *, const void *, size_t, size_t *);
    5858
    5959static driver_ops_t driver_ops = {
     
    236236}
    237237
    238 static int pl050_read(chardev_srv_t *srv, void *buffer, size_t size)
     238static int pl050_read(chardev_srv_t *srv, void *buffer, size_t size,
     239    size_t *nread)
    239240{
    240241        pl050_t *pl050 = (pl050_t *)srv->srvs->sarg;
     
    257258        fibril_mutex_unlock(&pl050->buf_lock);
    258259
    259         return size - left;
    260 }
    261 
    262 static int pl050_write(chardev_srv_t *srv, const void *data, size_t size)
     260        *nread = size - left;
     261        return EOK;
     262}
     263
     264static int pl050_write(chardev_srv_t *srv, const void *data, size_t size,
     265    size_t *nwritten)
    263266{
    264267        pl050_t *pl050 = (pl050_t *)srv->srvs->sarg;
     
    278281        ddf_msg(LVL_NOTE, "%s/pl050_write() success", pl050->name);
    279282
    280         return size;
     283        *nwritten = size;
     284        return EOK;
    281285}
    282286
  • uspace/lib/c/generic/io/chardev_srv.c

    r19ea61d r677cad5  
    4848        void *buf;
    4949        size_t size;
     50        size_t nread;
    5051        int rc;
    5152        ipc_callid_t rcallid;
     
    7071        }
    7172
    72         rc = srv->srvs->ops->read(srv, buf, size);
    73         if (rc < 0) {
     73        rc = srv->srvs->ops->read(srv, buf, size, &nread);
     74        if (rc != EOK && nread == 0) {
    7475                async_answer_0(rcallid, rc);
    7576                async_answer_0(callid, rc);
     
    7879        }
    7980
    80         async_data_read_finalize(rcallid, buf, size);
     81        async_data_read_finalize(rcallid, buf, nread);
    8182
    8283        free(buf);
    83         async_answer_2(callid, EOK, EOK, rc /* nread */);
     84        async_answer_2(callid, EOK, rc, nread);
    8485}
    8586
     
    8990        void *data;
    9091        size_t size;
     92        size_t nwr;
    9193        int rc;
    9294
     
    102104        }
    103105
    104         rc = srv->srvs->ops->write(srv, data, size);
     106        rc = srv->srvs->ops->write(srv, data, size, &nwr);
    105107        free(data);
    106         if (rc < 0)
     108        if (rc != EOK && nwr == 0) {
    107109                async_answer_0(callid, rc);
     110                return;
     111        }
    108112
    109         async_answer_2(callid, EOK, EOK, rc /* nwritten */);
     113        async_answer_2(callid, EOK, rc, nwr);
    110114}
    111115
  • uspace/lib/c/include/io/chardev_srv.h

    r19ea61d r677cad5  
    5959        int (*open)(chardev_srvs_t *, chardev_srv_t *);
    6060        int (*close)(chardev_srv_t *);
    61         int (*read)(chardev_srv_t *, void *, size_t);
    62         int (*write)(chardev_srv_t *, const void *, size_t);
     61        int (*read)(chardev_srv_t *, void *, size_t, size_t *);
     62        int (*write)(chardev_srv_t *, const void *, size_t, size_t *);
    6363};
    6464
Note: See TracChangeset for help on using the changeset viewer.