summaryrefslogtreecommitdiff
path: root/docs/tutorials/014/page04.html
blob: 88b6c553d0b3759e8325eab6698d5eaab2fa680b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="Bob McWhirter">
   <TITLE>ACE Tutorial 014</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F">

<CENTER><B><FONT SIZE=+2>ACE Tutorial 014</FONT></B></CENTER>

<CENTER><B><FONT SIZE=+2>ACE_Stream Tutorial, Of Sorts</FONT></B></CENTER>

<P>
<HR WIDTH="100%">
<P>
As stated in the comments below, the default action of the task at the 
	  stream tail is to treat any received data as an error.  In our
	  implementation it will often happen that data gets through to
	  the tail.  How, then, do we handle this without creating an
	  error condition?  Simple:  Create a custom Task for use as the
	  stream tail that doesn't consider it an error to receive data.
<P>
Read on...
<P>
<HR WIDTH="100%">
<PRE>

<font color=red>// $Id$</font>

<font color=red>// EndTask.h</font>
<font color=red>//</font>
<font color=red>// Tutorial regarding a way to use ACE_Stream.</font>
<font color=red>//</font>
<font color=red>// written by bob mcwhirter (bob@netwrench.com)</font>
<font color=red>//</font>
<font color=red>//</font>

<font color=blue>#ifndef</font> <font color=purple>ENDTASK_H</font>
<font color=blue>#define</font> <font color=purple>ENDTASK_H</font>

<font color=blue>#include</font> "<font color=green>Task.h</font>"

<font color=red>// When you setup a Stream and push your modules on,</font>
<font color=red>// there are two additional modules that go unseen</font>
<font color=red>// by the user.</font>
<font color=red>//</font>
<font color=red>// The Stream pushes on a Stream_Head in front of</font>
<font color=red>// your first module, and a Stream_Tail behind your</font>
<font color=red>// last module.</font>
<font color=red>//</font>
<font color=red>// If your put() a message to the Stream Tail, it</font>
<font color=red>// assumes you did so in error. This simple EndTask</font>
<font color=red>// class allows you to push a message to it and just</font>
<font color=red>// have it safely Go Away.</font>
<font color=red>//</font>
<font color=red>// All this Task does is release the Message_Block</font>
<font color=red>// and return 0.  It's a suitable black-hole.</font>


class EndTask : public Task
{

public:

  typedef Task inherited;

  EndTask(const char *nameOfTask) :
    inherited(nameOfTask, 0) {

    <font color=red>// when we get open()'d, it with 0 threads</font>
    <font color=red>// since there is actually no processing to do.</font>

        cerr &lt;&lt; __LINE__ &lt;&lt; "<font color=green> </font>" &lt;&lt; __FILE__ &lt;&lt; endl;
  };

  virtual int open(void *)
  {
        cerr &lt;&lt; __LINE__ &lt;&lt; "<font color=green> </font>" &lt;&lt; __FILE__ &lt;&lt; endl;
        return 0;
  }

  virtual int open(void)
  {
        cerr &lt;&lt; __LINE__ &lt;&lt; "<font color=green> </font>" &lt;&lt; __FILE__ &lt;&lt; endl;
        return 0;
  }

  virtual ~EndTask(void) {
  };

  virtual int put(ACE_Message_Block *message,
                  ACE_Time_Value *timeout) {

        cerr &lt;&lt; __LINE__ &lt;&lt; "<font color=green> </font>" &lt;&lt; __FILE__ &lt;&lt; endl;
    ACE_UNUSED_ARG(timeout);

    <font color=red>// we don't have anything to do, so</font>
    <font color=red>// release() the message.</font>
    ACE_DEBUG ((LM_DEBUG, "<font color=green>(%P|%t) %s <font color=#008888>EndTask::put</font>() -- releasing Message_Block\n</font>", this->nameOfTask()));
    message->release();
    return 0;
  };

};

<font color=blue>#endif</font> <font color=red>// ENDTASK_H</font>
</PRE>
<P><HR WIDTH="100%">
<CENTER>[<A HREF="..">Tutorial Index</A>] [<A HREF="page05.html">Continue This Tutorial</A>]</CENTER>