summaryrefslogtreecommitdiff
path: root/comm/Channel.cc
diff options
context:
space:
mode:
Diffstat (limited to 'comm/Channel.cc')
-rw-r--r--comm/Channel.cc139
1 files changed, 69 insertions, 70 deletions
diff --git a/comm/Channel.cc b/comm/Channel.cc
index 75a6a33..f396a40 100644
--- a/comm/Channel.cc
+++ b/comm/Channel.cc
@@ -10,16 +10,18 @@
*
* $Id$
* $CurLog$
+ * Smart(ies) removed by Stephane Sire
+ * Removed ReadHandler and WriteHandler
*/
#ifdef __GNUG__
#pragma implementation "Channel.h"
#endif
#include "Channel.h"
-#include "Multiplexer.h"
+#include "Scheduler.h"
#include "MsgBuffer.h"
#include "error.h"
-#include "ccu/String.h"
+#include "ivl/String.h"
#include <stdlib.h>
#include <stdio.h>
@@ -35,7 +37,7 @@ static int Inited = 0;
/*?nodoc?*/
void
-UchFilDes :: Use (int fd)
+IvlFilDes :: Use (int fd)
{
if (fd < 0)
return;
@@ -50,7 +52,7 @@ UchFilDes :: Use (int fd)
/*?nodoc?*/
void
-UchFilDes :: Unuse (int fd)
+IvlFilDes :: Unuse (int fd)
{
if (fd < 0)
return;
@@ -60,20 +62,20 @@ UchFilDes :: Unuse (int fd)
/*?nodoc?*/
char*
-UchFilDes :: StrRepr (char* buf)
+IvlFilDes :: StrRepr (char* buf)
{
sprintf (buf, "%d", Fd);
return buf;
}
-/*?class UchFilDes
+/*?class IvlFilDes
This class implements objects representing Unix file descriptors.
-When the associated file descriptor is -1, the \typ{UchFilDes} is said to be closed,
+When the associated file descriptor is -1, the \typ{IvlFilDes} is said to be closed,
else it is said to be opened.
Because several objects of this class can refer to the same file descriptor,
the destructor closes the file descriptor only if it is the last object referring to this file descriptor.
This is implemented with the help of a reference count, the overloading of \fun{operator =}
-and the definition of the constructor \fun{UchFilDes(const UchFilDes\&)}.
+and the definition of the constructor \fun{IvlFilDes(const IvlFilDes\&)}.
All member functions described here are inline for maximum efficiency.
?*/
@@ -82,30 +84,30 @@ All member functions described here are inline for maximum efficiency.
/*?
Construct a closed file descriptor.
?*/
-UchFilDes :: UchFilDes ()
+IvlFilDes :: IvlFilDes ()
{ }
/*?
Construct an open file descriptor for the Unix file descriptor \var{fd}.
-In particular, this makes it possible to pass an integer where a \typ{UchFilDes} is normally expected.
+In particular, this makes it possible to pass an integer where a \typ{IvlFilDes} is normally expected.
This is most useful when using Unix file descriptors.
?*/
-UchFilDes :: UchFilDes (int fd)
+IvlFilDes :: IvlFilDes (int fd)
{ }
/*?
-This conversion operator makes it possible to pass a \typ{UchFilDes} argument where
+This conversion operator makes it possible to pass a \typ{IvlFilDes} argument where
an integer is expected. This is most useful for system calls.
?*/
int
-UchFilDes :: operator int ()
+IvlFilDes :: operator int ()
{ }
/*?
Return the Unix file descriptor, or -1 if it is closed.
?*/
int
-UchFilDes :: FilDes ()
+IvlFilDes :: FilDes ()
{ }
/*?
@@ -113,7 +115,7 @@ Open the object on file descriptor \var{fd}.
If it was already opened, it is closed first.
?*/
void
-UchFilDes :: Open (int fd)
+IvlFilDes :: Open (int fd)
{ }
/*?
@@ -122,14 +124,14 @@ only if it was the last reference to it.
\fun{Close} is automatically called by the destructor.
?*/
void
-UchFilDes :: Close ()
+IvlFilDes :: Close ()
{ }
/*?
Return true if the object is opened, false else.
?*/
bool
-UchFilDes :: Opened ()
+IvlFilDes :: Opened ()
{ }
/*?
@@ -138,7 +140,7 @@ This is the Unix \fun{read} system call.
For efficiency, this function does not test whether the file descriptor is opened.
?*/
int
-UchFilDes :: Read (byte* b, int n)
+IvlFilDes :: Read (byte* b, int n)
{ }
/*?
@@ -147,29 +149,29 @@ This is the Unix \fun{write} system call.
For efficiency, this function does not test whether the file descriptor is opened.
?*/
int
-UchFilDes :: Write (byte* b, int n)
+IvlFilDes :: Write (byte* b, int n)
{ }
#endif /* DOC */
-/*?class UchChannel
-A \typ{UchChannel} is basically a file descriptor, with more strict semantics than a \typ{UchFilDes}.
+/*?class IvlChannel
+A \typ{IvlChannel} is basically a file descriptor, with more strict semantics than a \typ{IvlFilDes}.
A channel is immutable: once initialized, it cannot change its file descriptor.
It has a mode, of type \typ{^{IOMODE}}, with possible values
\var{IONone}, \var{IORead}, \var{IOWrite}, \var{IOReadWrite},
\var{IOSelect}, \var{IOReadSelect}, \var{IOWriteSelect}, \var{IOAll}.
\index{IOMODE :: IONone}\index{IOMODE :: IORead}\index{IOMODE :: IOWrite}\index{IOMODE :: IOReadWrite}\index{IOMODE :: IOSelect}\index{IOMODE :: IOReadSelect}\index{IOMODE :: IOWriteSelect}\index{IOMODE :: IOAll}
-Before being initialized, a UchChannel.has mode \var{IONone} and is said to be closed.
+Before being initialized, a IvlChannel.has mode \var{IONone} and is said to be closed.
-A UchChannel.has a number of virtual functions.
+A IvlChannel.has a number of virtual functions.
The destructor is virtual; this is useful for classes that store pointers to objects
-of a class derived from \typ{UchChannel} (like in the class \typ{UchSocket}).
+of a class derived from \typ{IvlChannel} (like in the class \typ{IvlSocket}).
The functions \fun{HandleSelect}, \fun{HandleRead} and \fun{HandleWrite}
are intended to give a channel the ability to automatically handle input/output,
for instance for use with the \fun{select} system call.
-Such capabilities are used and thus illustrated in class \typ{UchMultiplexer}.
+Such capabilities are used and thus illustrated in class \typ{IvlScheduler}.
-A \typ{UchChannel} can be associated with only one \typ{UchBaseMultiplexer}
+A \typ{IvlChannel} can be associated with only one \typ{IvlBaseScheduler}
at a time by using the functions \fun{Add} and \fun{Remove} of the Channel.
When it is added/removed from its Multiplexor,
virtual function \fun{Added/Removed} is called.
@@ -178,8 +180,8 @@ virtual function \fun{Added/Removed} is called.
/*?
Construct a closed channel.
?*/
-UchChannel :: UchChannel ()
-: UchIOS (),
+IvlChannel :: IvlChannel ()
+: IvlIOS (),
Fd (),
Mode (IONone),
Mpx (0)
@@ -189,8 +191,8 @@ UchChannel :: UchChannel ()
/*?
Construct an open channel on file descriptor \var{fd} with mode \var{io}.
?*/
-UchChannel :: UchChannel (int fd, IOMODE io)
-: UchIOS (),
+IvlChannel :: IvlChannel (int fd, IOMODE io)
+: IvlIOS (),
Fd (fd),
Mode (io),
Mpx (0)
@@ -198,8 +200,8 @@ UchChannel :: UchChannel (int fd, IOMODE io)
}
/*?nodoc?*/
-UchChannel :: UchChannel (const UchChannel& ch)
-: UchIOS (ch),
+IvlChannel :: IvlChannel (const IvlChannel& ch)
+: IvlIOS (ch),
Fd (ch.Fd),
Mode (ch.Mode),
Mpx (ch.Mpx)
@@ -215,12 +217,12 @@ in order to associate a file descriptor to it.
Because a channel is immutable, this can be done only once.
?*/
void
-UchChannel :: Open (int fd)
+IvlChannel :: Open (int fd)
{ }
/*?nextdoc?*/
IOMODE
-UchChannel :: IOMode ()
+IvlChannel :: IOMode ()
{
}
@@ -228,23 +230,22 @@ UchChannel :: IOMode ()
Return/set the mode of the channel.
?*/
void
-UchChannel :: SetMode (IOMODE io)
+IvlChannel :: SetMode (IOMODE io)
{ }
#endif /* DOC */
-
/*?
Destroy the channel. It is removed from its multiplexor if necessary.
?*/
-UchChannel :: ~UchChannel ()
+IvlChannel :: ~IvlChannel ()
{
Remove ();
}
/*?nextdoc?*/
void
-UchChannel :: Added ()
+IvlChannel :: Added ()
{
}
@@ -254,13 +255,13 @@ These virtual functions are called whenever a channel is added to
nothing.
?*/
void
-UchChannel :: Removed ()
+IvlChannel :: Removed ()
{
}
/*?nextdoc?*/
void
-UchChannel :: Add (UchBaseMultiplexer* m)
+IvlChannel :: Add (IvlBaseScheduler* m)
{
if (Mpx != m) {
if (Mpx != 0)
@@ -279,7 +280,7 @@ If a channel with the same file descriptor as the one being added
is already in the multiplexor, the old channel is first removed.
?*/
void
-UchChannel :: Remove ()
+IvlChannel :: Remove ()
{
if (Mpx && Mpx->Remove (*this)) {
Removed ();
@@ -289,30 +290,30 @@ UchChannel :: Remove ()
/*?nextdoc?*/
void
-UchChannel :: HandleWrite ()
+IvlChannel :: HandleWrite ()
{
}
/*?
-These virtual functions are called by a \typ{UchMultiplexer} when data can be written
+These virtual functions are called by a \typ{IvlScheduler} when data can be written
to the channel or read from the channel.
The default implementation does nothing.
?*/
void
-UchChannel :: HandleRead ()
+IvlChannel :: HandleRead ()
{
}
#if 0
/*?
-This virtual function is called by a \typ{UchMultiplexer} before making a \fun{select} call.
+This virtual function is called by a \typ{IvlScheduler} before making a \fun{select} call.
It is intended to handle any background task or buffered input/output associated to the channel.
If it returns true, the channel set scan functions will return before performing the select call.
-See the class \typ{UchMultiplexer} for more details.
+See the class \typ{IvlScheduler} for more details.
The default implementation does nothing but returning false.
?*/
bool
-UchChannel :: HandleSelect ()
+IvlChannel :: HandleSelect ()
{
return false;
}
@@ -322,21 +323,21 @@ UchChannel :: HandleSelect ()
/*?nextdoc?*/
int
-UchChannel :: Read (byte* b, int n)
+IvlChannel :: Read (byte* b, int n)
{ }
/*?
-The Unix \fun{read} and \fun{write} system calls, as in class \typ{UchFilDes}.
+The Unix \fun{read} and \fun{write} system calls, as in class \typ{IvlFilDes}.
?*/
int
-UchChannel :: Write (byte* b, int n)
+IvlChannel :: Write (byte* b, int n)
{ }
#endif /* DOC */
/*?nextdoc?*/
int
-UchChannel :: Read (UchMsgBuffer& b)
+IvlChannel :: Read (IvlMsgBuffer& b)
{
int l = b.FreeLength ();
if (! l)
@@ -348,12 +349,12 @@ UchChannel :: Read (UchMsgBuffer& b)
}
/*?
-The Unix \fun{read} and \fun{write} system calls applied to a \typ{UchMsgBuffer}.
+The Unix \fun{read} and \fun{write} system calls applied to a \typ{IvlMsgBuffer}.
They return the number of bytes transferred, -1 if a system error occurred,
-2 if the buffer is empty when writing or full when reading.
?*/
int
-UchChannel :: Write (UchMsgBuffer& b)
+IvlChannel :: Write (IvlMsgBuffer& b)
{
int l = b.BufLength ();
if (! l)
@@ -366,7 +367,7 @@ UchChannel :: Write (UchMsgBuffer& b)
/*?nextdoc?*/
bool
-UchChannel :: ReadBuffer (UchMsgBuffer& b)
+IvlChannel :: ReadBuffer (IvlMsgBuffer& b)
{
int n;
errno = 0;
@@ -380,7 +381,7 @@ These functions repeatedly call \fun{Read} or \fun{Write} until the whole buffer
transferred or a system error occurred. In case of an error, they return false, else true.
?*/
bool
-UchChannel :: WriteBuffer (UchMsgBuffer& b)
+IvlChannel :: WriteBuffer (IvlMsgBuffer& b)
{
int n;
errno = 0;
@@ -390,69 +391,67 @@ UchChannel :: WriteBuffer (UchMsgBuffer& b)
}
void
-UchChannel :: WriteLong (lword l)
+IvlChannel :: WriteLong (lword l)
{
Write ((byte*)&l, lwsize);
}
void
-UchChannel :: WriteShort (sword s)
+IvlChannel :: WriteShort (sword s)
{
Write ((byte*)&s, swsize);
}
void
-UchChannel :: WriteByte (byte b)
+IvlChannel :: WriteByte (byte b)
{
Write (&b, 1);
}
void
-UchChannel :: WriteChar (char c)
+IvlChannel :: WriteChar (char c)
{
Write ((byte*)&c, 1);
}
void
-UchChannel :: WriteString (const char* s)
+IvlChannel :: WriteString (const char* s)
{
Write ((byte*) s, strlen (s) + 1);
}
void
-UchChannel :: WriteBuf (const byte* b, int n)
+IvlChannel :: WriteBuf (const byte* b, int n)
{
Write (b, n);
}
-
-
bool
-UchChannel :: ReadLong (lword& l)
+IvlChannel :: ReadLong (lword& l)
{
return bool (Read ((byte*)&l, lwsize) == lwsize);
}
bool
-UchChannel :: ReadShort (sword& s)
+IvlChannel :: ReadShort (sword& s)
{
return bool (Read ((byte*)&s, swsize) == swsize);
}
bool
-UchChannel :: ReadByte (byte& b)
+IvlChannel :: ReadByte (byte& b)
{
return bool (Read (&b, 1) == 1);
}
bool
-UchChannel :: ReadChar (char& c)
+IvlChannel :: ReadChar (char& c)
{
return bool (Read ((byte*)&c, 1) == 1);
}
int
-UchChannel :: ReadString (char* s, int n)
+IvlChannel :: ReadString (char* s, int n)
{
int i = 0;
// this is extremely non optimal
@@ -464,7 +463,7 @@ UchChannel :: ReadString (char* s, int n)
}
int
-UchChannel :: ReadString (CcuString& s)
+IvlChannel :: ReadString (IvlString& s)
{
// this enforces an undue limitation
char c [1024];
@@ -474,7 +473,7 @@ UchChannel :: ReadString (CcuString& s)
}
bool
-UchChannel :: ReadBuf (byte* b, int n)
+IvlChannel :: ReadBuf (byte* b, int n)
{
return bool (Read (b, n) == n);
}