⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 combine.shar

📁 这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用于网络游戏医学图像网关的高qos要求.更详细的内容可阅读相应的材料
💻 SHAR
📖 第 1 页 / 共 3 页
字号:
  sed 's/^X//' << 'SHAR_EOF' > 'page04.pre' &&
The implementation of the Client object.  Only the open() method
X      really does any work.  The other methods simply delegate their
X      function to the Protocol_Stream.
<HR>
SHAR_EOF
  $shar_touch -am 04090120100 'page04.pre' &&
  chmod 0664 'page04.pre' ||
  $echo 'restore of' 'page04.pre' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'page04.pre:' 'MD5 check failed'
2955ca8d3b0fc6840f3d371aea528b8d  page04.pre
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page04.pre'`"
    test 178 -eq "$shar_count" ||
    $echo 'page04.pre:' 'original size' '178,' 'current size' "$shar_count!"
  fi
fi
# ============= page05.pre ==============
if test -f 'page05.pre' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'page05.pre' '(file already exists)'
else
  $echo 'x -' extracting 'page05.pre' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'page05.pre' &&
Like the client, we want to keep the main() part of our server code as
X      simple as possible.  This is done by putting most of the work
X      into the Handler object that will deal with client connections.
XFrom the looks of the code below, I think we've been successful in our
simplification.
<HR>
X
SHAR_EOF
  $shar_touch -am 04090120100 'page05.pre' &&
  chmod 0664 'page05.pre' ||
  $echo 'restore of' 'page05.pre' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'page05.pre:' 'MD5 check failed'
7413a66059d2bd31c99b6414cfa9faef  page05.pre
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page05.pre'`"
    test 302 -eq "$shar_count" ||
    $echo 'page05.pre:' 'original size' '302,' 'current size' "$shar_count!"
  fi
fi
# ============= page06.pre ==============
if test -f 'page06.pre' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'page06.pre' '(file already exists)'
else
  $echo 'x -' extracting 'page06.pre' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'page06.pre' &&
The Server object exists in order simplify the
main() application level.  To that end, it hides the details of
creating an acceptor and managing the reactor.
<P>
The static close() method available for a signal handler as you saw on
the previous page.  Of course the assumption here is that there would
only be one Server instance but since you can't provide a TCP/IP port,
that's probably a valid assumption!
<HR>
SHAR_EOF
  $shar_touch -am 04090120100 'page06.pre' &&
  chmod 0664 'page06.pre' ||
  $echo 'restore of' 'page06.pre' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'page06.pre:' 'MD5 check failed'
af07f1b6fd76a7bd82ca2eb679ebe482  page06.pre
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page06.pre'`"
    test 415 -eq "$shar_count" ||
    $echo 'page06.pre:' 'original size' '415,' 'current size' "$shar_count!"
  fi
fi
# ============= page07.pre ==============
if test -f 'page07.pre' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'page07.pre' '(file already exists)'
else
  $echo 'x -' extracting 'page07.pre' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'page07.pre' &&
And now the implementation of Server.  This is actually just the
main() code from a previous tutorial broken into appropriate method
calls.  It may seem silly to do this rather than keeping the stuff in
main() but you'll find that you have less trouble enhancing an
application when you take this sort of approach.
<HR>
X
SHAR_EOF
  $shar_touch -am 04090120100 'page07.pre' &&
  chmod 0664 'page07.pre' ||
  $echo 'restore of' 'page07.pre' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'page07.pre:' 'MD5 check failed'
7dfb75884939c3c05ee1e1000956e9f4  page07.pre
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page07.pre'`"
    test 321 -eq "$shar_count" ||
    $echo 'page07.pre:' 'original size' '321,' 'current size' "$shar_count!"
  fi
fi
# ============= page08.pre ==============
if test -f 'page08.pre' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'page08.pre' '(file already exists)'
else
  $echo 'x -' extracting 'page08.pre' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'page08.pre' &&
