5 IOFileObjects are used as part of the IO.Handle
6 implementation, ensuring that when handles are
7 finalised, buffers are flushed and FILE* objects
8 are closed (we really should be using file descriptors
13 typedef struct _IOFileObject {
17 int bufStart; /* offset of start of data waiting to
18 be written. This may be non-zero in
19 the case where we wrote out some of the
20 buffer, and then blocked.
22 NOTE: this field should be non-zero *only*
23 when we just blocked on a call to writeBuffer,
24 and we're going to restart the call when
25 we unblock. It should be zero at all other
29 int bufWPtr; /* points to next position to write,
30 bufRPtr >= bufWPtr <= bufSize.
32 For read-only files, bufWPtr = bufSize
34 bufWPtr = 0 => buffer is empty.
37 int bufRPtr; /* points to the next char to read
38 -1 >= bufRPtr <= bufWPtr
40 For write-only files, bufRPtr = 0
42 bufRPtr == -1 => buffer is empty.
46 struct _IOFileObject* connectedTo;
52 #define FILEOBJ_READ 16
53 #define FILEOBJ_WRITE 32
54 #define FILEOBJ_STD 64
55 /* The next two flags are used for RW file objects only.
56 They indicate whether the last operation was a read or a write.
57 (Need this info to determine whether a RW file object's
58 buffer should be flushed before doing a subsequent
61 #define FILEOBJ_RW_READ 256
62 #define FILEOBJ_RW_WRITE 512
64 * Under Win32, a file fd is not the same as a socket fd, so
65 * we need to use separate r/w calls.
67 #define FILEOBJ_WINSOCK 1024
68 #define FILEOBJ_BINARY 2048
70 #define FILEOBJ_IS_EOF(x) ((x)->flags & FILEOBJ_EOF)
71 #define FILEOBJ_SET_EOF(x) ((x)->flags |= FILEOBJ_EOF)
72 #define FILEOBJ_CLEAR_EOF(x) ((x)->flags &= ~FILEOBJ_EOF)
73 #define FILEOBJ_CLEAR_ERR(x) FILEOBJ_CLEAR_EOF(x)
75 #define FILEOBJ_BLOCKED_READ -5
76 #define FILEOBJ_BLOCKED_WRITE -6
77 #define FILEOBJ_BLOCKED_CONN_WRITE -7
79 #define FILEOBJ_UNBUFFERED(x) (!((x)->flags & FILEOBJ_LB) && !((x)->flags & FILEOBJ_BB))
80 #define FILEOBJ_LINEBUFFERED(x) ((x)->flags & FILEOBJ_LB)
81 #define FILEOBJ_BLOCKBUFFERED(x) ((x)->flags & FILEOBJ_BB)
82 #define FILEOBJ_BUFFER_FULL(x) ((x)->bufWPtr >= (x)->bufSize)
83 #define FILEOBJ_BUFFER_EMPTY(x) ((x)->bufRPtr == (x)->bufWPtr)
84 #define FILEOBJ_HAS_PUSHBACKS(x) ((x)->buf != NULL && (x)->bufRPtr >= 0 && (x)->bufRPtr < (x)->bufWPtr)
85 #define FILEOBJ_READABLE(x) ((x)->flags & FILEOBJ_READ)
86 #define FILEOBJ_WRITEABLE(x) ((x)->flags & FILEOBJ_WRITE)
87 #define FILEOBJ_JUST_READ(x) ((x)->flags & FILEOBJ_RW_READ)
88 #define FILEOBJ_JUST_WRITTEN(x) ((x)->flags & FILEOBJ_RW_WRITE)
89 #define FILEOBJ_NEEDS_FLUSHING(x) (!FILEOBJ_BUFFER_EMPTY(x))
90 #define FILEOBJ_RW(x) (FILEOBJ_READABLE(x) && FILEOBJ_WRITEABLE(x))
92 #endif /* FILEOBJECT_H */