Postfix3.3.1
nbbio.h
[詳解]
1 #ifndef _NBBIO_H_INCLUDED_
2 #define _NBBIO_H_INCLUDED_
3 
4 /*++
5 /* NAME
6 /* nbbio 3h
7 /* SUMMARY
8 /* non-blocking buffered I/O
9 /* SYNOPSIS
10 /* #include "nbbio.h"
11 /* DESCRIPTION
12 /* .nf
13 
14  /*
15  * Utility library.
16  */
17 #include <events.h> /* Needed for EVENT_READ etc. */
18 
19  /*
20  * External interface. All structure members are private.
21  */
22 typedef void (*NBBIO_ACTION) (int, void *);
23 
24 typedef struct {
25  int fd; /* socket file descriptor */
26  ssize_t bufsize; /* read/write buffer size */
27  char *label; /* diagnostics */
28  NBBIO_ACTION action; /* call-back routine */
29  void *context; /* call-back context */
30  int flags; /* buffer-pair status */
31 
32  char *read_buf; /* start of buffer */
33  ssize_t read_pend; /* nr of unread bytes */
34 
35  char *write_buf; /* start of buffer */
36  ssize_t write_pend; /* nr of unwritten bytes */
37 } NBBIO;
38 
39 #define NBBIO_FLAG_READ (1<<0)
40 #define NBBIO_FLAG_WRITE (1<<1)
41 #define NBBIO_FLAG_EOF (1<<2)
42 #define NBBIO_FLAG_ERROR (1<<3)
43 #define NBBIO_FLAG_TIMEOUT (1<<4)
44 
45 #define NBBIO_OP_NAME(np) \
46  (((np)->flags & NBBIO_FLAG_READ) ? "read" : \
47  ((np)->flags & NBBIO_FLAG_WRITE) ? "write" : \
48  "unknown")
49 
50 #define NBBIO_MASK_ACTIVE \
51  (NBBIO_FLAG_READ | NBBIO_FLAG_WRITE)
52 
53 #define NBBIO_MASK_ERROR \
54  (NBBIO_FLAG_EOF | NBBIO_FLAG_ERROR | NBBIO_FLAG_TIMEOUT)
55 
56 #define NBBIO_BUFSIZE(np) (((np)->bufsize) + 0) /* Read-only */
57 
58 #define NBBIO_READ_PEND(np) ((np)->read_pend)
59 #define NBBIO_READ_BUF(np) ((np)->read_buf + 0) /* Read-only */
60 
61 #define NBBIO_WRITE_PEND(np) ((np)->write_pend)
62 #define NBBIO_WRITE_BUF(np) ((np)->write_buf + 0) /* Read-only */
63 
64 #define NBBIO_ACTIVE_FLAGS(np) ((np)->flags & NBBIO_MASK_ACTIVE)
65 #define NBBIO_ERROR_FLAGS(np) ((np)->flags & NBBIO_MASK_ERROR)
66 
67 extern NBBIO *nbbio_create(int, ssize_t, const char *, NBBIO_ACTION, void *);
68 extern void nbbio_free(NBBIO *);
69 extern void nbbio_enable_read(NBBIO *, int);
70 extern void nbbio_enable_write(NBBIO *, int);
71 extern void nbbio_disable_readwrite(NBBIO *);
72 extern void nbbio_slumber(NBBIO *, int);
73 
74 /* LICENSE
75 /* .ad
76 /* .fi
77 /* The Secure Mailer license must be distributed with this software.
78 /* AUTHOR(S)
79 /* Wietse Venema
80 /* IBM T.J. Watson Research
81 /* P.O. Box 704
82 /* Yorktown Heights, NY 10598, USA
83 /*--*/
84 
85 #endif
ssize_t bufsize
Definition: nbbio.h:26
void nbbio_disable_readwrite(NBBIO *)
Definition: nbbio.c:310
void nbbio_enable_write(NBBIO *, int)
Definition: nbbio.c:283
int fd
Definition: nbbio.h:25
ssize_t read_pend
Definition: nbbio.h:33
void nbbio_free(NBBIO *)
Definition: nbbio.c:363
void nbbio_enable_read(NBBIO *, int)
Definition: nbbio.c:256
char * label
Definition: nbbio.h:27
void * context
Definition: nbbio.h:29
ssize_t write_pend
Definition: nbbio.h:36
Definition: nbbio.h:24
int flags
Definition: nbbio.h:30
char * write_buf
Definition: nbbio.h:35
NBBIO * nbbio_create(int, ssize_t, const char *, NBBIO_ACTION, void *)
Definition: nbbio.c:328
int int
Definition: smtpd_proxy.h:21
void nbbio_slumber(NBBIO *, int)
Definition: nbbio.c:319
char * read_buf
Definition: nbbio.h:32
NBBIO_ACTION action
Definition: nbbio.h:28
void(* NBBIO_ACTION)(int, void *)
Definition: nbbio.h:22