The Handler object is our event handler.  You can use either
ACE_Event_Handler or ACE_Svc_Handler<> for the baseclass.  I generally
prefer the latter since it takes care of some housekeeping that I
would otherwise be responsible for.
<P>
The class declaration is taken almost exactly from a previous
tutorial.  A good design will have a simple handler object that will
collect data from the peer and pass it along to another object for
processing.  Again, keep it simple and delegate authority.
<HR>
SHAR_EOF
  $shar_touch -am 04090120100 'page08.pre' &&
  chmod 0664 'page08.pre' ||
  $echo 'restore of' 'page08.pre' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'page08.pre:' 'MD5 check failed'
8e5bd08125af0eb8b2a8ac6fa1cd6773  page08.pre
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page08.pre'`"
    test 500 -eq "$shar_count" ||
    $echo 'page08.pre:' 'original size' '500,' 'current size' "$shar_count!"
  fi
fi
# ============= page09.pre ==============
if test -f 'page09.pre' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'page09.pre' '(file already exists)'
else
  $echo 'x -' extracting 'page09.pre' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'page09.pre' &&
Like any other event handler, the handle_input() method will be
responsible for getting data from the peer() and doing something with
it.  In this case, we have a Protocol_Stream to deal with.  We'll use
the stream for the actual I/O but we are ultimately responsible for
processing the data from the peer.  To do that, we've created a
Handler_Task that fits within the Protocol_Stream framework to process
data that has been received.  Handler::handle_input() will tell the stream that
it's time to read data and that data will eventually show up at
Handler_Task::recv() where we'll process it as required by our
application logic.
<HR>
SHAR_EOF
  $shar_touch -am 04090120100 'page09.pre' &&
  chmod 0664 'page09.pre' ||
  $echo 'restore of' 'page09.pre' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'page09.pre:' 'MD5 check failed'
4157b3795510b693de745d3fa9890418  page09.pre
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page09.pre'`"
    test 638 -eq "$shar_count" ||
    $echo 'page09.pre:' 'original size' '638,' 'current size' "$shar_count!"
  fi
fi
# ============= page10.pre ==============
if test -f 'page10.pre' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'page10.pre' '(file already exists)'
else
  $echo 'x -' extracting 'page10.pre' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'page10.pre' &&
And so finally we come to the Protocol_Stream.  That, after all, is
the focus of the entire tutorial but it took us half of the day to get
here!
<P>
The Protocol_Stream uses an ACE_Stream to move an ACE_Message_Block
through a series of tasks.  Each task in the stream is responsible for
performing some operation on the data in the message block.  That is
the nature of a protocol stream (or "stack" if you prefer).  In this
stream, the data is compressed and encrypted* on its way between
peers.  We also allow users of the stream to install a reader task to
handle data that percolates up from the peer.  As you saw a page or
two ago, this is most useful for a server.
X
<P>
<font size=-1>*Again, I just pretend to do these things.  It would
take another day or two to go through any sort of reasonable
encryption or compression!</font>
<P>
Before we get into the code, here's a picture that's shows what's
going on here.
<P><center><img src="stream.gif"></center></p>
<HR>
SHAR_EOF
  $shar_touch -am 04090120100 'page10.pre' &&
  chmod 0664 'page10.pre' ||
  $echo 'restore of' 'page10.pre' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'page10.pre:' 'MD5 check failed'
cd2042fe28f3ec83a293de6d795b6804  page10.pre
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page10.pre'`"
    test 976 -eq "$shar_count" ||
    $echo 'page10.pre:' 'original size' '976,' 'current size' "$shar_count!"
  fi
fi
# ============= page11.pre ==============
if test -f 'page11.pre' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'page11.pre' '(file already exists)'
else
  $echo 'x -' extracting 'page11.pre' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'page11.pre' &&
