summaryrefslogtreecommitdiff
path: root/ghc/lib/std/cbits/fileObject.h
diff options
context:
space:
mode:
authorsimonmar <unknown>2001-05-18 16:54:11 +0000
committersimonmar <unknown>2001-05-18 16:54:11 +0000
commitd9af408e5c512501cfa991f5e4a76c9154bca917 (patch)
tree627365b7dad9c2a5e1d892a1f631690b46e24a11 /ghc/lib/std/cbits/fileObject.h
parent5f6f90850d5c82dc56d13bbc035d635e1cb2106b (diff)
downloadhaskell-d9af408e5c512501cfa991f5e4a76c9154bca917.tar.gz
[project @ 2001-05-18 16:54:04 by simonmar]
I/O library rewrite ------------------- This commit replaces the old C/Haskell I/O implementation with a new Haskell-only one using the new FFI & hsc2hs. main points: - lots of code deleted: we're about 3000 lines of C lighter, but the amount of Haskell code is about the same. - performance is ok: some operations are faster, others are slower. There's still some tuning to do, though. - the new library is designed to handle read/write streams much better: a read/write stream gets a special kind of handle internally called a "DuplexHandle", which actually contains two separate handles, one for writing and one for reading. The upshot is that you can do simultaneous reading and writing to/from a socket or FIFO without any locking problems. The effect is similar to calling socketToHandle twice, except that finalization works properly (creating two separate Handles could lead to the socket being closed too early when one of the Handles is GC'd). - hConnectTo and withHandleFor are gone (no one responded to my mail on GHC users, but we can always bring 'em back if necessary). - I made a half-hearted attempt at keeping the system-specific code in one place: see PrelPosix.hsc. - I've rearranged the I/O tests and added lots more. ghc/tests/lib/IO now contains Haskell 98-only IO tests, ghc/test/lib/{IOExts, Directory, Time} now contain tests for the relevant libraries. I haven't quite finished in here yet, the IO tests work but the others don't yet. - I haven't done anything about Unicode yet, but now we can start to discuss what needs doing here. The new library is using MutableByteArrays for its buffers because that turned out to be a *lot* easier (and quicker) than malloc'd buffers - I hope this won't cause trouble for unicode translations though. WARNING: Windows users refrain from updating until we've had a chance to fix any issues that arise. Testing: the basic H98 stuff has been pretty thoroughly tested, but the new duplex handle stuff is still a little green.
Diffstat (limited to 'ghc/lib/std/cbits/fileObject.h')
-rw-r--r--ghc/lib/std/cbits/fileObject.h82
1 files changed, 0 insertions, 82 deletions
diff --git a/ghc/lib/std/cbits/fileObject.h b/ghc/lib/std/cbits/fileObject.h
deleted file mode 100644
index def099d975..0000000000
--- a/ghc/lib/std/cbits/fileObject.h
+++ /dev/null
@@ -1,82 +0,0 @@
-#ifndef FILEOBJECT_H
-#define FILEOBJECT_H
-
-/*
- IOFileObjects are used as part of the IO.Handle
- implementation, ensuring that when handles are
- finalised, buffers are flushed and FILE* objects
- are closed (we really should be using file descriptors
- here..)
-
- */
-
-typedef struct _IOFileObject {
- int fd;
- void* buf;
-
- int bufWPtr; /* points to next position to write,
- bufRPtr >= bufWPtr <= bufSize.
-
- For read-only files, bufWPtr = bufSize
-
- bufWPtr = 0 => buffer is empty.
-
- */
- int bufRPtr; /* points to the next char to read
- -1 >= bufRPtr <= bufWPtr
-
- For write-only files, bufRPtr = 0
-
- bufRPtr == -1 => buffer is empty.
- */
- int bufSize; /* the size of the buffer, i.e. the number of bytes
- malloced */
- int flags;
- struct _IOFileObject* connectedTo;
-
-} IOFileObject;
-
-#define FILEOBJ_LB 2
-#define FILEOBJ_BB 4
-#define FILEOBJ_EOF 8
-#define FILEOBJ_READ 16
-#define FILEOBJ_WRITE 32
-#define FILEOBJ_STD 64
-/* The next two flags are used for RW file objects only.
- They indicate whether the last operation was a read or a write.
- (Need this info to determine whether a RW file object's
- buffer should be flushed before doing a subsequent
- read or write).
-*/
-#define FILEOBJ_RW_READ 256
-#define FILEOBJ_RW_WRITE 512
-/*
- * Under Win32, a file fd is not the same as a socket fd, so
- * we need to use separate r/w calls.
- */
-#define FILEOBJ_WINSOCK 1024
-#define FILEOBJ_BINARY 2048
-
-#define FILEOBJ_IS_EOF(x) ((x)->flags & FILEOBJ_EOF)
-#define FILEOBJ_SET_EOF(x) ((x)->flags |= FILEOBJ_EOF)
-#define FILEOBJ_CLEAR_EOF(x) ((x)->flags &= ~FILEOBJ_EOF)
-#define FILEOBJ_CLEAR_ERR(x) FILEOBJ_CLEAR_EOF(x)
-
-#define FILEOBJ_BLOCKED_READ -5
-#define FILEOBJ_BLOCKED_WRITE -6
-#define FILEOBJ_BLOCKED_CONN_WRITE -7
-
-#define FILEOBJ_UNBUFFERED(x) (!((x)->flags & FILEOBJ_LB) && !((x)->flags & FILEOBJ_BB))
-#define FILEOBJ_LINEBUFFERED(x) ((x)->flags & FILEOBJ_LB)
-#define FILEOBJ_BLOCKBUFFERED(x) ((x)->flags & FILEOBJ_BB)
-#define FILEOBJ_BUFFER_FULL(x) ((x)->bufWPtr >= (x)->bufSize)
-#define FILEOBJ_BUFFER_EMPTY(x) ((x)->bufRPtr == (x)->bufWPtr)
-#define FILEOBJ_HAS_PUSHBACKS(x) ((x)->buf != NULL && (x)->bufRPtr >= 0 && (x)->bufRPtr < (x)->bufWPtr)
-#define FILEOBJ_READABLE(x) ((x)->flags & FILEOBJ_READ)
-#define FILEOBJ_WRITEABLE(x) ((x)->flags & FILEOBJ_WRITE)
-#define FILEOBJ_JUST_READ(x) ((x)->flags & FILEOBJ_RW_READ)
-#define FILEOBJ_JUST_WRITTEN(x) ((x)->flags & FILEOBJ_RW_WRITE)
-#define FILEOBJ_NEEDS_FLUSHING(x) (!FILEOBJ_BUFFER_EMPTY(x))
-#define FILEOBJ_RW(x) (FILEOBJ_READABLE(x) && FILEOBJ_WRITEABLE(x))
-
-#endif /* FILEOBJECT_H */