1 /* asyn_init(), asyn_read(), asyn_write(), asyn_ioctl(),
2 * asyn_wait(), asyn_synch(), asyn_close()
5 * Thise are just stub routines that are call compatible with
6 * the asynchio(3) library of Minix-vmd. See asynchio.h.
12 #define sigaction _sigaction
13 #define sigfillset _sigfillset
18 #include <sys/ioctl.h>
19 #include <sys/asynchio.h>
26 #define IO_INPROGRESS 1
34 static asynchio_t
*asyn_current
;
36 void asyn_init(asynchio_t
*asyn
)
42 static ssize_t
operation(int op
, asynchio_t
*asyn
, int fd
, int req
,
43 void *data
, ssize_t count
)
45 switch (asyn
->state
) {
47 if (asyn_current
!= asyn
&& asyn
->op
!= op
) abort();
56 asyn
->state
= IO_INPROGRESS
;
60 if (asyn_current
!= asyn
&& asyn
->op
!= op
) abort();
66 ssize_t
asyn_read(asynchio_t
*asyn
, int fd
, void *buf
, size_t len
)
68 return operation(OP_READ
, asyn
, fd
, 0, buf
, len
);
71 ssize_t
asyn_write(asynchio_t
*asyn
, int fd
, const void *buf
, size_t len
)
73 return operation(OP_WRITE
, asyn
, fd
, 0, (void *) buf
, len
);
76 int asyn_ioctl(asynchio_t
*asyn
, int fd
, unsigned long request
, void *data
)
78 return operation(OP_IOCTL
, asyn
, fd
, request
, data
, 0);
81 static void time_out(int sig
)
86 int asyn_wait(asynchio_t
*asyn
, int flags
, struct timeval
*to
)
89 unsigned old_timer
, new_timer
;
90 struct sigaction old_sa
, new_sa
;
92 if (asyn_current
!= asyn
) abort();
93 if (flags
& ASYN_NONBLOCK
) abort();
95 if (asyn
->state
== IO_RESULT
) {
103 if (to
->tv_sec
<= now
) { errno
= EINTR
; return -1; }
105 new_sa
.sa_handler
= time_out
;
106 sigfillset(&new_sa
.sa_mask
);
108 sigaction(SIGALRM
, &new_sa
, &old_sa
);
109 new_timer
= to
->tv_sec
- now
;
110 if (new_timer
< old_timer
) {
111 new_timer
= old_timer
;
117 asyn
->count
= pause();
120 asyn
->count
= read(asyn
->fd
, asyn
->data
, asyn
->count
);
124 asyn
->count
= write(asyn
->fd
, asyn
->data
, asyn
->count
);
128 asyn
->count
= ioctl(asyn
->fd
, asyn
->req
, asyn
->data
);
134 sigaction(SIGALRM
, &old_sa
, (struct sigaction
*)0);
138 if (asyn
->count
== -1 && asyn
->errno
== EINTR
) {
142 asyn
->state
= IO_RESULT
;
147 int asyn_synch(asynchio_t
*asyn
, int fd
)
151 int asyn_close(asynchio_t
*asyn
, int fd
)