[BACK]Return to file.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / aucat

Annotation of src/usr.bin/aucat/file.h, Revision 1.6

1.6     ! ratchov     1: /*     $OpenBSD: file.h,v 1.5 2008/12/29 17:59:08 ratchov Exp $        */
1.1       ratchov     2: /*
                      3:  * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
                      4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:  */
                     17: #ifndef FILE_H
                     18: #define FILE_H
                     19:
                     20: #include <sys/queue.h>
                     21: #include <sys/types.h>
                     22:
1.4       ratchov    23: struct file;
1.1       ratchov    24: struct aparams;
                     25: struct aproc;
                     26: struct abuf;
1.4       ratchov    27: struct pollfd;
                     28:
                     29: struct fileops {
                     30:        char *name;
                     31:        size_t size;
                     32:        void (*close)(struct file *);
                     33:        unsigned (*read)(struct file *, unsigned char *, unsigned);
1.6     ! ratchov    34:        unsigned (*write)(struct file *, unsigned char *, unsigned);
1.4       ratchov    35:        void (*start)(struct file *);
                     36:        void (*stop)(struct file *);
                     37:        int (*nfds)(struct file *);
                     38:        int (*pollfd)(struct file *, struct pollfd *, int);
                     39:        int (*revents)(struct file *, struct pollfd *);
                     40: };
1.1       ratchov    41:
                     42: struct file {
1.4       ratchov    43:        struct fileops *ops;
1.1       ratchov    44:        struct pollfd *pfd;             /* arg to poll(2) syscall */
                     45: #define FILE_ROK       0x1             /* file readable */
                     46: #define FILE_WOK       0x2             /* file writable */
                     47: #define FILE_EOF       0x4             /* eof on the read end */
1.4       ratchov    48: #define FILE_HUP       0x8             /* hang-up on the write end */
                     49: #define FILE_ZOMB      0x10            /* closed, but struct not freed */
                     50:        unsigned state;                 /* one of above */
                     51:        unsigned refs;                  /* reference counter */
1.1       ratchov    52:        char *name;                     /* for debug purposes */
                     53:        struct aproc *rproc, *wproc;    /* reader and/or writer */
                     54:        LIST_ENTRY(file) entry;
                     55: };
                     56:
                     57: LIST_HEAD(filelist,file);
                     58:
                     59: extern struct filelist file_list;
                     60:
1.4       ratchov    61: void filelist_init(void);
                     62: void filelist_done(void);
                     63: void filelist_unlisten(void);
                     64:
                     65: struct file *file_new(struct fileops *, char *, unsigned);
1.1       ratchov    66: void file_del(struct file *);
1.4       ratchov    67:
1.1       ratchov    68: void file_attach(struct file *, struct aproc *, struct aproc *);
                     69: unsigned file_read(struct file *, unsigned char *, unsigned);
                     70: unsigned file_write(struct file *, unsigned char *, unsigned);
                     71: int file_poll(void);
                     72: void file_eof(struct file *);
                     73: void file_hup(struct file *);
1.5       ratchov    74: void file_close(struct file *);
1.1       ratchov    75:
                     76: #endif /* !defined(FILE_H) */