summaryrefslogtreecommitdiff
path: root/docs/tutorials/015/page14.html
blob: 735a6ee32cad3ceb066d5e3dde40eb2f6a396fcd (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
<!-- $Id$ -->
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="James CE Johnson">
   <TITLE>ACE Tutorial 015</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F">

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

<CENTER><B><FONT SIZE=+2>Building a protocol stream</FONT></B></CENTER>

<P>
<HR WIDTH="100%">
The Xmit object knows how to send data to the peer.  It sits at the
tail of the stream and gets everything that flows down from the head.
In keeping with the spirit of things, this object does only one thing
and doesn't concern itself with anyone else' details.
<P>
The only thing you might want to do is combine it with Recv.  Why?
As you'll realize in a page or two, the Xmit and Recv objects must
interact if you're going to ensure a safe transit.  By having a single
object it's easier to coordinate and maintain the interaction.
<HR>
<PRE>
<font color=red>// $Id$</font>

<font color=blue>#ifndef</font> <font color=purple>XMIT_H</font>
<font color=blue>#define</font> <font color=purple>XMIT_h</font>

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

<font color=red>// Forward reference reduces <font color=blue>#include</font> dependencies</font>
class ACE_SOCK_Stream;

<font color=red>/* A class suitable for sending data to a peer from within an
   ACE_Stream.
 */</font>
class Xmit : public Protocol_Task
{
public:
  typedef Protocol_Task inherited;

  <font color=red>// We must be given a valid peer when constructed.  Without that we</font>
  <font color=red>// don't know who to send data to.</font>
  Xmit (ACE_SOCK_Stream &peer);
  ~Xmit (void);

  <font color=red>// As you know, close() will be called in a couple of ways by the</font>
  <font color=red>// ACE framework.  We use that opportunity to terminate the</font>
  <font color=red>// connection to the peer.</font>
  int close (u_long flags);

protected:

  ACE_SOCK_Stream &peer (void)
  {
    return this->peer_;
  }

  <font color=red>// Send the data to the peer.  By now it will have been completely</font>
  <font color=red>// protocol-ized by other tasks in the stream.</font>
  int send (ACE_Message_Block *message,
            ACE_Time_Value *timeout);

private:
  <font color=red>// A representation of the peer we're talking to.</font>
  ACE_SOCK_Stream &peer_;
};

<font color=blue>#endif</font> <font color=red>/* XMIT_H */</font>
</PRE>
<P><HR WIDTH="100%">
<CENTER>[<A HREF="../online-tutorials.html">Tutorial Index</A>] [<A HREF="page15.html">Continue This Tutorial</A>]</CENTER>