1gensio_set_sync(3)         Library Functions Manual         gensio_set_sync(3)
2
3
4

NAME

6       gensio_set_sync,  gensio_clear_sync,  gensio_read_s,  gensio_write_s  -
7       Synchronous I/O operations on a gensio
8

SYNOPSIS

10       #include <gensio/gensio.h>
11
12       int gensio_set_sync(struct gensio *io);
13
14       int gensio_clear_sync(struct gensio *io);
15
16       int gensio_read_s(struct gensio *io, gensiods *count,
17                           void *data, gensiods datalen,
18                           struct gensio_time *timeout);
19
20       int gensio_read_s_intr(struct gensio *io, gensiods *count,
21                           void *data, gensiods datalen,
22                           struct gensio_time *timeout);
23
24       int gensio_write_s(struct gensio *io, gensiods *count,
25                           const void *data, gensiods datalen,
26                           struct gensio_time *timeout);
27
28       int gensio_write_s_intr(struct gensio *io, gensiods *count,
29                           const void *data, gensiods datalen,
30                           struct gensio_time *timeout);
31

DESCRIPTION

33       Normal gensio operation is asynchronous callback  based.   This  serves
34       most programs fairly well, especially if they are listening to multiple
35       connections at the same time.  You wouldn't want to  write  a  compiler
36       this  way,  but if you are writing something that is driven by external
37       events, this event-driven type of programming works well.  If you think
38       about  it,  if you are using something like poll, select, etc., you al‐
39       most always end up with something like:
40
41              poll(fds...)
42              if (fd1 read is set)
43                 call fd1_read_handler()
44              if (fd1 write is set)
45                 call fd1_write_handler()
46              if (fd2 read is set)
47                 ...
48
49       The gensio handling does all this for you.   Just  register  a  handler
50       with  the gensio to get the read and write calls.  It's more efficient,
51       neater, and you end up with less code.
52
53       But occasionally you need to do something synchronous with the  program
54       execution.   For  instance,  in gtlsshd, if the initial certificate and
55       password verification fails, it uses PAM to handle reading the password
56       from  the  remote  gensio.   This requires synchronous I/O, and it uses
57       this capability.
58
59       gensio_set_sync sets up the gensio for  synchronous  I/O.   If  you  do
60       this,  the  event  callback that is currently registered will no longer
61       receive read and write callbacks.  It *will* receive  other  callbacks.
62       You  must  call this before doing any of the synchronous read and write
63       operations.  This function will block  (while  handling  normal  gensio
64       events) until no callbacks are active.
65
66       gensio_clear_sync returns the gensio to asynchronous I/O.  The callback
67       will be restored to the one that was  set  when  gensio_set_sync()  was
68       called.
69
70       gensio_read_s  Waits  for  data  from  the gensio, up to datalen bytes.
71       count (if not NULL) will be updated to the actual number of bytes read.
72       This  will  wait  for  any read and will return whatever that read was,
73       even if it is less than datalen.  This function waits for the amount of
74       time  in  timeout.   timeout  is  updated to the amount of time left to
75       wait.  If timeout is NULL, wait forever.
76
77       gensio_write_s writes data to the gensio.  count (if not NULL) will  be
78       updated to the actual number of bytes written.  This function will wait
79       until either the timeout occurs or all the data is written.  This func‐
80       tion  waits  for  the amount of time in timeout.  timeout is updated to
81       the amount of time left to wait.  If timeout is NULL, wait forever.
82
83       gensio_read_s_intr and gensio_write_s_intr are like  gensio_read_s  and
84       gensio_write_s,  but they return immediately if an signal interrupt oc‐
85       curs.  On systems without signals, these are the same as  gensio_read_s
86       and gensio_write_s.
87
88

RETURN VALUES

90       Zero is returned on success, or a gensio error on failure.
91

SEE ALSO

93       gensio_err(3), gensio(5)
94
95
96
97                                  27 Feb 2019               gensio_set_sync(3)
Impressum