#ifndef _NBBIO_H_INCLUDED_
#define _NBBIO_H_INCLUDED_
#include <events.h>
typedef void (*NBBIO_ACTION) (int, void *);
typedef struct {
int fd;
ssize_t bufsize;
char *label;
NBBIO_ACTION action;
void *context;
int flags;
char *read_buf;
ssize_t read_pend;
char *write_buf;
ssize_t write_pend;
} NBBIO;
#define NBBIO_FLAG_READ (1<<0)
#define NBBIO_FLAG_WRITE (1<<1)
#define NBBIO_FLAG_EOF (1<<2)
#define NBBIO_FLAG_ERROR (1<<3)
#define NBBIO_FLAG_TIMEOUT (1<<4)
#define NBBIO_OP_NAME(np) \
(((np)->flags & NBBIO_FLAG_READ) ? "read" : \
((np)->flags & NBBIO_FLAG_WRITE) ? "write" : \
"unknown")
#define NBBIO_MASK_ACTIVE \
(NBBIO_FLAG_READ | NBBIO_FLAG_WRITE)
#define NBBIO_MASK_ERROR \
(NBBIO_FLAG_EOF | NBBIO_FLAG_ERROR | NBBIO_FLAG_TIMEOUT)
#define NBBIO_BUFSIZE(np) (((np)->bufsize) + 0)
#define NBBIO_READ_PEND(np) ((np)->read_pend)
#define NBBIO_READ_BUF(np) ((np)->read_buf + 0)
#define NBBIO_WRITE_PEND(np) ((np)->write_pend)
#define NBBIO_WRITE_BUF(np) ((np)->write_buf + 0)
#define NBBIO_ACTIVE_FLAGS(np) ((np)->flags & NBBIO_MASK_ACTIVE)
#define NBBIO_ERROR_FLAGS(np) ((np)->flags & NBBIO_MASK_ERROR)
extern NBBIO *nbbio_create(int, ssize_t, const char *, NBBIO_ACTION, void *);
extern void nbbio_free(NBBIO *);
extern void nbbio_enable_read(NBBIO *, int);
extern void nbbio_enable_write(NBBIO *, int);
extern void nbbio_disable_readwrite(NBBIO *);
extern void nbbio_slumber(NBBIO *, int);
#endif