Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 29c369053a983cc5d8c880dc6e0a2237 > files > 618

libdtn-devel-2.6.0-2mdv2009.1.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>DTN Reference Implementation: SerialConvergenceLayer.cc Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>SerialConvergenceLayer.cc</h1><a href="SerialConvergenceLayer_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> *    Copyright 2004-2006 Intel Corporation</span>
<a name="l00003"></a>00003 <span class="comment"> * </span>
<a name="l00004"></a>00004 <span class="comment"> *    Licensed under the Apache License, Version 2.0 (the "License");</span>
<a name="l00005"></a>00005 <span class="comment"> *    you may not use this file except in compliance with the License.</span>
<a name="l00006"></a>00006 <span class="comment"> *    You may obtain a copy of the License at</span>
<a name="l00007"></a>00007 <span class="comment"> * </span>
<a name="l00008"></a>00008 <span class="comment"> *        http://www.apache.org/licenses/LICENSE-2.0</span>
<a name="l00009"></a>00009 <span class="comment"> * </span>
<a name="l00010"></a>00010 <span class="comment"> *    Unless required by applicable law or agreed to in writing, software</span>
<a name="l00011"></a>00011 <span class="comment"> *    distributed under the License is distributed on an "AS IS" BASIS,</span>
<a name="l00012"></a>00012 <span class="comment"> *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<a name="l00013"></a>00013 <span class="comment"> *    See the License for the specific language governing permissions and</span>
<a name="l00014"></a>00014 <span class="comment"> *    limitations under the License.</span>
<a name="l00015"></a>00015 <span class="comment"> */</span>
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
<a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor">#  include &lt;<a class="code" href="dtn-config_8h.html">dtn-config.h</a>&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#endif</span>
<a name="l00020"></a>00020 <span class="preprocessor"></span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;sys/poll.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;oasys/io/FileUtils.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;oasys/util/OptParser.h&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;oasys/util/HexDumpBuffer.h&gt;</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="preprocessor">#include "<a class="code" href="SerialConvergenceLayer_8h.html">SerialConvergenceLayer.h</a>"</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include "<a class="code" href="BundleDaemon_8h.html">bundling/BundleDaemon.h</a>"</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include "<a class="code" href="ContactManager_8h.html">contacts/ContactManager.h</a>"</span>
<a name="l00031"></a>00031 
<a name="l00032"></a>00032 <span class="keyword">namespace </span>dtn {
<a name="l00033"></a>00033 
<a name="l00034"></a>00034 SerialConvergenceLayer::SerialLinkParams
<a name="l00035"></a>00035     <a class="code" href="classdtn_1_1SerialConvergenceLayer.html#01da52844843829a18dd7d255117e597" title="Default link parameters.">SerialConvergenceLayer::default_link_params_</a>(<span class="keyword">true</span>);
<a name="l00036"></a>00036 
<a name="l00037"></a>00037 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00038"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html#2299d1b10ae34cf1eef9e3331a7922db">00038</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html#2299d1b10ae34cf1eef9e3331a7922db">SerialConvergenceLayer::SerialLinkParams::SerialLinkParams</a>(<span class="keywordtype">bool</span> init_defaults)
<a name="l00039"></a>00039     : StreamLinkParams(init_defaults),
<a name="l00040"></a>00040       hexdump_(false),
<a name="l00041"></a>00041       initstr_(<span class="stringliteral">""</span>),
<a name="l00042"></a>00042       ispeed_(19200),
<a name="l00043"></a>00043       ospeed_(19200),
<a name="l00044"></a>00044       sync_interval_(1000)
<a name="l00045"></a>00045 {
<a name="l00046"></a>00046 }
<a name="l00047"></a>00047 
<a name="l00048"></a>00048 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00049"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer.html#d2618503a0d71fe913d4b29bf44be0e9">00049</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer.html#d2618503a0d71fe913d4b29bf44be0e9" title="Constructor.">SerialConvergenceLayer::SerialConvergenceLayer</a>()
<a name="l00050"></a>00050     : <a class="code" href="classdtn_1_1StreamConvergenceLayer.html" title="Another shared-implementation convergence layer class for use with reliable, in-order...">StreamConvergenceLayer</a>(<span class="stringliteral">"SerialConvergenceLayer"</span>, <span class="stringliteral">"serial"</span>,
<a name="l00051"></a>00051                              <a class="code" href="classdtn_1_1SerialConvergenceLayer.html#9ca5cfc6044fa55480a78bbb287a19c6" title="Current version of the protocol.">SERIALCL_VERSION</a>)
<a name="l00052"></a>00052 {
<a name="l00053"></a>00053 }
<a name="l00054"></a>00054 
<a name="l00055"></a>00055 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00056"></a>00056 <a class="code" href="classdtn_1_1ConnectionConvergenceLayer_1_1LinkParams.html" title="Tunable parameter structure stored in each Link&amp;#39;s CLInfo slot.">ConnectionConvergenceLayer::LinkParams</a>*
<a name="l00057"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer.html#577e34fb15238b91dbf015ce1e1b32c4">00057</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer.html#577e34fb15238b91dbf015ce1e1b32c4" title="Virtual from ConnectionConvergenceLayer.">SerialConvergenceLayer::new_link_params</a>()
<a name="l00058"></a>00058 {
<a name="l00059"></a>00059     <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html" title="Tunable link parameter structure.">SerialLinkParams</a>(<a class="code" href="classdtn_1_1SerialConvergenceLayer.html#01da52844843829a18dd7d255117e597" title="Default link parameters.">default_link_params_</a>);
<a name="l00060"></a>00060 }
<a name="l00061"></a>00061 
<a name="l00062"></a>00062 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00063"></a>00063 <span class="keywordtype">bool</span>
<a name="l00064"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer.html#4229e8c830a1f83a22e257eba769e23c">00064</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer.html#4229e8c830a1f83a22e257eba769e23c" title="Virtual from ConnectionConvergenceLayer.">SerialConvergenceLayer::parse_link_params</a>(<a class="code" href="classdtn_1_1ConnectionConvergenceLayer_1_1LinkParams.html" title="Tunable parameter structure stored in each Link&amp;#39;s CLInfo slot.">LinkParams</a>* lparams,
<a name="l00065"></a>00065                                        <span class="keywordtype">int</span> argc, <span class="keyword">const</span> <span class="keywordtype">char</span>** argv,
<a name="l00066"></a>00066                                        <span class="keyword">const</span> <span class="keywordtype">char</span>** invalidp)
<a name="l00067"></a>00067 {
<a name="l00068"></a>00068     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html" title="Tunable link parameter structure.">SerialLinkParams</a>* params = <span class="keyword">dynamic_cast&lt;</span><a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html" title="Tunable link parameter structure.">SerialLinkParams</a>*<span class="keyword">&gt;</span>(lparams);
<a name="l00069"></a>00069     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(params != NULL);
<a name="l00070"></a>00070 
<a name="l00071"></a>00071     oasys::OptParser p;
<a name="l00072"></a>00072     
<a name="l00073"></a>00073     p.addopt(<span class="keyword">new</span> oasys::BoolOpt(<span class="stringliteral">"hexdump"</span>, &amp;params-&gt;<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html#e6ba05ebfbd5b7c82dc3b58570aa0877" title="Log a hexdump of all traffic.">hexdump_</a>));
<a name="l00074"></a>00074     p.addopt(<span class="keyword">new</span> oasys::StringOpt(<span class="stringliteral">"initstr"</span>, &amp;params-&gt;<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html#6309596645d9366c4d291e5a4a1aca3a" title="String to initialize the tty.">initstr_</a>));
<a name="l00075"></a>00075     p.addopt(<span class="keyword">new</span> oasys::UIntOpt(<span class="stringliteral">"sync_interval"</span>, &amp;params-&gt;<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html#32944b5d122196cbc42aaf76c623d0f1" title="Interval to send initial sync bits.">sync_interval_</a>));
<a name="l00076"></a>00076     
<a name="l00077"></a>00077     <span class="keywordtype">int</span> <a class="code" href="dtnping_8c.html#d43c3812e6d13e0518d9f8b8f463ffcf">count</a> = p.parse_and_shift(argc, argv, invalidp);
<a name="l00078"></a>00078     <span class="keywordflow">if</span> (count == -1) {
<a name="l00079"></a>00079         <span class="keywordflow">return</span> <span class="keyword">false</span>; <span class="comment">// bogus value</span>
<a name="l00080"></a>00080     }
<a name="l00081"></a>00081     argc -= count;
<a name="l00082"></a>00082     
<a name="l00083"></a>00083     <span class="comment">// continue up to parse the parent class</span>
<a name="l00084"></a>00084     <span class="keywordflow">return</span> <a class="code" href="classdtn_1_1SerialConvergenceLayer.html#4229e8c830a1f83a22e257eba769e23c" title="Virtual from ConnectionConvergenceLayer.">StreamConvergenceLayer::parse_link_params</a>(lparams, argc, argv,
<a name="l00085"></a>00085                                                      invalidp);
<a name="l00086"></a>00086 }
<a name="l00087"></a>00087 
<a name="l00088"></a>00088 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00089"></a>00089 <span class="keywordtype">void</span>
<a name="l00090"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer.html#e794014bbd22de08dde5c2d7b6d3ebf2">00090</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer.html#e794014bbd22de08dde5c2d7b6d3ebf2" title="Virtual from ConvergenceLayer.">SerialConvergenceLayer::dump_link</a>(<span class="keyword">const</span> <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a>&amp; link, oasys::StringBuffer* <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>)
<a name="l00091"></a>00091 {
<a name="l00092"></a>00092     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(link != NULL);
<a name="l00093"></a>00093     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(!link-&gt;isdeleted());
<a name="l00094"></a>00094     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(link-&gt;cl_info() != NULL);
<a name="l00095"></a>00095 
<a name="l00096"></a>00096     <a class="code" href="classdtn_1_1SerialConvergenceLayer.html#e794014bbd22de08dde5c2d7b6d3ebf2" title="Virtual from ConvergenceLayer.">StreamConvergenceLayer::dump_link</a>(link, buf);
<a name="l00097"></a>00097     
<a name="l00098"></a>00098     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html" title="Tunable link parameter structure.">SerialLinkParams</a>* params = <span class="keyword">dynamic_cast&lt;</span><a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html" title="Tunable link parameter structure.">SerialLinkParams</a>*<span class="keyword">&gt;</span>(link-&gt;cl_info());
<a name="l00099"></a>00099     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(params != NULL);
<a name="l00100"></a>00100     
<a name="l00101"></a>00101     buf-&gt;appendf(<span class="stringliteral">"initstr: %s\n"</span>, params-&gt;<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html#6309596645d9366c4d291e5a4a1aca3a" title="String to initialize the tty.">initstr_</a>.c_str());
<a name="l00102"></a>00102 }
<a name="l00103"></a>00103 
<a name="l00104"></a>00104 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00105"></a>00105 <span class="keywordtype">bool</span>
<a name="l00106"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer.html#ec245a904942d54ef0a9bed6d14b82d2">00106</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer.html#ec245a904942d54ef0a9bed6d14b82d2" title="Virtual from ConvergenceLayer.">SerialConvergenceLayer::set_link_defaults</a>(<span class="keywordtype">int</span> argc, <span class="keyword">const</span> <span class="keywordtype">char</span>* argv[],
<a name="l00107"></a>00107                                        <span class="keyword">const</span> <span class="keywordtype">char</span>** invalidp)
<a name="l00108"></a>00108 {
<a name="l00109"></a>00109     <span class="keywordflow">return</span> <a class="code" href="classdtn_1_1SerialConvergenceLayer.html#4229e8c830a1f83a22e257eba769e23c" title="Virtual from ConnectionConvergenceLayer.">parse_link_params</a>(&amp;<a class="code" href="classdtn_1_1SerialConvergenceLayer.html#01da52844843829a18dd7d255117e597" title="Default link parameters.">default_link_params_</a>, argc, argv, invalidp);
<a name="l00110"></a>00110 }
<a name="l00111"></a>00111 
<a name="l00112"></a>00112 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00113"></a>00113 <span class="keywordtype">bool</span>
<a name="l00114"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer.html#a304f26f6b759df0c70ee81322a2eaea">00114</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer.html#a304f26f6b759df0c70ee81322a2eaea" title="Virtual from ConnectionConvergenceLayer.">SerialConvergenceLayer::parse_nexthop</a>(<span class="keyword">const</span> <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a>&amp; link, <a class="code" href="classdtn_1_1ConnectionConvergenceLayer_1_1LinkParams.html" title="Tunable parameter structure stored in each Link&amp;#39;s CLInfo slot.">LinkParams</a>* lparams)
<a name="l00115"></a>00115 {
<a name="l00116"></a>00116     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html" title="Tunable link parameter structure.">SerialLinkParams</a>* params = <span class="keyword">dynamic_cast&lt;</span><a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html" title="Tunable link parameter structure.">SerialLinkParams</a>*<span class="keyword">&gt;</span>(lparams);
<a name="l00117"></a>00117     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(params != NULL);
<a name="l00118"></a>00118 
<a name="l00119"></a>00119     <span class="keywordflow">if</span> (! oasys::FileUtils::readable(link-&gt;nexthop()))
<a name="l00120"></a>00120     {
<a name="l00121"></a>00121         log_warn(<span class="stringliteral">"can't read tty device file %s"</span>, link-&gt;nexthop());
<a name="l00122"></a>00122         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00123"></a>00123     }
<a name="l00124"></a>00124 
<a name="l00125"></a>00125     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00126"></a>00126 }
<a name="l00127"></a>00127 
<a name="l00128"></a>00128 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00129"></a>00129 <a class="code" href="classdtn_1_1CLConnection.html" title="Helper class (and thread) that manages an established connection with a peer daemon...">CLConnection</a>*
<a name="l00130"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer.html#0584f928831b0dfa967c54ab6b4122f0">00130</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer.html#0584f928831b0dfa967c54ab6b4122f0" title="Virtual from ConnectionConvergenceLayer.">SerialConvergenceLayer::new_connection</a>(<span class="keyword">const</span> <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a>&amp; link, <a class="code" href="classdtn_1_1ConnectionConvergenceLayer_1_1LinkParams.html" title="Tunable parameter structure stored in each Link&amp;#39;s CLInfo slot.">LinkParams</a>* p)
<a name="l00131"></a>00131 {
<a name="l00132"></a>00132     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html" title="Tunable link parameter structure.">SerialLinkParams</a>* params = <span class="keyword">dynamic_cast&lt;</span><a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html" title="Tunable link parameter structure.">SerialLinkParams</a>*<span class="keyword">&gt;</span>(p);
<a name="l00133"></a>00133     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(params != NULL);
<a name="l00134"></a>00134     <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html" title="Helper class (and thread) that manages an established connection with a peer daemon...">Connection</a>(<span class="keyword">this</span>, link, params);
<a name="l00135"></a>00135 }
<a name="l00136"></a>00136 
<a name="l00137"></a>00137 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00138"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#8d2ce59a6c3e42563f2abf3935b0e39c">00138</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#8d2ce59a6c3e42563f2abf3935b0e39c" title="Constructor for a connection.">SerialConvergenceLayer::Connection::Connection</a>(<a class="code" href="classdtn_1_1SerialConvergenceLayer.html" title="The Serial Convergence Layer.">SerialConvergenceLayer</a>* cl,
<a name="l00139"></a>00139                                                <span class="keyword">const</span> <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a>&amp;          link,
<a name="l00140"></a>00140                                                <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html" title="Tunable link parameter structure.">SerialLinkParams</a>*       params)
<a name="l00141"></a>00141     : <a class="code" href="classdtn_1_1StreamConvergenceLayer.html" title="Another shared-implementation convergence layer class for use with reliable, in-order...">StreamConvergenceLayer</a>::<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html" title="Helper class (and thread) that manages an established connection with a peer daemon...">Connection</a>(<span class="stringliteral">"SerialConvergenceLayer::Connection"</span>,
<a name="l00142"></a>00142                                          cl-&gt;logpath(), cl, params,
<a name="l00143"></a>00143                                          true <span class="comment">/* call connect() */</span>)
<a name="l00144"></a>00144 {
<a name="l00145"></a>00145     logpathf(<span class="stringliteral">"%s/conn/%p"</span>, cl-&gt;logpath(), <span class="keyword">this</span>);
<a name="l00146"></a>00146     
<a name="l00147"></a>00147     <span class="comment">// set up the base class' nexthop parameter</span>
<a name="l00148"></a>00148     <a class="code" href="classdtn_1_1CLConnection.html#463fcafdc6fd41f67a39c78decb0ee92" title="Assignment function for the nexthop identifier.">set_nexthop</a>(link-&gt;nexthop());
<a name="l00149"></a>00149 
<a name="l00150"></a>00150     <span class="comment">// the actual tty wrapper</span>
<a name="l00151"></a>00151     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#964abbef443c4eba28d19e8cf8ef929d" title="The tty.">tty_</a> = <span class="keyword">new</span> oasys::TTY(logpath_);
<a name="l00152"></a>00152     tty_-&gt;logpathf(<span class="stringliteral">"%s/tty"</span>, logpath_);
<a name="l00153"></a>00153 
<a name="l00154"></a>00154     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#1dcd6cccd0dde6a561a7fa2e74de31f9" title="Whether the SYNC has completed.">synced_</a> = <span class="keyword">false</span>;
<a name="l00155"></a>00155 }
<a name="l00156"></a>00156 
<a name="l00157"></a>00157 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00158"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#67fa05a4527544e69ba60f3b4b728471">00158</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#67fa05a4527544e69ba60f3b4b728471" title="Destructor.">SerialConvergenceLayer::Connection::~Connection</a>()
<a name="l00159"></a>00159 {
<a name="l00160"></a>00160     <span class="keyword">delete</span> <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#964abbef443c4eba28d19e8cf8ef929d" title="The tty.">tty_</a>;
<a name="l00161"></a>00161 }
<a name="l00162"></a>00162 
<a name="l00163"></a>00163 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00164"></a>00164 <span class="keywordtype">void</span>
<a name="l00165"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#15954497b3f6652747004b8a9edfaa0d">00165</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#15954497b3f6652747004b8a9edfaa0d" title="Virtual from SerializableObject.">SerialConvergenceLayer::Connection::serialize</a>(oasys::SerializeAction *a)
<a name="l00166"></a>00166 {
<a name="l00167"></a>00167     <span class="comment">// XXX/demmer this should be fixed</span>
<a name="l00168"></a>00168     (void)a;
<a name="l00169"></a>00169 }
<a name="l00170"></a>00170 
<a name="l00171"></a>00171 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00172"></a>00172 <span class="keywordtype">void</span>
<a name="l00173"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#68fa10dfe4cbaac461ddfe8515193a88">00173</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#68fa10dfe4cbaac461ddfe8515193a88" title="Virtual from CLConnection.">SerialConvergenceLayer::Connection::initialize_pollfds</a>()
<a name="l00174"></a>00174 {
<a name="l00175"></a>00175     <span class="comment">// XXX/demmer maybe rename this hook to just "initialize"</span>
<a name="l00176"></a>00176     
<a name="l00177"></a>00177     <span class="keyword">const</span> <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a>&amp; link = <a class="code" href="classdtn_1_1CLConnection.html#29c0707d21c5347919186a8e14728ed0" title="Ref to the Contact.">contact_</a>-&gt;link();
<a name="l00178"></a>00178     
<a name="l00179"></a>00179     <span class="comment">// the first thing we do is try to parse the next hop address...</span>
<a name="l00180"></a>00180     <span class="comment">// if we're unable to do so, the link can't be opened.</span>
<a name="l00181"></a>00181     <span class="keywordflow">if</span> (! <a class="code" href="classdtn_1_1CLConnection.html#99b84b09e39381998c5a918579853a30" title="Pointer to the CL.">cl_</a>-&gt;<a class="code" href="classdtn_1_1ConnectionConvergenceLayer.html#9f96d07f1c0cb39625c18d08fda84bfc" title="Parse and validate the nexthop address for the given link.">parse_nexthop</a>(link, <a class="code" href="classdtn_1_1CLConnection.html#e3408a135a49d68ab36fd8de5805b1fe" title="Pointer to Link parameters, or to defaults until Link is bound.">params_</a>)) {
<a name="l00182"></a>00182         log_info(<span class="stringliteral">"can't resolve nexthop address '%s'"</span>, link-&gt;nexthop());
<a name="l00183"></a>00183         <a class="code" href="classdtn_1_1StreamConvergenceLayer_1_1Connection.html#b06d1276d10f66d40f04da6bd824e54b" title="virtual from CLConnection">break_contact</a>(<a class="code" href="classdtn_1_1ContactEvent.html#e20f7357509a2bcca3d8e6c8daf552f7f0c1475c056a0f72e11b5ba8466a27f7" title="Unexpected session interruption.">ContactEvent::BROKEN</a>);
<a name="l00184"></a>00184         <span class="keywordflow">return</span>;
<a name="l00185"></a>00185     }
<a name="l00186"></a>00186 
<a name="l00187"></a>00187     <span class="comment">// open the tty</span>
<a name="l00188"></a>00188     <span class="keywordtype">int</span> ret = <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#964abbef443c4eba28d19e8cf8ef929d" title="The tty.">tty_</a>-&gt;open(link-&gt;nexthop(), O_RDWR | O_NOCTTY);
<a name="l00189"></a>00189     <span class="keywordflow">if</span> (ret == -1) {
<a name="l00190"></a>00190         log_info(<span class="stringliteral">"opening %s failed... %s"</span>, link-&gt;nexthop(), strerror(<a class="code" href="IPDiscovery_8cc.html#d65a8842cc674e3ddf69355898c0ecbf">errno</a>));
<a name="l00191"></a>00191         <a class="code" href="classdtn_1_1StreamConvergenceLayer_1_1Connection.html#b06d1276d10f66d40f04da6bd824e54b" title="virtual from CLConnection">break_contact</a>(<a class="code" href="classdtn_1_1ContactEvent.html#e20f7357509a2bcca3d8e6c8daf552f7f0c1475c056a0f72e11b5ba8466a27f7" title="Unexpected session interruption.">ContactEvent::BROKEN</a>);
<a name="l00192"></a>00192         <span class="keywordflow">return</span>;
<a name="l00193"></a>00193     }
<a name="l00194"></a>00194 
<a name="l00195"></a>00195     log_debug(<span class="stringliteral">"opened %s"</span>, link-&gt;nexthop());
<a name="l00196"></a>00196     <span class="keywordflow">if</span> (!<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#964abbef443c4eba28d19e8cf8ef929d" title="The tty.">tty_</a>-&gt;isatty()) {
<a name="l00197"></a>00197         log_err(<span class="stringliteral">"%s is not a TTY"</span>, link-&gt;nexthop());
<a name="l00198"></a>00198         <a class="code" href="classdtn_1_1StreamConvergenceLayer_1_1Connection.html#b06d1276d10f66d40f04da6bd824e54b" title="virtual from CLConnection">break_contact</a>(<a class="code" href="classdtn_1_1ContactEvent.html#e20f7357509a2bcca3d8e6c8daf552f7f0c1475c056a0f72e11b5ba8466a27f7" title="Unexpected session interruption.">ContactEvent::BROKEN</a>);
<a name="l00199"></a>00199         <span class="keywordflow">return</span>;
<a name="l00200"></a>00200     }
<a name="l00201"></a>00201 
<a name="l00202"></a>00202     log_debug(<span class="stringliteral">"setting tty parameters..."</span>);
<a name="l00203"></a>00203     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#964abbef443c4eba28d19e8cf8ef929d" title="The tty.">tty_</a>-&gt;tcgetattr();
<a name="l00204"></a>00204     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#964abbef443c4eba28d19e8cf8ef929d" title="The tty.">tty_</a>-&gt;cfmakeraw();
<a name="l00205"></a>00205     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#964abbef443c4eba28d19e8cf8ef929d" title="The tty.">tty_</a>-&gt;cfsetispeed(<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#47ee79660e2f6b536482a70b4261030a" title="Utility function to downcast the params_ pointer that&amp;#39;s stored in the CLConnection...">serial_lparams</a>()-&gt;ispeed_);
<a name="l00206"></a>00206     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#964abbef443c4eba28d19e8cf8ef929d" title="The tty.">tty_</a>-&gt;cfsetospeed(<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#47ee79660e2f6b536482a70b4261030a" title="Utility function to downcast the params_ pointer that&amp;#39;s stored in the CLConnection...">serial_lparams</a>()-&gt;ospeed_);
<a name="l00207"></a>00207     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#964abbef443c4eba28d19e8cf8ef929d" title="The tty.">tty_</a>-&gt;tcflush(TCIOFLUSH);
<a name="l00208"></a>00208     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#964abbef443c4eba28d19e8cf8ef929d" title="The tty.">tty_</a>-&gt;tcsetattr(TCSANOW);
<a name="l00209"></a>00209     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#964abbef443c4eba28d19e8cf8ef929d" title="The tty.">tty_</a>-&gt;set_nonblocking(<span class="keyword">true</span>);
<a name="l00210"></a>00210 
<a name="l00211"></a>00211     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#05433db208375cb11590a39cf4b9012b" title="Poll structure for the tty.">tty_pollfd_</a>  = &amp;<a class="code" href="classdtn_1_1CLConnection.html#9b530df82d1a6b8ca6717fd225c30b5b" title="Array of pollfds.">pollfds_</a>[0];
<a name="l00212"></a>00212     <a class="code" href="classdtn_1_1CLConnection.html#9acc4a1e846c1a93ca38be02296b9ee0" title="Number of pollfds in use.">num_pollfds_</a> = 1;
<a name="l00213"></a>00213     
<a name="l00214"></a>00214     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#05433db208375cb11590a39cf4b9012b" title="Poll structure for the tty.">tty_pollfd_</a>-&gt;fd     = <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#964abbef443c4eba28d19e8cf8ef929d" title="The tty.">tty_</a>-&gt;fd();
<a name="l00215"></a>00215     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#05433db208375cb11590a39cf4b9012b" title="Poll structure for the tty.">tty_pollfd_</a>-&gt;events = POLLIN;
<a name="l00216"></a>00216     
<a name="l00217"></a>00217     <a class="code" href="classdtn_1_1CLConnection.html#b9b601dae1312020426d0d57daca19da" title="Timeout to wait for poll data.">poll_timeout_</a> = <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#47ee79660e2f6b536482a70b4261030a" title="Utility function to downcast the params_ pointer that&amp;#39;s stored in the CLConnection...">serial_lparams</a>()-&gt;<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html#32944b5d122196cbc42aaf76c623d0f1" title="Interval to send initial sync bits.">sync_interval_</a>;
<a name="l00218"></a>00218 }
<a name="l00219"></a>00219 
<a name="l00220"></a>00220 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00221"></a>00221 <span class="keywordtype">void</span>
<a name="l00222"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#25724e198a60975d9eb4a9a2f3a113c7">00222</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#25724e198a60975d9eb4a9a2f3a113c7" title="Virtual from CLConnection.">SerialConvergenceLayer::Connection::connect</a>()
<a name="l00223"></a>00223 {
<a name="l00224"></a>00224     <span class="comment">// initialize the timer here (it's reset in initiate_contact) so</span>
<a name="l00225"></a>00225     <span class="comment">// we know to stop syncing after a while</span><a class="code" href="namespacedtnsim.html#372b0bd474085f20b38efbbade7ce72a" title="Override gettimeofday to return the simulator time."></a>
<a name="l00226"></a>00226 <a class="code" href="namespacedtnsim.html#372b0bd474085f20b38efbbade7ce72a" title="Override gettimeofday to return the simulator time.">    ::gettimeofday</a>(&amp;<a class="code" href="classdtn_1_1StreamConvergenceLayer_1_1Connection.html#906480a8d18388e12f207611a7bdecad" title="Timestamp for idle/keepalive timer.">data_rcvd_</a>, 0);
<a name="l00227"></a>00227 
<a name="l00228"></a>00228     <span class="comment">// if there's a dialing string, send it now</span>
<a name="l00229"></a>00229     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html" title="Tunable link parameter structure.">SerialLinkParams</a>* params = <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#47ee79660e2f6b536482a70b4261030a" title="Utility function to downcast the params_ pointer that&amp;#39;s stored in the CLConnection...">serial_lparams</a>();
<a name="l00230"></a>00230     <span class="keywordtype">size_t</span> initstr_len = params-&gt;<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html#6309596645d9366c4d291e5a4a1aca3a" title="String to initialize the tty.">initstr_</a>.length();
<a name="l00231"></a>00231     <span class="keywordflow">if</span> (initstr_len != 0) {
<a name="l00232"></a>00232         log_debug(<span class="stringliteral">"copying initialization string \"%s\""</span>,
<a name="l00233"></a>00233                   params-&gt;<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html#6309596645d9366c4d291e5a4a1aca3a" title="String to initialize the tty.">initstr_</a>.c_str());
<a name="l00234"></a>00234         
<a name="l00235"></a>00235         <span class="comment">// just to be safe, reserve space in the buffer</span>
<a name="l00236"></a>00236         <a class="code" href="classdtn_1_1CLConnection.html#95f89064268605c6183fa4c436a12071" title="Buffer for outgoing data.">sendbuf_</a>.reserve(initstr_len);
<a name="l00237"></a>00237         memcpy(<a class="code" href="classdtn_1_1CLConnection.html#95f89064268605c6183fa4c436a12071" title="Buffer for outgoing data.">sendbuf_</a>.end(), params-&gt;<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html#6309596645d9366c4d291e5a4a1aca3a" title="String to initialize the tty.">initstr_</a>.data(), initstr_len);
<a name="l00238"></a>00238         <a class="code" href="classdtn_1_1CLConnection.html#95f89064268605c6183fa4c436a12071" title="Buffer for outgoing data.">sendbuf_</a>.fill(initstr_len);
<a name="l00239"></a>00239     }
<a name="l00240"></a>00240     
<a name="l00241"></a>00241     <span class="comment">// send a sync byte to kick things off</span>
<a name="l00242"></a>00242     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#cf42b629fcff7125293df3d98c261303" title="Send a sync byte.">send_sync</a>();
<a name="l00243"></a>00243 }
<a name="l00244"></a>00244 
<a name="l00245"></a>00245 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00246"></a>00246 <span class="keywordtype">void</span>
<a name="l00247"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#9af77a8e2544cdf2d6c563ad830e6430">00247</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#9af77a8e2544cdf2d6c563ad830e6430" title="Virtual from CLConnection.">SerialConvergenceLayer::Connection::disconnect</a>()
<a name="l00248"></a>00248 {
<a name="l00249"></a>00249     <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#964abbef443c4eba28d19e8cf8ef929d" title="The tty.">tty_</a>-&gt;fd() != -1) {
<a name="l00250"></a>00250         <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#964abbef443c4eba28d19e8cf8ef929d" title="The tty.">tty_</a>-&gt;close();
<a name="l00251"></a>00251     }
<a name="l00252"></a>00252 }
<a name="l00253"></a>00253 
<a name="l00254"></a>00254 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00255"></a>00255 <span class="keywordtype">void</span>
<a name="l00256"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#cf42b629fcff7125293df3d98c261303">00256</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#cf42b629fcff7125293df3d98c261303" title="Send a sync byte.">SerialConvergenceLayer::Connection::send_sync</a>()
<a name="l00257"></a>00257 {
<a name="l00258"></a>00258     <span class="comment">// it's highly unlikely that this will hit, but if it does, we</span>
<a name="l00259"></a>00259     <span class="comment">// should be ready</span>
<a name="l00260"></a>00260     <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1CLConnection.html#95f89064268605c6183fa4c436a12071" title="Buffer for outgoing data.">sendbuf_</a>.tailbytes() == 0) {
<a name="l00261"></a>00261         log_debug(<span class="stringliteral">"send_sync: "</span>
<a name="l00262"></a>00262                   <span class="stringliteral">"send buffer has %zu bytes queued, suppressing sync"</span>,
<a name="l00263"></a>00263                   <a class="code" href="classdtn_1_1CLConnection.html#95f89064268605c6183fa4c436a12071" title="Buffer for outgoing data.">sendbuf_</a>.fullbytes());
<a name="l00264"></a>00264         <span class="keywordflow">return</span>;
<a name="l00265"></a>00265     }
<a name="l00266"></a>00266     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(<a class="code" href="classdtn_1_1CLConnection.html#95f89064268605c6183fa4c436a12071" title="Buffer for outgoing data.">sendbuf_</a>.tailbytes() &gt; 0);
<a name="l00267"></a>00267 
<a name="l00268"></a>00268     *(<a class="code" href="classdtn_1_1CLConnection.html#95f89064268605c6183fa4c436a12071" title="Buffer for outgoing data.">sendbuf_</a>.end()) = <a class="code" href="classdtn_1_1SerialConvergenceLayer.html#45eb9e45649902e4463a348069bdbd0d" title="Byte sent on the wire to synchronize the two ends.">SYNC</a>;
<a name="l00269"></a>00269     <a class="code" href="classdtn_1_1CLConnection.html#95f89064268605c6183fa4c436a12071" title="Buffer for outgoing data.">sendbuf_</a>.fill(1);
<a name="l00270"></a>00270     
<a name="l00271"></a>00271     <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#84124f28ba5bbbe2c78ef97ff015bebb" title="virtual from StreamConvergenceLayer::Connection">send_data</a>();
<a name="l00272"></a>00272 }
<a name="l00273"></a>00273 
<a name="l00274"></a>00274 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00275"></a>00275 <span class="keywordtype">void</span>
<a name="l00276"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#848fe92bfc1191c8f11b1a16f3006059">00276</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#848fe92bfc1191c8f11b1a16f3006059" title="Virtual from CLConnection.">SerialConvergenceLayer::Connection::handle_poll_timeout</a>()
<a name="l00277"></a>00277 {
<a name="l00278"></a>00278     <span class="keywordflow">if</span> (!<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#1dcd6cccd0dde6a561a7fa2e74de31f9" title="Whether the SYNC has completed.">synced_</a>) {
<a name="l00279"></a>00279         <span class="keyword">struct </span>timeval now;
<a name="l00280"></a>00280         u_int elapsed;
<a name="l00281"></a>00281         <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html" title="Tunable link parameter structure.">SerialLinkParams</a>* params = <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#47ee79660e2f6b536482a70b4261030a" title="Utility function to downcast the params_ pointer that&amp;#39;s stored in the CLConnection...">serial_lparams</a>();<a class="code" href="namespacedtnsim.html#372b0bd474085f20b38efbbade7ce72a" title="Override gettimeofday to return the simulator time."></a>
<a name="l00282"></a>00282 <a class="code" href="namespacedtnsim.html#372b0bd474085f20b38efbbade7ce72a" title="Override gettimeofday to return the simulator time.">        </a>
<a name="l00283"></a>00283 <a class="code" href="namespacedtnsim.html#372b0bd474085f20b38efbbade7ce72a" title="Override gettimeofday to return the simulator time.">        ::gettimeofday</a>(&amp;now, 0);
<a name="l00284"></a>00284         
<a name="l00285"></a>00285         <span class="comment">// check that it hasn't been too long since we got some data from</span>
<a name="l00286"></a>00286         <span class="comment">// the other side (copied from StreamConvergenceLayer)</span>
<a name="l00287"></a>00287         elapsed = <a class="code" href="dtnping_8h.html#78237999c2659b5d28c1a90a2123607f">TIMEVAL_DIFF_MSEC</a>(now, <a class="code" href="classdtn_1_1StreamConvergenceLayer_1_1Connection.html#906480a8d18388e12f207611a7bdecad" title="Timestamp for idle/keepalive timer.">data_rcvd_</a>);
<a name="l00288"></a>00288         <span class="keywordflow">if</span> (elapsed &gt; params-&gt;data_timeout_) {
<a name="l00289"></a>00289             log_info(<span class="stringliteral">"handle_poll_timeout: no data heard for %d msecs "</span>
<a name="l00290"></a>00290                      <span class="stringliteral">"(data_rcvd %u.%u, now %u.%u, data_timeout %d) "</span>
<a name="l00291"></a>00291                      <span class="stringliteral">"-- closing contact"</span>,
<a name="l00292"></a>00292                      elapsed,
<a name="l00293"></a>00293                      (u_int)<a class="code" href="classdtn_1_1StreamConvergenceLayer_1_1Connection.html#906480a8d18388e12f207611a7bdecad" title="Timestamp for idle/keepalive timer.">data_rcvd_</a>.tv_sec, (u_int)<a class="code" href="classdtn_1_1StreamConvergenceLayer_1_1Connection.html#906480a8d18388e12f207611a7bdecad" title="Timestamp for idle/keepalive timer.">data_rcvd_</a>.tv_usec,
<a name="l00294"></a>00294                      (u_int)now.tv_sec, (u_int)now.tv_usec,
<a name="l00295"></a>00295                      params-&gt;data_timeout_);
<a name="l00296"></a>00296             
<a name="l00297"></a>00297             <a class="code" href="classdtn_1_1StreamConvergenceLayer_1_1Connection.html#b06d1276d10f66d40f04da6bd824e54b" title="virtual from CLConnection">break_contact</a>(<a class="code" href="classdtn_1_1ContactEvent.html#e20f7357509a2bcca3d8e6c8daf552f7f0c1475c056a0f72e11b5ba8466a27f7" title="Unexpected session interruption.">ContactEvent::BROKEN</a>);
<a name="l00298"></a>00298             <span class="keywordflow">return</span>;
<a name="l00299"></a>00299         }
<a name="l00300"></a>00300 
<a name="l00301"></a>00301         log_debug(<span class="stringliteral">"handle_poll_timeout: sending another sync byte"</span>);
<a name="l00302"></a>00302         <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#cf42b629fcff7125293df3d98c261303" title="Send a sync byte.">send_sync</a>();
<a name="l00303"></a>00303     } <span class="keywordflow">else</span> {
<a name="l00304"></a>00304         <span class="comment">// once synced, let the StreamCL connection handle it</span>
<a name="l00305"></a>00305         <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#848fe92bfc1191c8f11b1a16f3006059" title="Virtual from CLConnection.">StreamConvergenceLayer::Connection::handle_poll_timeout</a>();
<a name="l00306"></a>00306     }
<a name="l00307"></a>00307 }
<a name="l00308"></a>00308 
<a name="l00309"></a>00309 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00310"></a>00310 <span class="keywordtype">void</span>
<a name="l00311"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#a780cb6afe25f98b9de942aa45b420cd">00311</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#a780cb6afe25f98b9de942aa45b420cd" title="Virtual from CLConnection.">SerialConvergenceLayer::Connection::handle_poll_activity</a>()
<a name="l00312"></a>00312 {
<a name="l00313"></a>00313     <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#05433db208375cb11590a39cf4b9012b" title="Poll structure for the tty.">tty_pollfd_</a>-&gt;revents &amp; POLLHUP) {
<a name="l00314"></a>00314         log_info(<span class="stringliteral">"tty closed connection -- returned POLLHUP"</span>);
<a name="l00315"></a>00315         <a class="code" href="classdtn_1_1StreamConvergenceLayer_1_1Connection.html#b06d1276d10f66d40f04da6bd824e54b" title="virtual from CLConnection">break_contact</a>(<a class="code" href="classdtn_1_1ContactEvent.html#e20f7357509a2bcca3d8e6c8daf552f7f0c1475c056a0f72e11b5ba8466a27f7" title="Unexpected session interruption.">ContactEvent::BROKEN</a>);
<a name="l00316"></a>00316         <span class="keywordflow">return</span>;
<a name="l00317"></a>00317     }
<a name="l00318"></a>00318     
<a name="l00319"></a>00319     <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#05433db208375cb11590a39cf4b9012b" title="Poll structure for the tty.">tty_pollfd_</a>-&gt;revents &amp; POLLERR) {
<a name="l00320"></a>00320         log_info(<span class="stringliteral">"error condition on tty -- returned POLLERR"</span>);
<a name="l00321"></a>00321         <a class="code" href="classdtn_1_1StreamConvergenceLayer_1_1Connection.html#b06d1276d10f66d40f04da6bd824e54b" title="virtual from CLConnection">break_contact</a>(<a class="code" href="classdtn_1_1ContactEvent.html#e20f7357509a2bcca3d8e6c8daf552f7f0c1475c056a0f72e11b5ba8466a27f7" title="Unexpected session interruption.">ContactEvent::BROKEN</a>);
<a name="l00322"></a>00322         <span class="keywordflow">return</span>;
<a name="l00323"></a>00323     }
<a name="l00324"></a>00324     
<a name="l00325"></a>00325     <span class="comment">// first check for write readiness, meaning either we're getting a</span>
<a name="l00326"></a>00326     <span class="comment">// notification that the deferred connect() call completed, or</span>
<a name="l00327"></a>00327     <span class="comment">// that we are no longer write blocked</span>
<a name="l00328"></a>00328     <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#05433db208375cb11590a39cf4b9012b" title="Poll structure for the tty.">tty_pollfd_</a>-&gt;revents &amp; POLLOUT)
<a name="l00329"></a>00329     {
<a name="l00330"></a>00330         log_debug(<span class="stringliteral">"poll returned write ready, clearing POLLOUT bit"</span>);
<a name="l00331"></a>00331         <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#05433db208375cb11590a39cf4b9012b" title="Poll structure for the tty.">tty_pollfd_</a>-&gt;events &amp;= ~POLLOUT;
<a name="l00332"></a>00332         <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#84124f28ba5bbbe2c78ef97ff015bebb" title="virtual from StreamConvergenceLayer::Connection">send_data</a>();
<a name="l00333"></a>00333     }
<a name="l00334"></a>00334     
<a name="l00335"></a>00335     <span class="comment">// check that the connection was not broken during the data send</span>
<a name="l00336"></a>00336     <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1CLConnection.html#a61b296b02812f04b3df0c8fb09919b8" title="Contact has been broken.">contact_broken_</a>)
<a name="l00337"></a>00337     {
<a name="l00338"></a>00338         <span class="keywordflow">return</span>;
<a name="l00339"></a>00339     }
<a name="l00340"></a>00340     
<a name="l00341"></a>00341     <span class="comment">// finally, check for incoming data</span>
<a name="l00342"></a>00342     <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#05433db208375cb11590a39cf4b9012b" title="Poll structure for the tty.">tty_pollfd_</a>-&gt;revents &amp; POLLIN) {
<a name="l00343"></a>00343         <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#d8a05c363c2044e2315c09451113e48b" title="Hook for handle_poll_activity to receive data.">recv_data</a>();
<a name="l00344"></a>00344         <a class="code" href="classdtn_1_1StreamConvergenceLayer_1_1Connection.html#5e611627d2caa87dbce0e3affc5b5c68" title="utility functions used by derived classes">process_data</a>();
<a name="l00345"></a>00345 
<a name="l00346"></a>00346         <span class="comment">// Sanity check to make sure that there's space in the buffer</span>
<a name="l00347"></a>00347         <span class="comment">// for a subsequent read_data() call</span>
<a name="l00348"></a>00348         <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1CLConnection.html#483ff0dd2871a812491c16aa8d3f9124" title="Buffer for incoming data.">recvbuf_</a>.tailbytes() == 0) {
<a name="l00349"></a>00349             log_err(<span class="stringliteral">"process_data left no space in recvbuf!!"</span>);
<a name="l00350"></a>00350         }
<a name="l00351"></a>00351 
<a name="l00352"></a>00352         <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1CLConnection.html#5712e80e8d3608ae67709fd8adf53bbe" title="Has contact_up been called.">contact_up_</a> &amp;&amp; ! <a class="code" href="classdtn_1_1CLConnection.html#a61b296b02812f04b3df0c8fb09919b8" title="Contact has been broken.">contact_broken_</a>) {
<a name="l00353"></a>00353             <a class="code" href="classdtn_1_1StreamConvergenceLayer_1_1Connection.html#a7f82a1ad41a82f47cebf230ac0b5036" title="utility functions used by derived classes">check_keepalive</a>();
<a name="l00354"></a>00354         }
<a name="l00355"></a>00355     }
<a name="l00356"></a>00356 }
<a name="l00357"></a>00357 
<a name="l00358"></a>00358 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00359"></a>00359 <span class="keywordtype">void</span>
<a name="l00360"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#84124f28ba5bbbe2c78ef97ff015bebb">00360</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#84124f28ba5bbbe2c78ef97ff015bebb" title="virtual from StreamConvergenceLayer::Connection">SerialConvergenceLayer::Connection::send_data</a>()
<a name="l00361"></a>00361 {
<a name="l00362"></a>00362     <span class="comment">// XXX/demmer this assertion is mostly for debugging to catch call</span>
<a name="l00363"></a>00363     <span class="comment">// chains where the contact is broken but we're still using the</span>
<a name="l00364"></a>00364     <span class="comment">// socket</span>
<a name="l00365"></a>00365     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(! <a class="code" href="classdtn_1_1CLConnection.html#a61b296b02812f04b3df0c8fb09919b8" title="Contact has been broken.">contact_broken_</a>);
<a name="l00366"></a>00366 
<a name="l00367"></a>00367     u_int towrite = <a class="code" href="classdtn_1_1CLConnection.html#95f89064268605c6183fa4c436a12071" title="Buffer for outgoing data.">sendbuf_</a>.fullbytes();
<a name="l00368"></a>00368     <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1CLConnection.html#e3408a135a49d68ab36fd8de5805b1fe" title="Pointer to Link parameters, or to defaults until Link is bound.">params_</a>-&gt;<a class="code" href="classdtn_1_1ConnectionConvergenceLayer_1_1LinkParams.html#08a9fb0dfcc27d98a3c327ec74bb41e0" title="Max amount to write to the channel.">test_write_limit_</a> != 0) {
<a name="l00369"></a>00369         towrite = std::min(towrite, <a class="code" href="classdtn_1_1CLConnection.html#e3408a135a49d68ab36fd8de5805b1fe" title="Pointer to Link parameters, or to defaults until Link is bound.">params_</a>-&gt;<a class="code" href="classdtn_1_1ConnectionConvergenceLayer_1_1LinkParams.html#08a9fb0dfcc27d98a3c327ec74bb41e0" title="Max amount to write to the channel.">test_write_limit_</a>);
<a name="l00370"></a>00370     }
<a name="l00371"></a>00371     
<a name="l00372"></a>00372     log_debug(<span class="stringliteral">"send_data: trying to drain %u bytes from send buffer..."</span>,
<a name="l00373"></a>00373               towrite);
<a name="l00374"></a>00374     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(towrite &gt; 0);
<a name="l00375"></a>00375 
<a name="l00376"></a>00376     <span class="keywordtype">int</span> cc = <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#964abbef443c4eba28d19e8cf8ef929d" title="The tty.">tty_</a>-&gt;write(<a class="code" href="classdtn_1_1CLConnection.html#95f89064268605c6183fa4c436a12071" title="Buffer for outgoing data.">sendbuf_</a>.start(), towrite);
<a name="l00377"></a>00377     <span class="keywordflow">if</span> (cc &gt; 0) {
<a name="l00378"></a>00378         log_debug(<span class="stringliteral">"send_data: wrote %d/%zu bytes from send buffer"</span>,
<a name="l00379"></a>00379                   cc, <a class="code" href="classdtn_1_1CLConnection.html#95f89064268605c6183fa4c436a12071" title="Buffer for outgoing data.">sendbuf_</a>.fullbytes());
<a name="l00380"></a>00380         <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#47ee79660e2f6b536482a70b4261030a" title="Utility function to downcast the params_ pointer that&amp;#39;s stored in the CLConnection...">serial_lparams</a>()-&gt;<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html#e6ba05ebfbd5b7c82dc3b58570aa0877" title="Log a hexdump of all traffic.">hexdump_</a>) {
<a name="l00381"></a>00381             oasys::HexDumpBuffer <a class="code" href="num2sdnv_8c.html#ba4680bea50e4ffb92fe4ca7ee66b86c">hex</a>;
<a name="l00382"></a>00382             hex.append((u_char*)<a class="code" href="classdtn_1_1CLConnection.html#95f89064268605c6183fa4c436a12071" title="Buffer for outgoing data.">sendbuf_</a>.start(), cc);
<a name="l00383"></a>00383             log_multiline(oasys::LOG_ALWAYS, hex.hexify().c_str());
<a name="l00384"></a>00384         }
<a name="l00385"></a>00385         
<a name="l00386"></a>00386         <a class="code" href="classdtn_1_1CLConnection.html#95f89064268605c6183fa4c436a12071" title="Buffer for outgoing data.">sendbuf_</a>.consume(cc);
<a name="l00387"></a>00387         
<a name="l00388"></a>00388         <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1CLConnection.html#95f89064268605c6183fa4c436a12071" title="Buffer for outgoing data.">sendbuf_</a>.fullbytes() != 0) {
<a name="l00389"></a>00389             log_debug(<span class="stringliteral">"send_data: incomplete write, setting POLLOUT bit"</span>);
<a name="l00390"></a>00390             <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#05433db208375cb11590a39cf4b9012b" title="Poll structure for the tty.">tty_pollfd_</a>-&gt;events |= POLLOUT;
<a name="l00391"></a>00391 
<a name="l00392"></a>00392         } <span class="keywordflow">else</span> {
<a name="l00393"></a>00393             <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#05433db208375cb11590a39cf4b9012b" title="Poll structure for the tty.">tty_pollfd_</a>-&gt;events &amp; POLLOUT) {
<a name="l00394"></a>00394                 log_debug(<span class="stringliteral">"send_data: drained buffer, clearing POLLOUT bit"</span>);
<a name="l00395"></a>00395                 <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#05433db208375cb11590a39cf4b9012b" title="Poll structure for the tty.">tty_pollfd_</a>-&gt;events &amp;= ~POLLOUT;
<a name="l00396"></a>00396             }
<a name="l00397"></a>00397         }
<a name="l00398"></a>00398     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="IPDiscovery_8cc.html#d65a8842cc674e3ddf69355898c0ecbf">errno</a> == EWOULDBLOCK) {
<a name="l00399"></a>00399         log_debug(<span class="stringliteral">"send_data: write returned EWOULDBLOCK, setting POLLOUT bit"</span>);
<a name="l00400"></a>00400         <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#05433db208375cb11590a39cf4b9012b" title="Poll structure for the tty.">tty_pollfd_</a>-&gt;events |= POLLOUT;
<a name="l00401"></a>00401         
<a name="l00402"></a>00402     } <span class="keywordflow">else</span> {
<a name="l00403"></a>00403         log_info(<span class="stringliteral">"send_data: remote connection unexpectedly closed: %s"</span>,
<a name="l00404"></a>00404                  strerror(<a class="code" href="IPDiscovery_8cc.html#d65a8842cc674e3ddf69355898c0ecbf">errno</a>));
<a name="l00405"></a>00405         <a class="code" href="classdtn_1_1StreamConvergenceLayer_1_1Connection.html#b06d1276d10f66d40f04da6bd824e54b" title="virtual from CLConnection">break_contact</a>(<a class="code" href="classdtn_1_1ContactEvent.html#e20f7357509a2bcca3d8e6c8daf552f7f0c1475c056a0f72e11b5ba8466a27f7" title="Unexpected session interruption.">ContactEvent::BROKEN</a>);
<a name="l00406"></a>00406     }
<a name="l00407"></a>00407 }
<a name="l00408"></a>00408 
<a name="l00409"></a>00409 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00410"></a>00410 <span class="keywordtype">void</span>
<a name="l00411"></a><a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#d8a05c363c2044e2315c09451113e48b">00411</a> <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#d8a05c363c2044e2315c09451113e48b" title="Hook for handle_poll_activity to receive data.">SerialConvergenceLayer::Connection::recv_data</a>()
<a name="l00412"></a>00412 {
<a name="l00413"></a>00413     <span class="comment">// XXX/demmer this assertion is mostly for debugging to catch call</span>
<a name="l00414"></a>00414     <span class="comment">// chains where the contact is broken but we're still using the</span>
<a name="l00415"></a>00415     <span class="comment">// socket</span>
<a name="l00416"></a>00416     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(! <a class="code" href="classdtn_1_1CLConnection.html#a61b296b02812f04b3df0c8fb09919b8" title="Contact has been broken.">contact_broken_</a>);
<a name="l00417"></a>00417     
<a name="l00418"></a>00418     <span class="comment">// this shouldn't ever happen</span>
<a name="l00419"></a>00419     <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1CLConnection.html#483ff0dd2871a812491c16aa8d3f9124" title="Buffer for incoming data.">recvbuf_</a>.tailbytes() == 0) {
<a name="l00420"></a>00420         log_err(<span class="stringliteral">"no space in receive buffer to accept data!!!"</span>);
<a name="l00421"></a>00421         <span class="keywordflow">return</span>;
<a name="l00422"></a>00422     }
<a name="l00423"></a>00423     
<a name="l00424"></a>00424     <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1CLConnection.html#e3408a135a49d68ab36fd8de5805b1fe" title="Pointer to Link parameters, or to defaults until Link is bound.">params_</a>-&gt;<a class="code" href="classdtn_1_1ConnectionConvergenceLayer_1_1LinkParams.html#9e10301e4342cf1319096e973d1e5ff3" title="Msecs to sleep between read calls.">test_read_delay_</a> != 0) {
<a name="l00425"></a>00425         log_debug(<span class="stringliteral">"recv_data: sleeping for test_read_delay msecs %u"</span>,
<a name="l00426"></a>00426                   <a class="code" href="classdtn_1_1CLConnection.html#e3408a135a49d68ab36fd8de5805b1fe" title="Pointer to Link parameters, or to defaults until Link is bound.">params_</a>-&gt;<a class="code" href="classdtn_1_1ConnectionConvergenceLayer_1_1LinkParams.html#9e10301e4342cf1319096e973d1e5ff3" title="Msecs to sleep between read calls.">test_read_delay_</a>);
<a name="l00427"></a>00427         
<a name="l00428"></a>00428         usleep(<a class="code" href="classdtn_1_1CLConnection.html#e3408a135a49d68ab36fd8de5805b1fe" title="Pointer to Link parameters, or to defaults until Link is bound.">params_</a>-&gt;<a class="code" href="classdtn_1_1ConnectionConvergenceLayer_1_1LinkParams.html#9e10301e4342cf1319096e973d1e5ff3" title="Msecs to sleep between read calls.">test_read_delay_</a> * 1000);
<a name="l00429"></a>00429     }
<a name="l00430"></a>00430 
<a name="l00431"></a>00431     u_int toread = <a class="code" href="classdtn_1_1CLConnection.html#483ff0dd2871a812491c16aa8d3f9124" title="Buffer for incoming data.">recvbuf_</a>.tailbytes();
<a name="l00432"></a>00432     <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1CLConnection.html#e3408a135a49d68ab36fd8de5805b1fe" title="Pointer to Link parameters, or to defaults until Link is bound.">params_</a>-&gt;<a class="code" href="classdtn_1_1ConnectionConvergenceLayer_1_1LinkParams.html#8cf6f011103e2250e2ab6d8c5e40a06e" title="Max amount to read from the channel.">test_read_limit_</a> != 0) {
<a name="l00433"></a>00433         toread = std::min(toread, <a class="code" href="classdtn_1_1CLConnection.html#e3408a135a49d68ab36fd8de5805b1fe" title="Pointer to Link parameters, or to defaults until Link is bound.">params_</a>-&gt;<a class="code" href="classdtn_1_1ConnectionConvergenceLayer_1_1LinkParams.html#8cf6f011103e2250e2ab6d8c5e40a06e" title="Max amount to read from the channel.">test_read_limit_</a>);
<a name="l00434"></a>00434     }
<a name="l00435"></a>00435 
<a name="l00436"></a>00436     log_debug(<span class="stringliteral">"recv_data: draining up to %u bytes into recv buffer..."</span>, toread);
<a name="l00437"></a>00437     <span class="keywordtype">int</span> cc = <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#964abbef443c4eba28d19e8cf8ef929d" title="The tty.">tty_</a>-&gt;read(<a class="code" href="classdtn_1_1CLConnection.html#483ff0dd2871a812491c16aa8d3f9124" title="Buffer for incoming data.">recvbuf_</a>.end(), toread);
<a name="l00438"></a>00438     <span class="keywordflow">if</span> (cc &lt; 1) {
<a name="l00439"></a>00439         log_info(<span class="stringliteral">"remote connection unexpectedly closed"</span>);
<a name="l00440"></a>00440         <a class="code" href="classdtn_1_1StreamConvergenceLayer_1_1Connection.html#b06d1276d10f66d40f04da6bd824e54b" title="virtual from CLConnection">break_contact</a>(<a class="code" href="classdtn_1_1ContactEvent.html#e20f7357509a2bcca3d8e6c8daf552f7f0c1475c056a0f72e11b5ba8466a27f7" title="Unexpected session interruption.">ContactEvent::BROKEN</a>);
<a name="l00441"></a>00441         <span class="keywordflow">return</span>;
<a name="l00442"></a>00442     }
<a name="l00443"></a>00443 
<a name="l00444"></a>00444     log_debug(<span class="stringliteral">"recv_data: read %d bytes, rcvbuf has %zu bytes"</span>,
<a name="l00445"></a>00445               cc, <a class="code" href="classdtn_1_1CLConnection.html#483ff0dd2871a812491c16aa8d3f9124" title="Buffer for incoming data.">recvbuf_</a>.fullbytes());
<a name="l00446"></a>00446     <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#47ee79660e2f6b536482a70b4261030a" title="Utility function to downcast the params_ pointer that&amp;#39;s stored in the CLConnection...">serial_lparams</a>()-&gt;<a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html#e6ba05ebfbd5b7c82dc3b58570aa0877" title="Log a hexdump of all traffic.">hexdump_</a>) {
<a name="l00447"></a>00447         oasys::HexDumpBuffer <a class="code" href="num2sdnv_8c.html#ba4680bea50e4ffb92fe4ca7ee66b86c">hex</a>;
<a name="l00448"></a>00448         hex.append((u_char*)<a class="code" href="classdtn_1_1CLConnection.html#483ff0dd2871a812491c16aa8d3f9124" title="Buffer for incoming data.">recvbuf_</a>.end(), cc);
<a name="l00449"></a>00449         log_multiline(oasys::LOG_ALWAYS, hex.hexify().c_str());
<a name="l00450"></a>00450     }
<a name="l00451"></a>00451     <a class="code" href="classdtn_1_1CLConnection.html#483ff0dd2871a812491c16aa8d3f9124" title="Buffer for incoming data.">recvbuf_</a>.fill(cc);
<a name="l00452"></a>00452 
<a name="l00453"></a>00453     <span class="comment">// once we hear some data on the channel, it means the other side</span>
<a name="l00454"></a>00454     <span class="comment">// is up and trying to sync, so send the contact header</span>
<a name="l00455"></a>00455     <span class="keywordflow">if</span> (! <a class="code" href="classdtn_1_1StreamConvergenceLayer_1_1Connection.html#334e73df91eb3303aae9c96c8b7c7301">contact_initiated_</a>) {
<a name="l00456"></a>00456         <a class="code" href="classdtn_1_1StreamConvergenceLayer_1_1Connection.html#db6e45fa1f3fdf6e3e753df0cfb792c8" title="utility functions used by derived classes">initiate_contact</a>();
<a name="l00457"></a>00457     }
<a name="l00458"></a>00458     
<a name="l00459"></a>00459     <span class="comment">// if we're at the start of the connection, then ignore SYNC bytes</span>
<a name="l00460"></a>00460     <span class="keywordflow">if</span> (! <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#1dcd6cccd0dde6a561a7fa2e74de31f9" title="Whether the SYNC has completed.">synced_</a>)
<a name="l00461"></a>00461     {
<a name="l00462"></a>00462         <span class="keywordflow">while</span> ((<a class="code" href="classdtn_1_1CLConnection.html#483ff0dd2871a812491c16aa8d3f9124" title="Buffer for incoming data.">recvbuf_</a>.fullbytes() != 0) &amp;&amp;
<a name="l00463"></a>00463                (*(u_char*)<a class="code" href="classdtn_1_1CLConnection.html#483ff0dd2871a812491c16aa8d3f9124" title="Buffer for incoming data.">recvbuf_</a>.start() == <a class="code" href="classdtn_1_1SerialConvergenceLayer.html#45eb9e45649902e4463a348069bdbd0d" title="Byte sent on the wire to synchronize the two ends.">SYNC</a>))
<a name="l00464"></a>00464         {
<a name="l00465"></a>00465             log_debug(<span class="stringliteral">"got a sync byte... ignoring"</span>);
<a name="l00466"></a>00466             <a class="code" href="classdtn_1_1CLConnection.html#483ff0dd2871a812491c16aa8d3f9124" title="Buffer for incoming data.">recvbuf_</a>.consume(1);
<a name="l00467"></a>00467         }
<a name="l00468"></a>00468 
<a name="l00469"></a>00469         <span class="comment">// if something is left, then it's the start of the contact</span>
<a name="l00470"></a>00470         <span class="comment">// header, so we're done syncing</span>
<a name="l00471"></a>00471         <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1CLConnection.html#483ff0dd2871a812491c16aa8d3f9124" title="Buffer for incoming data.">recvbuf_</a>.fullbytes() != 0)
<a name="l00472"></a>00472         {
<a name="l00473"></a>00473             log_debug(<span class="stringliteral">"done reading sync bytes, clearing synced flag"</span>);
<a name="l00474"></a>00474             <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#1dcd6cccd0dde6a561a7fa2e74de31f9" title="Whether the SYNC has completed.">synced_</a> = <span class="keyword">true</span>;
<a name="l00475"></a>00475         }
<a name="l00476"></a>00476 
<a name="l00477"></a>00477         <span class="comment">// reset the poll timeout</span>
<a name="l00478"></a>00478         <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1SerialLinkParams.html" title="Tunable link parameter structure.">SerialLinkParams</a>* params = <a class="code" href="classdtn_1_1SerialConvergenceLayer_1_1Connection.html#47ee79660e2f6b536482a70b4261030a" title="Utility function to downcast the params_ pointer that&amp;#39;s stored in the CLConnection...">serial_lparams</a>();
<a name="l00479"></a>00479         <a class="code" href="classdtn_1_1CLConnection.html#b9b601dae1312020426d0d57daca19da" title="Timeout to wait for poll data.">poll_timeout_</a> = params-&gt;data_timeout_;
<a name="l00480"></a>00480         
<a name="l00481"></a>00481         <span class="keywordflow">if</span> (params-&gt;keepalive_interval_ != 0 &amp;&amp;
<a name="l00482"></a>00482             (params-&gt;keepalive_interval_ * 1000) &lt; params-&gt;data_timeout_)
<a name="l00483"></a>00483         {
<a name="l00484"></a>00484             <a class="code" href="classdtn_1_1CLConnection.html#b9b601dae1312020426d0d57daca19da" title="Timeout to wait for poll data.">poll_timeout_</a> = params-&gt;keepalive_interval_ * 1000;
<a name="l00485"></a>00485         }
<a name="l00486"></a>00486     }
<a name="l00487"></a>00487 }
<a name="l00488"></a>00488 
<a name="l00489"></a>00489 } <span class="comment">// namespace dtn</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Fri Jan 30 09:26:58 2009 for DTN Reference Implementation by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
</body>
</html>