]> mj.ucw.cz Git - libucw.git/blob - lib/asio.h
Merge with git+ssh://cvs.ucw.cz/projects/sherlock/GIT/sherlock.git
[libucw.git] / lib / asio.h
1 /*
2  *      UCW Library -- Asynchronous I/O
3  *
4  *      (c) 2006 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #ifndef _UCW_ASIO_H
11 #define _UCW_ASIO_H
12
13 #include "lib/workqueue.h"
14 #include "lib/clists.h"
15
16 /* FIXME: Comment, especially on request ordering */
17
18 struct asio_queue {
19   uns buffer_size;                      // How large buffers do we use [user-settable]
20   uns max_writebacks;                   // Maximum number of writeback requests active [user-settable]
21   uns allocated_requests;
22   uns running_requests;                 // Total number of running requests
23   uns running_writebacks;               // How many of them are writebacks
24   clist idle_list;                      // Recycled requests waiting for get
25   clist done_list;                      // Finished requests
26   struct work_queue queue;
27   uns use_count;                        // For use by the caller
28 };
29
30 enum asio_op {
31   ASIO_FREE,
32   ASIO_READ,
33   ASIO_WRITE,
34   ASIO_WRITE_BACK,                      // Background write with no success notification
35 };
36
37 struct asio_request {
38   struct work work;                     // asio_requests are internally just work nodes
39   struct asio_queue *queue;
40   byte *buffer;
41   int fd;
42   enum asio_op op;
43   uns len;
44   int status;
45   int returned_errno;
46   int submitted;
47   void *user_data;                      // For use by the caller
48 };
49
50 void asio_init_queue(struct asio_queue *q);                     // Initialize a new queue
51 void asio_cleanup_queue(struct asio_queue *q);
52 struct asio_request *asio_get(struct asio_queue *q);            // Get an empty request
53 void asio_submit(struct asio_request *r);                       // Submit the request (can block if too many writebacks)
54 struct asio_request *asio_wait(struct asio_queue *q);           // Wait for the first finished request, NULL if no more
55 void asio_put(struct asio_request *r);                          // Return a finished request for recycling
56 void asio_sync(struct asio_queue *q);                           // Wait until all requests are finished
57
58 #endif  /* !_UCW_ASIO_H */