File: async.c

package info (click to toggle)
foot 1.6.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,492 kB
  • sloc: ansic: 21,242; python: 170; sh: 26; makefile: 7
file content (35 lines) | stat: -rw-r--r-- 744 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "async.h"

#include <stdint.h>
#include <errno.h>
#include <unistd.h>

#define LOG_MODULE "async"
#define LOG_ENABLE_DBG 0
#include "log.h"

enum async_write_status
async_write(int fd, const void *_data, size_t len, size_t *idx)
{
    const uint8_t *const data = _data;
    size_t left = len - *idx;

    while (left > 0) {
        ssize_t ret = write(fd, &data[*idx], left);

        if (ret < 0) {
            if (errno == EAGAIN || errno == EWOULDBLOCK)
                return ASYNC_WRITE_REMAIN;

            return ASYNC_WRITE_ERR;
        }

        LOG_DBG("wrote %zd bytes of %zu (%zu left) to FD=%d",
                ret, left, left - ret, fd);

        *idx += ret;
        left -= ret;
    }

    return ASYNC_WRITE_DONE;
}