1 /* asyn_write() Author: Kees J. Bot
7 ssize_t
asyn_write(asynchio_t
*asyn
, int fd
, const void *buf
, size_t len
)
8 /* Nonblocking write(). (See asyn_read()). */
14 if ((unsigned) fd
>= FD_SETSIZE
) { errno
= EBADF
; return -1; }
15 afd
= &asyn
->asyn_afd
[fd
];
18 if ((afd
->afd_flags
= fcntl(fd
, F_GETFL
)) < 0) return -1;
22 if (afd
->afd_state
[SEL_WRITE
] == PENDING
) {
28 if (sigprocmask(SIG_SETMASK
, &mask
, &mask
) < 0) return -1;
29 (void) fcntl(fd
, F_SETFL
, afd
->afd_flags
| O_NONBLOCK
);
31 result
= write(fd
, buf
, len
);
34 (void) fcntl(fd
, F_SETFL
, afd
->afd_flags
);
35 (void) sigprocmask(SIG_SETMASK
, &mask
, nil
);
38 if (result
!= -1 || errno
!= EAGAIN
) {
39 afd
->afd_state
[SEL_WRITE
]= IDLE
;
44 afd
->afd_state
[SEL_WRITE
]= WAITING
;
45 FD_SET(fd
, &asyn
->asyn_fdset
[SEL_WRITE
]);