And now the implementation of the Protocol_Stream.  There are more
lines of code here than we've seen so far but it still isn't
complicated.  The basic idea is to construct the ACE_Stream with our
set of protocol objects that will manipulate the data.  Our primary
concern in this file is to get everything in the correct order!
<HR>
SHAR_EOF
  $shar_touch -am 04090120100 'page11.pre' &&
  chmod 0664 'page11.pre' ||
  $echo 'restore of' 'page11.pre' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'page11.pre:' 'MD5 check failed'
b0e968102fb417b12710e99465f4e387  page11.pre
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page11.pre'`"
    test 334 -eq "$shar_count" ||
    $echo 'page11.pre:' 'original size' '334,' 'current size' "$shar_count!"
  fi
fi
# ============= page12.pre ==============
if test -f 'page12.pre' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'page12.pre' '(file already exists)'
else
  $echo 'x -' extracting 'page12.pre' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'page12.pre' &&
A quick look at the Protocol_Task header...
<HR>
SHAR_EOF
  $shar_touch -am 04090120100 'page12.pre' &&
  chmod 0664 'page12.pre' ||
  $echo 'restore of' 'page12.pre' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'page12.pre:' 'MD5 check failed'
5258df32a7fddcecfe902aec8440f98f  page12.pre
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page12.pre'`"
    test 49 -eq "$shar_count" ||
    $echo 'page12.pre:' 'original size' '49,' 'current size' "$shar_count!"
  fi
fi
# ============= page13.pre ==============
if test -f 'page13.pre' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'page13.pre' '(file already exists)'
else
  $echo 'x -' extracting 'page13.pre' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'page13.pre' &&
The Protocol_Task implementation takes care of the open(), close(),
put() and svc() methods so that derivatives can concentrate on the
send() and recv() methods.  After a while you find that most
ACE_Task<> derivatives look very similar in the four basic methods and
only need one or two additional to do any real work.
<HR>
SHAR_EOF
  $shar_touch -am 04090120100 'page13.pre' &&
  chmod 0664 'page13.pre' ||
  $echo 'restore of' 'page13.pre' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'page13.pre:' 'MD5 check failed'
3dd6383ba5c5d97e74a7ace5f44b0b33  page13.pre
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page13.pre'`"
    test 325 -eq "$shar_count" ||
    $echo 'page13.pre:' 'original size' '325,' 'current size' "$shar_count!"
  fi
fi
# ============= page14.pre ==============
if test -f 'page14.pre' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'page14.pre' '(file already exists)'
else
  $echo 'x -' extracting 'page14.pre' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'page14.pre' &&
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>
SHAR_EOF
  $shar_touch -am 04090120100 'page14.pre' &&
  chmod 0664 'page14.pre' ||
  $echo 'restore of' 'page14.pre' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'page14.pre:' 'MD5 check failed'
aa057b88a7c770d1a15721cecbf91032  page14.pre
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page14.pre'`"
    test 539 -eq "$shar_count" ||
    $echo 'page14.pre:' 'original size' '539,' 'current size' "$shar_count!"
  fi
fi
# ============= page15.pre ==============
if test -f 'page15.pre' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'page15.pre' '(file already exists)'
else
  $echo 'x -' extracting 'page15.pre' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'page15.pre' &&
The implementation of Xmit isn't too complicated.  If we choose to
combine it with the Recv task we simply lift the recv() method from
that object and drop it into this one.
<P>
Note that close() must decide if it's being called when the stream is
shutdown or when it's svc() method exits.  Since we tell the baseclass
not to use any threads it's a safe bet that flags will always be
non-zero.  Still, it's good practice to plan for the future by
checking the value.
<P>
Note also that when we send the data we prefix it with the data size.
This let's our sibling Recv ensure that an entire block is received
together.  This can be very important for compression and encryption
processes which typically work better with blocks of data instead of
streams of data.
<HR>
SHAR_EOF
  $shar_touch -am 04090120100 'page15.pre' &&

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -