WvStreams
wvmagicloopback.cc
1/*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2004 Net Integration Technologies, Inc.
4 */
5
6#include "wvmagicloopback.h"
7
8WvMagicLoopback::WvMagicLoopback(size_t size)
9 : circle(size), loop()
10{
11}
12
13
15{
16 loop.drain();
17
18 loop.pre_select(si);
19
20 if ((si.wants.readable && circle.used() > 0) ||
21 (si.wants.writable && circle.left() > 0))
22 si.msec_timeout = 0;
23}
24
25
27{
28 bool ret = WvStream::post_select(si);
29
30 if ((si.wants.readable && circle.used() > 0) ||
31 (si.wants.writable && circle.left() > 0))
32 ret = true;
33
34 return ret;
35}
36
37
38size_t WvMagicLoopback::uread(void *buf, size_t len)
39{
40 return circle.get(buf, len);
41}
42
43
44size_t WvMagicLoopback::uwrite(const void *buf, size_t len)
45{
46 len = circle.put(buf, len);
47
48 if (len > 0)
49 loop.uwrite("", 1); // Make select wake up
50
51 return len;
52}
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling ::select().
Definition: wvfdstream.cc:214
virtual size_t uwrite(const void *buf, size_t count)
unbuffered I/O functions; these ignore the buffer, which is handled by write().
Definition: wvfdstream.cc:162
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling ::select().
virtual size_t uread(void *buf, size_t len)
unbuffered I/O functions; these ignore the buffer, which is handled by read().
virtual size_t uwrite(const void *buf, size_t len)
unbuffered I/O functions; these ignore the buffer, which is handled by write().
virtual bool post_select(SelectInfo &si)
post_select() is called after ::select(), and returns true if this object is now ready.
virtual bool post_select(SelectInfo &si)
post_select() is called after ::select(), and returns true if this object is now ready.
Definition: wvstream.cc:875
void drain()
drain the input buffer (read and discard data until select(0) returns false)
Definition: wvstream.cc:699
the data structure used by pre_select()/post_select() and internally by select().
Definition: iwvstream.h:50