abstract_io.h 1.65 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1
2
3
4
5
6
7
8
9
10
/* abstract_io.h
 *
 * This is the layer separating protocol processing from actual io.
 */

#ifndef LSH_ABSTRACT_IO_H_INCLUDED
#define LSH_ABSTRACT_IO_H_INCLUDED

#include "lsh_types.h"

11
#if 0
Niels Möller's avatar
Niels Möller committed
12
struct abstract_read;
13
typedef int (*abstract_read_f)(struct abstract_read *r,
Niels Möller's avatar
Niels Möller committed
14
			       UINT8 *buffer, UINT32 length);
15
16
#endif

17
18
19
20
21
22
23
24
25
26
/* A read-function returning n means:
 *
 * n > 0: n bytes were read successfully.
 * n = 0: No more data available, without blocking.
 * n = -1: Read failed.
 * n = -2: EOF.
 */
#define A_FAIL -1
#define A_EOF -2

Niels Möller's avatar
Niels Möller committed
27
28
struct abstract_read
{
29
30
  int (*read)(struct abstract_read **r,
	      UINT8 *buffer, UINT32 length);
Niels Möller's avatar
Niels Möller committed
31
32
};

33
#define A_READ(f, buffer, length) (f)->read(&(f), (buffer), (length))
Niels Möller's avatar
Niels Möller committed
34

35
#if 0
Niels Möller's avatar
Niels Möller committed
36
37
38
struct read_handler;
typedef struct read_handler * (*read_handler_f)(struct read_handler *closure,
						struct abstract_read *read);
39
40
41
#endif

/* May store a new handler into *h. */
Niels Möller's avatar
Niels Möller committed
42
43
struct read_handler
{
44
45
  int (*handler)(struct read_handler **h,
				  struct abstract_read *read);
Niels Möller's avatar
Niels Möller committed
46
47
};

48
#define READ_HANDLER(h, read) ((h)->handler(&(h), (read)))
49

50
51
52
/* FIXME: What should writers return? Perhaps a new writer,
 * analogous to read-handlers? */

53
#if 0
Niels Möller's avatar
Niels Möller committed
54
55
56
struct abstract_write;
typedef int (*abstract_write_f)(struct abstract_write *closure,
				struct lsh_string *packet);
57
58
#endif
/* May store a new handler into *w. */
Niels Möller's avatar
Niels Möller committed
59
60
struct abstract_write
{
61
62
  int (*write)(struct abstract_write **w,
	       struct lsh_string *packet);
Niels Möller's avatar
Niels Möller committed
63
64
};

65
#define A_WRITE(f, packet) ((f)->write(&(f), (packet)))
Niels Möller's avatar
Niels Möller committed
66
67
68
69
70
71
72
73

/* A processor that passes its result on to another processor */
struct abstract_write_pipe
{
  struct abstract_write super;
  struct abstract_write *next;
};

Niels Möller's avatar
Niels Möller committed
74
#endif /*LSH_ABSTRACT_IO_H_INCLUDED */