suitcase

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

io.h (2934B)


      1 #ifndef   _SC_IO_IO_H
      2 #define   _SC_IO_IO_H
      3 
      4 #define	int64	int64_t
      5 
      6 #ifndef BERNSTEINLY_CORRECT
      7 #define taitype		tai6464
      8 #else
      9 #define	taitype		taia
     10 #endif
     11 
     12 extern int io_readfile(int64 *d, const char *s);
     13 extern int io_createfile(int64 *d, const char *s);
     14 extern int io_pipe(int64 *d); // must be of length 2
     15 
     16 /* io_close always succeeds in deallocating the memory
     17  * used by the io library related to this, but the underlying
     18  * close(fd) system call may give an error return. in such a case
     19  * io_close is to be considered successful, but if you aren't
     20  * BERNSTEINLY_CORRECT you can harvest the output.
     21  */
     22 #ifndef BERNSTEINLY_CORRECT
     23 extern int io_close(int64 d);
     24 #else
     25 extern void io_close(int64 d);
     26 #endif
     27 
     28 extern int64 io_tryread(int64, const char *, int64);
     29 extern int64 io_waitread(int64, const char *, int64);
     30 
     31 extern int64 io_trywrite(int64, const char *, int64);
     32 extern int64 io_waitwrite(int64, const char *, int64);
     33 
     34 
     35 /* in thread-safe io, timeout can return -1 EAGAIN if a writer
     36  * lock to the structure is not currently available.
     37  * waittimeout will instead hang the current thread until the
     38  * lock comes up.
     39  * thread-safe CORRECT io will always hang.
     40  * for reliably nonblock timeout sets, always use trytimeout,
     41  * and for reliably block timeout sets, always use waittimeout.
     42  * both of these functions are extensions in Suitcase io.
     43  */
     44 #ifndef BERNSTEINLY_CORRECT
     45 extern void io_timeout(int64, taitype);
     46 #define io_waittimeout(i, t) io_timeout(i, t)
     47 extern int io_trytimeout(int64, taitype);
     48 #else
     49 extern int io_timeout(int64, taitype);
     50 extern void io_waittimeout(int64, taitype);
     51 #define io_trytimeout(i, t) io_timeout(i, t)
     52 #endif
     53 
     54 extern void io_wantread(int64);
     55 extern void io_wantwrite(int64);
     56 extern void io_dontwantread(int64);
     57 extern void io_dontwantwrite(int64);
     58 
     59 /* io_trywant* family functions will return -1 EAGAIN if a writer
     60  * lock to the structure is not currently available.
     61  * this enables a thread to go to sleep with the desired value in
     62  * its TLS, and an alarm connected to the lock available light,
     63  * if it can't set the lock right now.
     64  * bernstein standard versions of these functions will instead
     65  * hang the current thread until the lock is available.
     66  */
     67 #ifndef BERNSTEINLY_CORRECT
     68 extern int io_trywantread(int64);
     69 extern int io_trywantwrite(int64);
     70 extern int io_trydontwantread(int64);
     71 extern int io_trydontwantwrite(int64);
     72 #endif
     73 
     74 /* int versions of io_wait family functions will return the number
     75  * of FDs they've put into the queue, or on systems with native event
     76  * queues, the number of FDs the OS reports
     77  */
     78 #ifndef BERNSTEINLY_CORRECT
     79 extern int64 io_waituntil(taitype);
     80 extern int64 io_wait();
     81 extern int64 io_check();
     82 #else
     83 extern void io_waituntil(taitype);
     84 extern void io_wait();
     85 extern void io_check();
     86 #endif
     87 
     88 // returns an index (identical to an fd number for which this is true)
     89 extern int64 io_canread();
     90 extern int64 io_canwrite();
     91 
     92 #endif // _SC_IO_IO_H