<!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: APIServer.cc Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.5.6 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="main.html"><span>Main 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> <h1>APIServer.cc</h1><a href="APIServer_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 <<a class="code" href="dtn-config_8h.html">dtn-config.h</a>></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 <algorithm></span> <a name="l00022"></a>00022 <a name="l00023"></a>00023 <span class="preprocessor">#include <sys/types.h></span> <a name="l00024"></a>00024 <span class="preprocessor">#include <sys/stat.h></span> <a name="l00025"></a>00025 <span class="preprocessor">#include <oasys/compat/inet_aton.h></span> <a name="l00026"></a>00026 <span class="preprocessor">#include <oasys/compat/rpc.h></span> <a name="l00027"></a>00027 <span class="preprocessor">#include <oasys/io/FileIOClient.h></span> <a name="l00028"></a>00028 <span class="preprocessor">#include <oasys/io/NetUtils.h></span> <a name="l00029"></a>00029 <span class="preprocessor">#include <oasys/util/Pointers.h></span> <a name="l00030"></a>00030 <span class="preprocessor">#include <oasys/util/ScratchBuffer.h></span> <a name="l00031"></a>00031 <span class="preprocessor">#include <oasys/util/XDRUtils.h></span> <a name="l00032"></a>00032 <a name="l00033"></a>00033 <span class="preprocessor">#include "<a class="code" href="APIServer_8h.html">APIServer.h</a>"</span> <a name="l00034"></a>00034 <span class="preprocessor">#include "<a class="code" href="APIBlockProcessor_8h.html">bundling/APIBlockProcessor.h</a>"</span> <a name="l00035"></a>00035 <span class="preprocessor">#include "<a class="code" href="bundling_2Bundle_8h.html">bundling/Bundle.h</a>"</span> <a name="l00036"></a>00036 <span class="preprocessor">#include "<a class="code" href="BundleEvent_8h.html">bundling/BundleEvent.h</a>"</span> <a name="l00037"></a>00037 <span class="preprocessor">#include "<a class="code" href="BundleDaemon_8h.html">bundling/BundleDaemon.h</a>"</span> <a name="l00038"></a>00038 <span class="preprocessor">#include "<a class="code" href="BundleStatusReport_8h.html">bundling/BundleStatusReport.h</a>"</span> <a name="l00039"></a>00039 <span class="preprocessor">#include "<a class="code" href="SDNV_8h.html">bundling/SDNV.h</a>"</span> <a name="l00040"></a>00040 <span class="preprocessor">#include "<a class="code" href="GbofId_8h.html">bundling/GbofId.h</a>"</span> <a name="l00041"></a>00041 <span class="preprocessor">#include "<a class="code" href="EndpointID_8h.html">naming/EndpointID.h</a>"</span> <a name="l00042"></a>00042 <span class="preprocessor">#include "<a class="code" href="APICommand_8h.html">cmd/APICommand.h</a>"</span> <a name="l00043"></a>00043 <span class="preprocessor">#include "<a class="code" href="APIRegistration_8h.html">reg/APIRegistration.h</a>"</span> <a name="l00044"></a>00044 <span class="preprocessor">#include "<a class="code" href="RegistrationTable_8h.html">reg/RegistrationTable.h</a>"</span> <a name="l00045"></a>00045 <span class="preprocessor">#include "<a class="code" href="BundleRouter_8h.html">routing/BundleRouter.h</a>"</span> <a name="l00046"></a>00046 <span class="preprocessor">#include "<a class="code" href="GlobalStore_8h.html">storage/GlobalStore.h</a>"</span> <a name="l00047"></a>00047 <span class="preprocessor">#include "<a class="code" href="Session_8h.html">session/Session.h</a>"</span> <a name="l00048"></a>00048 <a name="l00049"></a>00049 <span class="preprocessor">#ifndef MIN</span> <a name="l00050"></a><a class="code" href="APIServer_8cc.html#74e75242132eaabbc1c512488a135926">00050</a> <span class="preprocessor"></span><span class="preprocessor">#define MIN(x, y) ((x)<(y) ? (x) : (y))</span> <a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00052"></a>00052 <span class="preprocessor"></span> <a name="l00053"></a>00053 <span class="keyword">namespace </span>dtn { <a name="l00054"></a>00054 <a name="l00055"></a>00055 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00056"></a><a class="code" href="classdtn_1_1APIServer.html#964a720028d4513d9de05f4c88689917">00056</a> <a class="code" href="classdtn_1_1APIServer.html#964a720028d4513d9de05f4c88689917" title="The constructor checks for environment variable overrides of the address / port.">APIServer::APIServer</a>() <a name="l00057"></a>00057 <span class="comment">// DELETE_ON_EXIT flag is not set; see below.</span> <a name="l00058"></a>00058 : TCPServerThread(<span class="stringliteral">"APIServer"</span>, <span class="stringliteral">"/dtn/apiserver"</span>, 0) <a name="l00059"></a>00059 { <a name="l00060"></a>00060 <a class="code" href="classdtn_1_1APIServer.html#52bb7c6b0365b5a1f324d9f9d90f1c5a" title="whether or not to enable it">enabled_</a> = <span class="keyword">true</span>; <a name="l00061"></a>00061 <a class="code" href="classdtn_1_1APIServer.html#e19acdd68aa4c9f0c6c308493328f5c6" title="local address to bind to">local_addr_</a> = htonl(INADDR_LOOPBACK); <a name="l00062"></a>00062 <a class="code" href="classdtn_1_1APIServer.html#72c56ebd73a38bf0caa78a16036740c6" title="local port to use for api">local_port_</a> = <a class="code" href="dtn__ipc_8h.html#7f9f6b66a37fb74f861dec857888c0ba" title="Default api ports.">DTN_IPC_PORT</a>; <a name="l00063"></a>00063 <a name="l00064"></a>00064 <span class="comment">// override the defaults via environment variables, if given</span> <a name="l00065"></a>00065 <span class="keywordtype">char</span> *env; <a name="l00066"></a>00066 <span class="keywordflow">if</span> ((env = getenv(<span class="stringliteral">"DTNAPI_ADDR"</span>)) != NULL) { <a name="l00067"></a>00067 <span class="keywordflow">if</span> (inet_aton(env, (<span class="keyword">struct</span> in_addr*)&<a class="code" href="classdtn_1_1APIServer.html#e19acdd68aa4c9f0c6c308493328f5c6" title="local address to bind to">local_addr_</a>) == 0) <a name="l00068"></a>00068 { <a name="l00069"></a>00069 log_err(<span class="stringliteral">"DTNAPI_ADDR environment variable (%s) "</span> <a name="l00070"></a>00070 <span class="stringliteral">"not a valid ip address, using default of localhost"</span>, <a name="l00071"></a>00071 env); <a name="l00072"></a>00072 <span class="comment">// in case inet_aton touched it</span> <a name="l00073"></a>00073 local_addr_ = htonl(INADDR_LOOPBACK); <a name="l00074"></a>00074 } <span class="keywordflow">else</span> { <a name="l00075"></a>00075 log_debug(<span class="stringliteral">"local address set to %s by DTNAPI_ADDR "</span> <a name="l00076"></a>00076 <span class="stringliteral">"environment variable"</span>, env); <a name="l00077"></a>00077 } <a name="l00078"></a>00078 } <a name="l00079"></a>00079 <a name="l00080"></a>00080 <span class="keywordflow">if</span> ((env = getenv(<span class="stringliteral">"DTNAPI_PORT"</span>)) != NULL) { <a name="l00081"></a>00081 <span class="keywordtype">char</span> *<a class="code" href="dtncat_8c.html#7ab59805f7a1819164bc301293db600d">end</a>; <a name="l00082"></a>00082 u_int port = strtoul(env, &end, 10); <a name="l00083"></a>00083 <span class="keywordflow">if</span> (*end != <span class="charliteral">'\0'</span> || port > 0xffff) <a name="l00084"></a>00084 { <a name="l00085"></a>00085 log_err(<span class="stringliteral">"DTNAPI_PORT environment variable (%s) "</span> <a name="l00086"></a>00086 <span class="stringliteral">"not a valid ip port, using default of %d"</span>, <a name="l00087"></a>00087 env, <a class="code" href="dtn__ipc_8h.html#7f9f6b66a37fb74f861dec857888c0ba" title="Default api ports.">DTN_IPC_PORT</a>); <a name="l00088"></a>00088 port = <a class="code" href="dtn__ipc_8h.html#7f9f6b66a37fb74f861dec857888c0ba" title="Default api ports.">DTN_IPC_PORT</a>; <a name="l00089"></a>00089 } <span class="keywordflow">else</span> { <a name="l00090"></a>00090 log_debug(<span class="stringliteral">"api port set to %s by DTNAPI_PORT "</span> <a name="l00091"></a>00091 <span class="stringliteral">"environment variable"</span>, env); <a name="l00092"></a>00092 } <a name="l00093"></a>00093 <a class="code" href="classdtn_1_1APIServer.html#72c56ebd73a38bf0caa78a16036740c6" title="local port to use for api">local_port_</a> = (u_int16_t)port; <a name="l00094"></a>00094 } <a name="l00095"></a>00095 <a name="l00096"></a>00096 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1APIServer.html#e19acdd68aa4c9f0c6c308493328f5c6" title="local address to bind to">local_addr_</a> != INADDR_ANY || <a class="code" href="classdtn_1_1APIServer.html#72c56ebd73a38bf0caa78a16036740c6" title="local port to use for api">local_port_</a> != 0) { <a name="l00097"></a>00097 log_debug(<span class="stringliteral">"APIServer init (evironment set addr %s port %d)"</span>, <a name="l00098"></a>00098 intoa(<a class="code" href="classdtn_1_1APIServer.html#e19acdd68aa4c9f0c6c308493328f5c6" title="local address to bind to">local_addr_</a>), <a class="code" href="classdtn_1_1APIServer.html#72c56ebd73a38bf0caa78a16036740c6" title="local port to use for api">local_port_</a>); <a name="l00099"></a>00099 } <span class="keywordflow">else</span> { <a name="l00100"></a>00100 log_debug(<span class="stringliteral">"APIServer init"</span>); <a name="l00101"></a>00101 } <a name="l00102"></a>00102 <a name="l00103"></a>00103 oasys::TclCommandInterp::instance()->reg(<span class="keyword">new</span> <a class="code" href="classdtn_1_1APICommand.html" title="API options command.">APICommand</a>(<span class="keyword">this</span>)); <a name="l00104"></a>00104 } <a name="l00105"></a>00105 <a name="l00106"></a>00106 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00107"></a>00107 <span class="keywordtype">void</span> <a name="l00108"></a><a class="code" href="classdtn_1_1APIServer.html#9e4edfeba6a6b7b05e489f346f79b125">00108</a> APIServer::accepted(<span class="keywordtype">int</span> <a class="code" href="dtnperf-client_8c.html#6f8059414f0228f0256115e024eeed4b">fd</a>, in_addr_t addr, u_int16_t port) <a name="l00109"></a>00109 { <a name="l00110"></a>00110 <a class="code" href="classdtn_1_1APIClient.html" title="Class that implements the API session.">APIClient</a>* c = <span class="keyword">new</span> <a class="code" href="classdtn_1_1APIClient.html" title="Class that implements the API session.">APIClient</a>(fd, addr, port, <span class="keyword">this</span>); <a name="l00111"></a>00111 <a class="code" href="classdtn_1_1APIServer.html#a59a177fa443ca1be6a9da71e3495973">register_client</a>(c); <a name="l00112"></a>00112 c->start(); <a name="l00113"></a>00113 } <a name="l00114"></a>00114 <a name="l00115"></a>00115 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00116"></a>00116 <a name="l00117"></a>00117 <span class="comment">// We keep a list of clients (register_client, unregister_client). As</span> <a name="l00118"></a>00118 <span class="comment">// each client shuts down it removes itself from the list. The server</span> <a name="l00119"></a>00119 <span class="comment">// sets should_stop to each of the clients, then spins waiting for the</span> <a name="l00120"></a>00120 <span class="comment">// list of clients to be emptied out. If we spin for a long time</span> <a name="l00121"></a>00121 <span class="comment">// (MAX_SPIN_TIME) without the list getting empty we give up.</span> <a name="l00122"></a>00122 <a name="l00123"></a>00123 <span class="comment">// note that the thread was created without DELETE_ON_EXIT so that the</span> <a name="l00124"></a>00124 <span class="comment">// thread object sticks around after the thread has died. This has the</span> <a name="l00125"></a>00125 <span class="comment">// upside of helping out APIClient objects that wake up after the</span> <a name="l00126"></a>00126 <span class="comment">// APIServer has given up on them (saving us from a core dump) but has</span> <a name="l00127"></a>00127 <span class="comment">// the downside of losing memory (one APIServer thread object). But</span> <a name="l00128"></a>00128 <span class="comment">// since the APIServer is shut down when we're about to exit, it's not</span> <a name="l00129"></a>00129 <span class="comment">// an issue. And only one APIServer is ever created.</span> <a name="l00130"></a>00130 <a name="l00131"></a>00131 <span class="keywordtype">void</span> <a name="l00132"></a><a class="code" href="classdtn_1_1APIServer.html#9799799151cc98f5e84b3deb6b68b33e">00132</a> <a class="code" href="classdtn_1_1APIServer.html#9799799151cc98f5e84b3deb6b68b33e">APIServer::shutdown_hook</a>() <a name="l00133"></a>00133 { <a name="l00134"></a>00134 <span class="comment">// tell the clients to shut down</span> <a name="l00135"></a>00135 std::list<APIClient *>::iterator ci; <a name="l00136"></a>00136 <a class="code" href="classdtn_1_1APIServer.html#ad197c6739024b73b03c6287206bd6df" title="synchronizer">client_list_lock</a>.lock(<span class="stringliteral">"APIServer::shutdown"</span>); <a name="l00137"></a>00137 <span class="keywordflow">for</span> (ci = <a class="code" href="classdtn_1_1APIServer.html#ce510dee43b8d52dc6b2ffec93aa5ded" title="active clients">client_list</a>.begin(); ci != <a class="code" href="classdtn_1_1APIServer.html#ce510dee43b8d52dc6b2ffec93aa5ded" title="active clients">client_list</a>.end(); ++ci) { <a name="l00138"></a>00138 (*ci)->set_should_stop(); <a name="l00139"></a>00139 } <a name="l00140"></a>00140 <a class="code" href="classdtn_1_1APIServer.html#ad197c6739024b73b03c6287206bd6df" title="synchronizer">client_list_lock</a>.unlock(); <a name="l00141"></a>00141 <a name="l00142"></a>00142 <span class="preprocessor">#define MAX_SPIN_TIME (5 * 1000000) // max sleep in usec</span> <a name="l00143"></a>00143 <span class="preprocessor"></span><span class="preprocessor">#define EACH_SPIN_TIME 10000 // sleep 10ms each time</span> <a name="l00144"></a>00144 <span class="preprocessor"></span> <a name="l00145"></a>00145 <span class="comment">// As clients exit they unregister themselves, so if a client is</span> <a name="l00146"></a>00146 <span class="comment">// still on the list we assume that it is still alive. So here we</span> <a name="l00147"></a>00147 <span class="comment">// loop until the list is empty or MAX_SLEEP_TIME usecs have</span> <a name="l00148"></a>00148 <span class="comment">// passed. (We have a time out in case a client thread is wedged</span> <a name="l00149"></a>00149 <span class="comment">// or blocked waiting for a client. What we really want to catch</span> <a name="l00150"></a>00150 <span class="comment">// here is clients in the middle of processing a request.)</span> <a name="l00151"></a>00151 <span class="keywordtype">int</span> <a class="code" href="dtnping_8c.html#d43c3812e6d13e0518d9f8b8f463ffcf">count</a> = 0; <a name="l00152"></a>00152 <span class="keywordflow">while</span> (count++ < (<a class="code" href="APIServer_8cc.html#ef90b092d3ca34889802b64e24d11992">MAX_SPIN_TIME</a> / <a class="code" href="APIServer_8cc.html#b480dd65667f0c3033bbf2ebda0c2ee5">EACH_SPIN_TIME</a>)) { <a name="l00153"></a>00153 <a class="code" href="classdtn_1_1APIServer.html#ad197c6739024b73b03c6287206bd6df" title="synchronizer">client_list_lock</a>.lock(<span class="stringliteral">"APIServer::shutdown"</span>); <a name="l00154"></a>00154 <span class="keywordtype">bool</span> empty = <a class="code" href="classdtn_1_1APIServer.html#ce510dee43b8d52dc6b2ffec93aa5ded" title="active clients">client_list</a>.empty(); <a name="l00155"></a>00155 <a class="code" href="classdtn_1_1APIServer.html#ad197c6739024b73b03c6287206bd6df" title="synchronizer">client_list_lock</a>.unlock(); <a name="l00156"></a>00156 <span class="keywordflow">if</span> (!empty) <a name="l00157"></a>00157 usleep(<a class="code" href="APIServer_8cc.html#b480dd65667f0c3033bbf2ebda0c2ee5">EACH_SPIN_TIME</a>); <a name="l00158"></a>00158 <span class="keywordflow">else</span> <a name="l00159"></a>00159 <span class="keywordflow">break</span>; <a name="l00160"></a>00160 } <a name="l00161"></a>00161 <span class="keywordflow">return</span>; <a name="l00162"></a>00162 } <a name="l00163"></a>00163 <a name="l00164"></a>00164 <a name="l00165"></a>00165 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00166"></a>00166 <a name="l00167"></a>00167 <span class="comment">// manages a list of APIClient objects (threads) that have not exited yet.</span> <a name="l00168"></a>00168 <a name="l00169"></a>00169 <span class="keywordtype">void</span> <a name="l00170"></a><a class="code" href="classdtn_1_1APIServer.html#a59a177fa443ca1be6a9da71e3495973">00170</a> <a class="code" href="classdtn_1_1APIServer.html#a59a177fa443ca1be6a9da71e3495973">APIServer::register_client</a>(<a class="code" href="classdtn_1_1APIClient.html" title="Class that implements the API session.">APIClient</a> *c) <a name="l00171"></a>00171 { <a name="l00172"></a>00172 oasys::ScopeLock l(&<a class="code" href="classdtn_1_1APIServer.html#ad197c6739024b73b03c6287206bd6df" title="synchronizer">client_list_lock</a>, <span class="stringliteral">"APIServer::register_client"</span>); <a name="l00173"></a>00173 <a class="code" href="classdtn_1_1APIServer.html#ce510dee43b8d52dc6b2ffec93aa5ded" title="active clients">client_list</a>.push_front(c); <a name="l00174"></a>00174 } <a name="l00175"></a>00175 <a name="l00176"></a>00176 <span class="keywordtype">void</span> <a name="l00177"></a><a class="code" href="classdtn_1_1APIServer.html#fd9f7a445d44dfac0805db7846296f8e">00177</a> <a class="code" href="classdtn_1_1APIServer.html#fd9f7a445d44dfac0805db7846296f8e">APIServer::unregister_client</a>(<a class="code" href="classdtn_1_1APIClient.html" title="Class that implements the API session.">APIClient</a> *c) <a name="l00178"></a>00178 { <a name="l00179"></a>00179 <span class="comment">// remove c from the list of active clients</span> <a name="l00180"></a>00180 oasys::ScopeLock l(&<a class="code" href="classdtn_1_1APIServer.html#ad197c6739024b73b03c6287206bd6df" title="synchronizer">client_list_lock</a>, <span class="stringliteral">"APIServer::unregister_client"</span>); <a name="l00181"></a>00181 <a class="code" href="classdtn_1_1APIServer.html#ce510dee43b8d52dc6b2ffec93aa5ded" title="active clients">client_list</a>.remove(c); <a name="l00182"></a>00182 } <a name="l00183"></a>00183 <a name="l00184"></a>00184 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00185"></a><a class="code" href="classdtn_1_1APIClient.html#0a3ca236759a37189d2ff7bf19f4b977">00185</a> <a class="code" href="classdtn_1_1APIClient.html#0a3ca236759a37189d2ff7bf19f4b977">APIClient::APIClient</a>(<span class="keywordtype">int</span> <a class="code" href="dtnperf-client_8c.html#6f8059414f0228f0256115e024eeed4b">fd</a>, in_addr_t addr, u_int16_t port, <a class="code" href="classdtn_1_1APIServer.html" title="Class that implements the main server side handling of the DTN application IPC.">APIServer</a> *parent) <a name="l00186"></a>00186 : Thread(<span class="stringliteral">"APIClient"</span>, DELETE_ON_EXIT), <a name="l00187"></a>00187 TCPClient(fd, addr, port, <span class="stringliteral">"/dtn/apiclient"</span>), <a name="l00188"></a>00188 notifier_(logpath_), <a name="l00189"></a>00189 parent_(parent), <a name="l00190"></a>00190 total_sent_(0), <a name="l00191"></a>00191 total_rcvd_(0) <a name="l00192"></a>00192 { <a name="l00193"></a>00193 <span class="comment">// note that we skip space for the message length and code/status</span> <a name="l00194"></a>00194 xdrmem_create(&<a class="code" href="classdtn_1_1APIClient.html#913a8a0ef9793ca0ad9742be58aaa5e9">xdr_encode_</a>, <a class="code" href="classdtn_1_1APIClient.html#3d1129c8e4961bb050af83f927f57546">buf_</a> + 8, <a class="code" href="dtn__ipc_8h.html#51d06f90137293f017ba7e9019d6602f" title="The maximum IPC message size (in bytes).">DTN_MAX_API_MSG</a> - 8, XDR_ENCODE); <a name="l00195"></a>00195 xdrmem_create(&<a class="code" href="classdtn_1_1APIClient.html#ace73b2d7a0e5c748ee9c1bf741c5b41">xdr_decode_</a>, <a class="code" href="classdtn_1_1APIClient.html#3d1129c8e4961bb050af83f927f57546">buf_</a> + 8, <a class="code" href="dtn__ipc_8h.html#51d06f90137293f017ba7e9019d6602f" title="The maximum IPC message size (in bytes).">DTN_MAX_API_MSG</a> - 8, XDR_DECODE); <a name="l00196"></a>00196 <a name="l00197"></a>00197 <a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a> = <span class="keyword">new</span> <a class="code" href="classdtn_1_1APIRegistrationList.html" title="Typedef for a list of APIRegistrations.">APIRegistrationList</a>(); <a name="l00198"></a>00198 <a class="code" href="classdtn_1_1APIClient.html#5448e687c48be53a1df5d5246b0f7e3f">sessions_</a> = <span class="keyword">new</span> <a class="code" href="classdtn_1_1APIRegistrationList.html" title="Typedef for a list of APIRegistrations.">APIRegistrationList</a>(); <a name="l00199"></a>00199 } <a name="l00200"></a>00200 <a name="l00201"></a>00201 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00202"></a><a class="code" href="classdtn_1_1APIClient.html#b492c133ba9f0c9b22c69f067900be8a">00202</a> <a class="code" href="classdtn_1_1APIClient.html#b492c133ba9f0c9b22c69f067900be8a">APIClient::~APIClient</a>() <a name="l00203"></a>00203 { <a name="l00204"></a>00204 log_debug(<span class="stringliteral">"client destroyed"</span>); <a name="l00205"></a>00205 delete_z(<a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>); <a name="l00206"></a>00206 delete_z(<a class="code" href="classdtn_1_1APIClient.html#5448e687c48be53a1df5d5246b0f7e3f">sessions_</a>); <a name="l00207"></a>00207 } <a name="l00208"></a>00208 <a name="l00209"></a>00209 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00210"></a>00210 <span class="keywordtype">void</span> <a name="l00211"></a><a class="code" href="classdtn_1_1APIClient.html#6681a2fe127ddcfc2880004d21f06b19">00211</a> <a class="code" href="classdtn_1_1APIClient.html#6681a2fe127ddcfc2880004d21f06b19">APIClient::close_client</a>() <a name="l00212"></a>00212 { <a name="l00213"></a>00213 TCPClient::close(); <a name="l00214"></a>00214 <a name="l00215"></a>00215 <a class="code" href="classdtn_1_1APIRegistration.html" title="Registration class to represent an actual attached application over the client api...">APIRegistration</a>* reg; <a name="l00216"></a>00216 <span class="keywordflow">while</span> (! <a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>->empty()) { <a name="l00217"></a>00217 reg = <a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>->front(); <a name="l00218"></a>00218 <a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>->pop_front(); <a name="l00219"></a>00219 <a name="l00220"></a>00220 reg-><a class="code" href="classdtn_1_1Registration.html#ab703ed5afcd162fd7295954867a3fba" title="Accessors.">set_active</a>(<span class="keyword">false</span>); <a name="l00221"></a>00221 <a name="l00222"></a>00222 <span class="keywordflow">if</span> (reg-><a class="code" href="classdtn_1_1Registration.html#8222b37765e97aa6447469668c992b42" title="Accessors.">expired</a>()) { <a name="l00223"></a>00223 log_debug(<span class="stringliteral">"removing expired registration %d"</span>, reg-><a class="code" href="classdtn_1_1Registration.html#d1cd25dd8e4c512591849f44e7c8090b" title="Accessors.">regid</a>()); <a name="l00224"></a>00224 <a class="code" href="classdtn_1_1BundleDaemon.html#370a80f7dd9fd9297e76d7f830d737a8" title="Queues the event at the tail of the queue for processing by the daemon thread.">BundleDaemon::post</a>(<span class="keyword">new</span> <a class="code" href="classdtn_1_1RegistrationExpiredEvent.html" title="Event class for registration expiration.">RegistrationExpiredEvent</a>(reg)); <a name="l00225"></a>00225 } <a name="l00226"></a>00226 } <a name="l00227"></a>00227 <a name="l00228"></a>00228 <span class="comment">// XXX/demmer memory leak here?</span> <a name="l00229"></a>00229 <a class="code" href="classdtn_1_1APIClient.html#5448e687c48be53a1df5d5246b0f7e3f">sessions_</a>->clear(); <a name="l00230"></a>00230 <a name="l00231"></a>00231 <a class="code" href="classdtn_1_1APIClient.html#f3458aa411cf077c6d7196433aec8db2">parent_</a>-><a class="code" href="classdtn_1_1APIServer.html#fd9f7a445d44dfac0805db7846296f8e">unregister_client</a>(<span class="keyword">this</span>); <a name="l00232"></a>00232 } <a name="l00233"></a>00233 <a name="l00234"></a>00234 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00235"></a>00235 <span class="keywordtype">int</span> <a name="l00236"></a><a class="code" href="classdtn_1_1APIClient.html#8ccf701f5461adce95be8ee1e4781ebf">00236</a> <a class="code" href="classdtn_1_1APIClient.html#8ccf701f5461adce95be8ee1e4781ebf">APIClient::handle_handshake</a>() <a name="l00237"></a>00237 { <a name="l00238"></a>00238 u_int32_t handshake; <a name="l00239"></a>00239 u_int16_t message_type, ipc_version; <a name="l00240"></a>00240 <a name="l00241"></a>00241 <span class="keywordtype">int</span> ret = readall((<span class="keywordtype">char</span>*)&handshake, <span class="keyword">sizeof</span>(handshake)); <a name="l00242"></a>00242 <span class="keywordflow">if</span> (ret != <span class="keyword">sizeof</span>(handshake)) { <a name="l00243"></a>00243 log_err(<span class="stringliteral">"error reading handshake: (got %d/%zu), \"error\" %s"</span>, <a name="l00244"></a>00244 ret, <span class="keyword">sizeof</span>(handshake), strerror(<a class="code" href="IPDiscovery_8cc.html#d65a8842cc674e3ddf69355898c0ecbf">errno</a>)); <a name="l00245"></a>00245 <span class="keywordflow">return</span> -1; <a name="l00246"></a>00246 } <a name="l00247"></a>00247 <a name="l00248"></a>00248 <a class="code" href="classdtn_1_1APIClient.html#64c975c94dafb44c3d761065498aa62f">total_rcvd_</a> += ret; <a name="l00249"></a>00249 <a name="l00250"></a>00250 message_type = ntohl(handshake) >> 16; <a name="l00251"></a>00251 ipc_version = (u_int16_t) (ntohl(handshake) & 0x0ffff); <a name="l00252"></a>00252 <a name="l00253"></a>00253 <span class="keywordflow">if</span> (message_type != <a class="code" href="dtn__ipc_8h.html#c05301bf9560764f5e97fba507ef9e5d4e9e92913a117e7b6c92b2dee3eab867">DTN_OPEN</a>) { <a name="l00254"></a>00254 log_err(<span class="stringliteral">"handshake (0x%x)'s message type %d != DTN_OPEN (%d)"</span>, <a name="l00255"></a>00255 handshake, message_type, <a class="code" href="dtn__ipc_8h.html#c05301bf9560764f5e97fba507ef9e5d4e9e92913a117e7b6c92b2dee3eab867">DTN_OPEN</a>); <a name="l00256"></a>00256 <span class="keywordflow">return</span> -1; <a name="l00257"></a>00257 } <a name="l00258"></a>00258 <a name="l00259"></a>00259 <span class="comment">// to handle version mismatch more cleanly, we re-build the</span> <a name="l00260"></a>00260 <span class="comment">// handshake word with our own version and send it back to inform</span> <a name="l00261"></a>00261 <span class="comment">// the client, then if there's a mismatch, close the channel</span> <a name="l00262"></a>00262 handshake = htonl(<a class="code" href="dtn__ipc_8h.html#c05301bf9560764f5e97fba507ef9e5d4e9e92913a117e7b6c92b2dee3eab867">DTN_OPEN</a> << 16 | <a class="code" href="dtn__ipc_8h.html#2afeec365b4613086d19c23e8551d838" title="DTN IPC version.">DTN_IPC_VERSION</a>); <a name="l00263"></a>00263 <a name="l00264"></a>00264 ret = writeall((<span class="keywordtype">char</span>*)&handshake, <span class="keyword">sizeof</span>(handshake)); <a name="l00265"></a>00265 <span class="keywordflow">if</span> (ret != <span class="keyword">sizeof</span>(handshake)) { <a name="l00266"></a>00266 log_err(<span class="stringliteral">"error writing handshake: %s"</span>, strerror(<a class="code" href="IPDiscovery_8cc.html#d65a8842cc674e3ddf69355898c0ecbf">errno</a>)); <a name="l00267"></a>00267 <span class="keywordflow">return</span> -1; <a name="l00268"></a>00268 } <a name="l00269"></a>00269 <a name="l00270"></a>00270 <a class="code" href="classdtn_1_1APIClient.html#98a37692381356296c960cd1713ab9e8">total_sent_</a> += ret; <a name="l00271"></a>00271 <a name="l00272"></a>00272 <span class="keywordflow">if</span> (ipc_version != <a class="code" href="dtn__ipc_8h.html#2afeec365b4613086d19c23e8551d838" title="DTN IPC version.">DTN_IPC_VERSION</a>) { <a name="l00273"></a>00273 log_err(<span class="stringliteral">"handshake (0x%x)'s version %d != DTN_IPC_VERSION (%d)"</span>, <a name="l00274"></a>00274 handshake, ipc_version, <a class="code" href="dtn__ipc_8h.html#2afeec365b4613086d19c23e8551d838" title="DTN IPC version.">DTN_IPC_VERSION</a>); <a name="l00275"></a>00275 <span class="keywordflow">return</span> -1; <a name="l00276"></a>00276 } <a name="l00277"></a>00277 <a name="l00278"></a>00278 <span class="keywordflow">return</span> 0; <a name="l00279"></a>00279 } <a name="l00280"></a>00280 <a name="l00281"></a>00281 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00282"></a>00282 <span class="keywordtype">void</span> <a name="l00283"></a><a class="code" href="classdtn_1_1APIClient.html#1f9b4788d77129db1a3f8a6fb0f1da61">00283</a> <a class="code" href="classdtn_1_1APIClient.html#1f9b4788d77129db1a3f8a6fb0f1da61">APIClient::run</a>() <a name="l00284"></a>00284 { <a name="l00285"></a>00285 <span class="keywordtype">int</span> ret; <a name="l00286"></a>00286 u_int8_t type; <a name="l00287"></a>00287 u_int32_t <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>; <a name="l00288"></a>00288 <a name="l00289"></a>00289 log_info(<span class="stringliteral">"new session %s:%d -> %s:%d"</span>, <a name="l00290"></a>00290 intoa(local_addr()), local_port(), <a name="l00291"></a>00291 intoa(remote_addr()), remote_port()); <a name="l00292"></a>00292 <a name="l00293"></a>00293 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1APIClient.html#8ccf701f5461adce95be8ee1e4781ebf">handle_handshake</a>() != 0) { <a name="l00294"></a>00294 <a class="code" href="classdtn_1_1APIClient.html#6681a2fe127ddcfc2880004d21f06b19">close_client</a>(); <a name="l00295"></a>00295 <span class="keywordflow">return</span>; <a name="l00296"></a>00296 } <a name="l00297"></a>00297 <a name="l00298"></a>00298 <span class="keywordflow">while</span> (<span class="keyword">true</span>) { <a name="l00299"></a>00299 <span class="comment">// check if someone has told us to quit by setting the</span> <a name="l00300"></a>00300 <span class="comment">// should_stop flag. if so, we're all done</span> <a name="l00301"></a>00301 <span class="keywordflow">if</span> (should_stop()) { <a name="l00302"></a>00302 <a class="code" href="classdtn_1_1APIClient.html#6681a2fe127ddcfc2880004d21f06b19">close_client</a>(); <a name="l00303"></a>00303 <span class="keywordflow">return</span>; <a name="l00304"></a>00304 } <a name="l00305"></a>00305 <a name="l00306"></a>00306 xdr_setpos(&<a class="code" href="classdtn_1_1APIClient.html#913a8a0ef9793ca0ad9742be58aaa5e9">xdr_encode_</a>, 0); <a name="l00307"></a>00307 xdr_setpos(&<a class="code" href="classdtn_1_1APIClient.html#ace73b2d7a0e5c748ee9c1bf741c5b41">xdr_decode_</a>, 0); <a name="l00308"></a>00308 <a name="l00309"></a>00309 <span class="comment">// read the typecode and length of the incoming message into</span> <a name="l00310"></a>00310 <span class="comment">// the fourth byte of the, since the pair is five bytes long</span> <a name="l00311"></a>00311 <span class="comment">// and the XDR engines are set to point at the eighth byte of</span> <a name="l00312"></a>00312 <span class="comment">// the buffer</span> <a name="l00313"></a>00313 log_debug(<span class="stringliteral">"waiting for next message... total sent/rcvd: %zu/%zu"</span>, <a name="l00314"></a>00314 <a class="code" href="classdtn_1_1APIClient.html#98a37692381356296c960cd1713ab9e8">total_sent_</a>, <a class="code" href="classdtn_1_1APIClient.html#64c975c94dafb44c3d761065498aa62f">total_rcvd_</a>); <a name="l00315"></a>00315 <a name="l00316"></a>00316 ret = read(&<a class="code" href="classdtn_1_1APIClient.html#3d1129c8e4961bb050af83f927f57546">buf_</a>[3], 5); <a name="l00317"></a>00317 <span class="keywordflow">if</span> (ret <= 0) { <a name="l00318"></a>00318 log_warn(<span class="stringliteral">"client disconnected without calling dtn_close"</span>); <a name="l00319"></a>00319 <a class="code" href="classdtn_1_1APIClient.html#6681a2fe127ddcfc2880004d21f06b19">close_client</a>(); <a name="l00320"></a>00320 <span class="keywordflow">return</span>; <a name="l00321"></a>00321 } <a name="l00322"></a>00322 <a class="code" href="classdtn_1_1APIClient.html#64c975c94dafb44c3d761065498aa62f">total_rcvd_</a> += ret; <a name="l00323"></a>00323 <a name="l00324"></a>00324 <span class="keywordflow">if</span> (ret < 5) { <a name="l00325"></a>00325 log_err(<span class="stringliteral">"ack!! can't handle really short read..."</span>); <a name="l00326"></a>00326 <a class="code" href="classdtn_1_1APIClient.html#6681a2fe127ddcfc2880004d21f06b19">close_client</a>(); <a name="l00327"></a>00327 <span class="keywordflow">return</span>; <a name="l00328"></a>00328 } <a name="l00329"></a>00329 <a name="l00330"></a>00330 <span class="comment">// NOTE: this protocol is duplicated in the implementation of</span> <a name="l00331"></a>00331 <span class="comment">// handle_begin_poll to take care of a cancel_poll request</span> <a name="l00332"></a>00332 <span class="comment">// coming in while the thread is waiting for bundles so any</span> <a name="l00333"></a>00333 <span class="comment">// modifications must be propagated there</span> <a name="l00334"></a>00334 type = <a class="code" href="classdtn_1_1APIClient.html#3d1129c8e4961bb050af83f927f57546">buf_</a>[3]; <a name="l00335"></a>00335 memcpy(&len, &<a class="code" href="classdtn_1_1APIClient.html#3d1129c8e4961bb050af83f927f57546">buf_</a>[4], <span class="keyword">sizeof</span>(len)); <a name="l00336"></a>00336 <a name="l00337"></a>00337 len = ntohl(len); <a name="l00338"></a>00338 <a name="l00339"></a>00339 ret -= 5; <a name="l00340"></a>00340 log_debug(<span class="stringliteral">"got %s (%d/%d bytes)"</span>, <a class="code" href="dtn__ipc_8c.html#c5707d2923063f6fe2bde512f525f72b" title="Type code to string conversion routine.">dtnipc_msgtoa</a>(type), ret, len); <a name="l00341"></a>00341 <a name="l00342"></a>00342 <span class="comment">// if we didn't get the whole message, loop to get the rest,</span> <a name="l00343"></a>00343 <span class="comment">// skipping the header bytes and the already-read amount</span> <a name="l00344"></a>00344 <span class="keywordflow">if</span> (ret < (<span class="keywordtype">int</span>)len) { <a name="l00345"></a>00345 <span class="keywordtype">int</span> toget = len - ret; <a name="l00346"></a>00346 log_debug(<span class="stringliteral">"reading remainder of message... total sent/rcvd: %zu/%zu"</span>, <a name="l00347"></a>00347 <a class="code" href="classdtn_1_1APIClient.html#98a37692381356296c960cd1713ab9e8">total_sent_</a>, <a class="code" href="classdtn_1_1APIClient.html#64c975c94dafb44c3d761065498aa62f">total_rcvd_</a>); <a name="l00348"></a>00348 <span class="keywordflow">if</span> (readall(&<a class="code" href="classdtn_1_1APIClient.html#3d1129c8e4961bb050af83f927f57546">buf_</a>[8 + ret], toget) != toget) { <a name="l00349"></a>00349 log_err(<span class="stringliteral">"error reading message remainder: %s"</span>, <a name="l00350"></a>00350 strerror(<a class="code" href="IPDiscovery_8cc.html#d65a8842cc674e3ddf69355898c0ecbf">errno</a>)); <a name="l00351"></a>00351 <a class="code" href="classdtn_1_1APIClient.html#6681a2fe127ddcfc2880004d21f06b19">close_client</a>(); <a name="l00352"></a>00352 <span class="keywordflow">return</span>; <a name="l00353"></a>00353 } <a name="l00354"></a>00354 <a class="code" href="classdtn_1_1APIClient.html#64c975c94dafb44c3d761065498aa62f">total_rcvd_</a> += toget; <a name="l00355"></a>00355 } <a name="l00356"></a>00356 <a name="l00357"></a>00357 <span class="comment">// check if someone has told us to quit by setting the</span> <a name="l00358"></a>00358 <span class="comment">// should_stop flag. if so, we're all done</span> <a name="l00359"></a>00359 <span class="keywordflow">if</span> (should_stop()) { <a name="l00360"></a>00360 <a class="code" href="classdtn_1_1APIClient.html#6681a2fe127ddcfc2880004d21f06b19">close_client</a>(); <a name="l00361"></a>00361 <span class="keywordflow">return</span>; <a name="l00362"></a>00362 } <a name="l00363"></a>00363 <a name="l00364"></a>00364 <span class="comment">// dispatch to the handler routine</span> <a name="l00365"></a>00365 <span class="keywordflow">switch</span>(type) { <a name="l00366"></a>00366 <span class="preprocessor">#define DISPATCH(_type, _fn) \</span> <a name="l00367"></a>00367 <span class="preprocessor"> case _type: \</span> <a name="l00368"></a>00368 <span class="preprocessor"> ret = _fn(); \</span> <a name="l00369"></a>00369 <span class="preprocessor"> break;</span> <a name="l00370"></a>00370 <span class="preprocessor"></span> <a name="l00371"></a>00371 <a class="code" href="APIServer_8cc.html#b69d2900b1ebf251ee1ea1d8f880b47a">DISPATCH</a>(<a class="code" href="dtn__ipc_8h.html#c05301bf9560764f5e97fba507ef9e5d92dab95353850a6e914e4008347f07c7">DTN_LOCAL_EID</a>, <a class="code" href="classdtn_1_1APIClient.html#84d763e96acc0b07d425f4cf003ba257">handle_local_eid</a>); <a name="l00372"></a>00372 <a class="code" href="APIServer_8cc.html#b69d2900b1ebf251ee1ea1d8f880b47a">DISPATCH</a>(<a class="code" href="dtn__ipc_8h.html#c05301bf9560764f5e97fba507ef9e5de7933a4eff1b95879d4a353df40b195f">DTN_REGISTER</a>, <a class="code" href="classdtn_1_1APIClient.html#56bb3d82073d910564ece376b710fee4">handle_register</a>); <a name="l00373"></a>00373 <a class="code" href="APIServer_8cc.html#b69d2900b1ebf251ee1ea1d8f880b47a">DISPATCH</a>(<a class="code" href="dtn__ipc_8h.html#c05301bf9560764f5e97fba507ef9e5d1e3888bf2ac2f73a90c6c142080279f5">DTN_UNREGISTER</a>, <a class="code" href="classdtn_1_1APIClient.html#3ace90f9a37789ba35368c9f2f7d5489">handle_unregister</a>); <a name="l00374"></a>00374 <a class="code" href="APIServer_8cc.html#b69d2900b1ebf251ee1ea1d8f880b47a">DISPATCH</a>(<a class="code" href="dtn__ipc_8h.html#c05301bf9560764f5e97fba507ef9e5df41ecaa2e442e281718ce6c7cd88fe30">DTN_FIND_REGISTRATION</a>, <a class="code" href="classdtn_1_1APIClient.html#262746ba8158df642ab53a2083c51e77">handle_find_registration</a>); <a name="l00375"></a>00375 <a class="code" href="APIServer_8cc.html#b69d2900b1ebf251ee1ea1d8f880b47a">DISPATCH</a>(<a class="code" href="dtn__ipc_8h.html#c05301bf9560764f5e97fba507ef9e5d00609e70cdd50ac4a6d989603c2976bf">DTN_SEND</a>, <a class="code" href="classdtn_1_1APIClient.html#6961c3dcfe571414d3da893554ec7176">handle_send</a>); <a name="l00376"></a>00376 <a class="code" href="APIServer_8cc.html#b69d2900b1ebf251ee1ea1d8f880b47a">DISPATCH</a>(<a class="code" href="dtn__ipc_8h.html#c05301bf9560764f5e97fba507ef9e5d8ac916eaefdf27a024e85c5a71ef7caf">DTN_CANCEL</a>, <a class="code" href="classdtn_1_1APIClient.html#55108097eb6498f788eebadd3311725f">handle_cancel</a>); <a name="l00377"></a>00377 <a class="code" href="APIServer_8cc.html#b69d2900b1ebf251ee1ea1d8f880b47a">DISPATCH</a>(<a class="code" href="dtn__ipc_8h.html#c05301bf9560764f5e97fba507ef9e5d59676a9e0dd2cf2a2ebb493721f50198">DTN_BIND</a>, <a class="code" href="classdtn_1_1APIClient.html#98e793d1feb9e5254578bdbc357f7489">handle_bind</a>); <a name="l00378"></a>00378 <a class="code" href="APIServer_8cc.html#b69d2900b1ebf251ee1ea1d8f880b47a">DISPATCH</a>(<a class="code" href="dtn__ipc_8h.html#c05301bf9560764f5e97fba507ef9e5d801be28596a84f1a0ec58c57eac06b5b">DTN_UNBIND</a>, <a class="code" href="classdtn_1_1APIClient.html#fa8cf363d0568517bf082ef60a485938">handle_unbind</a>); <a name="l00379"></a>00379 <a class="code" href="APIServer_8cc.html#b69d2900b1ebf251ee1ea1d8f880b47a">DISPATCH</a>(<a class="code" href="dtn__ipc_8h.html#c05301bf9560764f5e97fba507ef9e5da5a90d9130e7ad725dede5a0c4110495">DTN_RECV</a>, <a class="code" href="classdtn_1_1APIClient.html#62bed4eeeb10a011c0dca071d32b1aff">handle_recv</a>); <a name="l00380"></a>00380 <a class="code" href="APIServer_8cc.html#b69d2900b1ebf251ee1ea1d8f880b47a">DISPATCH</a>(<a class="code" href="dtn__ipc_8h.html#c05301bf9560764f5e97fba507ef9e5d5f4461d4add4e2832436f9c8ae25e61e">DTN_BEGIN_POLL</a>, <a class="code" href="classdtn_1_1APIClient.html#e082ab699cdd974eff4be0b3622342e4">handle_begin_poll</a>); <a name="l00381"></a>00381 <a class="code" href="APIServer_8cc.html#b69d2900b1ebf251ee1ea1d8f880b47a">DISPATCH</a>(<a class="code" href="dtn__ipc_8h.html#c05301bf9560764f5e97fba507ef9e5df37b9c7e51b4309e5f3ca74a8b743c3b">DTN_CANCEL_POLL</a>, <a class="code" href="classdtn_1_1APIClient.html#67898f3771df3d7780d7dd7f3baf0f14">handle_cancel_poll</a>); <a name="l00382"></a>00382 <a class="code" href="APIServer_8cc.html#b69d2900b1ebf251ee1ea1d8f880b47a">DISPATCH</a>(<a class="code" href="dtn__ipc_8h.html#c05301bf9560764f5e97fba507ef9e5d88988342732cf7736a9a17338475582e">DTN_CLOSE</a>, <a class="code" href="classdtn_1_1APIClient.html#ba38760ce21e619d3296059842f56928">handle_close</a>); <a name="l00383"></a>00383 <a class="code" href="APIServer_8cc.html#b69d2900b1ebf251ee1ea1d8f880b47a">DISPATCH</a>(<a class="code" href="dtn__ipc_8h.html#c05301bf9560764f5e97fba507ef9e5d7f9ec4960a1d48ce448a1f7c2dfc0d5a">DTN_SESSION_UPDATE</a>, <a class="code" href="classdtn_1_1APIClient.html#f19b929f413fea3504c794202068c4d7">handle_session_update</a>); <a name="l00384"></a>00384 <span class="preprocessor">#undef DISPATCH</span> <a name="l00385"></a>00385 <span class="preprocessor"></span> <a name="l00386"></a>00386 <span class="keywordflow">default</span>: <a name="l00387"></a>00387 log_err(<span class="stringliteral">"unknown message type code 0x%x"</span>, type); <a name="l00388"></a>00388 ret = <a class="code" href="dtn__errno_8h.html#821d437975e7fec44cb53b89adf7e80a">DTN_EMSGTYPE</a>; <a name="l00389"></a>00389 <span class="keywordflow">break</span>; <a name="l00390"></a>00390 } <a name="l00391"></a>00391 <a name="l00392"></a>00392 <span class="comment">// if the handler returned -1, then the session should be</span> <a name="l00393"></a>00393 <span class="comment">// immediately terminated</span> <a name="l00394"></a>00394 <span class="keywordflow">if</span> (ret == -1) { <a name="l00395"></a>00395 <a class="code" href="classdtn_1_1APIClient.html#6681a2fe127ddcfc2880004d21f06b19">close_client</a>(); <a name="l00396"></a>00396 <span class="keywordflow">return</span>; <a name="l00397"></a>00397 } <a name="l00398"></a>00398 <a name="l00399"></a>00399 <span class="comment">// send the response</span> <a name="l00400"></a>00400 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1APIClient.html#476beb5eb7b7073738e3a9c18de1ab5f">send_response</a>(ret) != 0) { <a name="l00401"></a>00401 <span class="keywordflow">return</span>; <a name="l00402"></a>00402 } <a name="l00403"></a>00403 <a name="l00404"></a>00404 <span class="comment">// if there was an IPC communication error or unknown message</span> <a name="l00405"></a>00405 <span class="comment">// type, close terminate the session</span> <a name="l00406"></a>00406 <span class="comment">// XXX/matt we could potentially close on all errors, not just these 2</span> <a name="l00407"></a>00407 <span class="keywordflow">if</span> (ret == <a class="code" href="dtn__errno_8h.html#b4ae5bb2a6256b2dac33962e688584de">DTN_ECOMM</a> || ret == <a class="code" href="dtn__errno_8h.html#821d437975e7fec44cb53b89adf7e80a">DTN_EMSGTYPE</a>) { <a name="l00408"></a>00408 <a class="code" href="classdtn_1_1APIClient.html#6681a2fe127ddcfc2880004d21f06b19">close_client</a>(); <a name="l00409"></a>00409 <span class="keywordflow">return</span>; <a name="l00410"></a>00410 } <a name="l00411"></a>00411 <a name="l00412"></a>00412 } <span class="comment">// while(1)</span> <a name="l00413"></a>00413 } <a name="l00414"></a>00414 <a name="l00415"></a>00415 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00416"></a>00416 <span class="keywordtype">int</span> <a name="l00417"></a><a class="code" href="classdtn_1_1APIClient.html#476beb5eb7b7073738e3a9c18de1ab5f">00417</a> <a class="code" href="classdtn_1_1APIClient.html#476beb5eb7b7073738e3a9c18de1ab5f">APIClient::send_response</a>(<span class="keywordtype">int</span> ret) <a name="l00418"></a>00418 { <a name="l00419"></a>00419 u_int32_t <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>, msglen; <a name="l00420"></a>00420 <a name="l00421"></a>00421 <span class="comment">// make sure the dispatched function returned a valid error</span> <a name="l00422"></a>00422 <span class="comment">// code</span> <a name="l00423"></a>00423 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(ret == <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a> || <a name="l00424"></a>00424 (<a class="code" href="dtn__errno_8h.html#a8032a87bccfd732a7e9324732a994ce">DTN_ERRBASE</a> <= ret && ret <= <a class="code" href="dtn__errno_8h.html#1cd5eb95c18872e2914ba983eba5029c">DTN_ERRMAX</a>)); <a name="l00425"></a>00425 <a name="l00426"></a>00426 <span class="comment">// fill in the reply message with the status code and the</span> <a name="l00427"></a>00427 <span class="comment">// length of the reply. note that if there is no reply, then</span> <a name="l00428"></a>00428 <span class="comment">// the xdr position should still be zero</span> <a name="l00429"></a>00429 len = xdr_getpos(&<a class="code" href="classdtn_1_1APIClient.html#913a8a0ef9793ca0ad9742be58aaa5e9">xdr_encode_</a>); <a name="l00430"></a>00430 log_debug(<span class="stringliteral">"building reply: status %s, length %d"</span>, <a name="l00431"></a>00431 <a class="code" href="dtn__errno_8c.html#1b23d549407e59e3ce2a1c32e3885b1d" title="Get a string value associated with the dtn error code.">dtn_strerror</a>(ret), len); <a name="l00432"></a>00432 <a name="l00433"></a>00433 msglen = len + 8; <a name="l00434"></a>00434 ret = ntohl(ret); <a name="l00435"></a>00435 len = htonl(len); <a name="l00436"></a>00436 <a name="l00437"></a>00437 memcpy(<a class="code" href="classdtn_1_1APIClient.html#3d1129c8e4961bb050af83f927f57546">buf_</a>, &ret, <span class="keyword">sizeof</span>(ret)); <a name="l00438"></a>00438 memcpy(&<a class="code" href="classdtn_1_1APIClient.html#3d1129c8e4961bb050af83f927f57546">buf_</a>[4], &len, <span class="keyword">sizeof</span>(len)); <a name="l00439"></a>00439 <a name="l00440"></a>00440 log_debug(<span class="stringliteral">"sending %d byte reply message... total sent/rcvd: %zu/%zu"</span>, <a name="l00441"></a>00441 msglen, <a class="code" href="classdtn_1_1APIClient.html#98a37692381356296c960cd1713ab9e8">total_sent_</a>, <a class="code" href="classdtn_1_1APIClient.html#64c975c94dafb44c3d761065498aa62f">total_rcvd_</a>); <a name="l00442"></a>00442 <a name="l00443"></a>00443 <span class="keywordflow">if</span> (writeall(<a class="code" href="classdtn_1_1APIClient.html#3d1129c8e4961bb050af83f927f57546">buf_</a>, msglen) != (<span class="keywordtype">int</span>)msglen) { <a name="l00444"></a>00444 log_err(<span class="stringliteral">"error sending reply: %s"</span>, strerror(<a class="code" href="IPDiscovery_8cc.html#d65a8842cc674e3ddf69355898c0ecbf">errno</a>)); <a name="l00445"></a>00445 <a class="code" href="classdtn_1_1APIClient.html#6681a2fe127ddcfc2880004d21f06b19">close_client</a>(); <a name="l00446"></a>00446 <span class="keywordflow">return</span> -1; <a name="l00447"></a>00447 } <a name="l00448"></a>00448 <a name="l00449"></a>00449 <a class="code" href="classdtn_1_1APIClient.html#98a37692381356296c960cd1713ab9e8">total_sent_</a> += msglen; <a name="l00450"></a>00450 <a name="l00451"></a>00451 <span class="keywordflow">return</span> 0; <a name="l00452"></a>00452 } <a name="l00453"></a>00453 <a name="l00454"></a>00454 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00455"></a>00455 <span class="keywordtype">bool</span> <a name="l00456"></a><a class="code" href="classdtn_1_1APIClient.html#02902ee6c5e3a406c7c579ed21bcf205">00456</a> <a class="code" href="classdtn_1_1APIClient.html#02902ee6c5e3a406c7c579ed21bcf205">APIClient::is_bound</a>(u_int32_t <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a>) <a name="l00457"></a>00457 { <a name="l00458"></a>00458 APIRegistrationList::iterator iter; <a name="l00459"></a>00459 <span class="keywordflow">for</span> (iter = <a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>->begin(); iter != <a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>->end(); ++iter) { <a name="l00460"></a>00460 <span class="keywordflow">if</span> ((*iter)->regid() == regid) { <a name="l00461"></a>00461 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00462"></a>00462 } <a name="l00463"></a>00463 } <a name="l00464"></a>00464 <a name="l00465"></a>00465 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00466"></a>00466 } <a name="l00467"></a>00467 <a name="l00468"></a>00468 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00469"></a>00469 <span class="keywordtype">int</span> <a name="l00470"></a><a class="code" href="classdtn_1_1APIClient.html#84d763e96acc0b07d425f4cf003ba257">00470</a> <a class="code" href="classdtn_1_1APIClient.html#84d763e96acc0b07d425f4cf003ba257">APIClient::handle_local_eid</a>() <a name="l00471"></a>00471 { <a name="l00472"></a>00472 <a class="code" href="structdtn__service__tag__t.html" title="Specification of a service tag used in building a local endpoint identifier.">dtn_service_tag_t</a> service_tag; <a name="l00473"></a>00473 <a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a> local_eid; <a name="l00474"></a>00474 <a name="l00475"></a>00475 <span class="comment">// unpack the request</span> <a name="l00476"></a>00476 <span class="keywordflow">if</span> (!<a class="code" href="dtn__types_8h.html#9797727a4d9f870dfd962cd25d1a84de">xdr_dtn_service_tag_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#ace73b2d7a0e5c748ee9c1bf741c5b41">xdr_decode_</a>, &service_tag)) <a name="l00477"></a>00477 { <a name="l00478"></a>00478 log_err(<span class="stringliteral">"error in xdr unpacking arguments"</span>); <a name="l00479"></a>00479 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#2121e3f0d822e257e8d2e843a3524ef0">DTN_EXDR</a>; <a name="l00480"></a>00480 } <a name="l00481"></a>00481 <a name="l00482"></a>00482 <span class="comment">// build up the response</span> <a name="l00483"></a>00483 <a class="code" href="classdtn_1_1EndpointID.html">EndpointID</a> eid(BundleDaemon::instance()->local_eid()); <a name="l00484"></a>00484 <span class="keywordflow">if</span> (eid.<a class="code" href="classdtn_1_1EndpointID.html#41d5be95b3068c4c2fa7a4b28f18ee8a" title="Append the specified service tag (in a scheme-specific manner) to the ssp.">append_service_tag</a>(service_tag.<a class="code" href="structdtn__service__tag__t.html#63652556ffb523aed8804d87fa99eb58">tag</a>) == <span class="keyword">false</span>) { <a name="l00485"></a>00485 log_err(<span class="stringliteral">"error appending service tag"</span>); <a name="l00486"></a>00486 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l00487"></a>00487 } <a name="l00488"></a>00488 <a name="l00489"></a>00489 memset(&local_eid, 0, <span class="keyword">sizeof</span>(local_eid)); <a name="l00490"></a>00490 eid.<a class="code" href="classdtn_1_1EndpointID.html#618dc017f7a791f7aa64b5be6cb002f8" title="Copy the endpoint id contents out to the API type dtn_endpoint_id_t.">copyto</a>(&local_eid); <a name="l00491"></a>00491 <a name="l00492"></a>00492 <span class="comment">// pack the response</span> <a name="l00493"></a>00493 <span class="keywordflow">if</span> (!<a class="code" href="dtn__types_8h.html#16c5a6f4fcdc988f54f034bb1961b342">xdr_dtn_endpoint_id_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#913a8a0ef9793ca0ad9742be58aaa5e9">xdr_encode_</a>, &local_eid)) { <a name="l00494"></a>00494 log_err(<span class="stringliteral">"internal error in xdr: xdr_dtn_endpoint_id_t"</span>); <a name="l00495"></a>00495 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#2121e3f0d822e257e8d2e843a3524ef0">DTN_EXDR</a>; <a name="l00496"></a>00496 } <a name="l00497"></a>00497 <a name="l00498"></a>00498 log_debug(<span class="stringliteral">"get_local_eid encoded %d byte response"</span>, <a name="l00499"></a>00499 xdr_getpos(&<a class="code" href="classdtn_1_1APIClient.html#913a8a0ef9793ca0ad9742be58aaa5e9">xdr_encode_</a>)); <a name="l00500"></a>00500 <a name="l00501"></a>00501 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>; <a name="l00502"></a>00502 } <a name="l00503"></a>00503 <a name="l00504"></a>00504 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00505"></a>00505 <span class="keywordtype">int</span> <a name="l00506"></a><a class="code" href="classdtn_1_1APIClient.html#56bb3d82073d910564ece376b710fee4">00506</a> <a class="code" href="classdtn_1_1APIClient.html#56bb3d82073d910564ece376b710fee4">APIClient::handle_register</a>() <a name="l00507"></a>00507 { <a name="l00508"></a>00508 <a class="code" href="classdtn_1_1APIRegistration.html" title="Registration class to represent an actual attached application over the client api...">APIRegistration</a>* reg; <a name="l00509"></a>00509 <a class="code" href="classdtn_1_1Registration.html#7f4eb0e60d645c02fb6f7738de198cee" title="Type enumerating the option requested by the registration for how to handle bundles...">Registration::failure_action_t</a> action; <a name="l00510"></a>00510 <a class="code" href="classdtn_1_1EndpointIDPattern.html" title="A Distinct class for endpoint patterns (i.e.">EndpointIDPattern</a> <a class="code" href="dtnperf-server_8c.html#6d2d1c31529bee906473fcabaffff34f">endpoint</a>; <a name="l00511"></a>00511 std::string script; <a name="l00512"></a>00512 <a name="l00513"></a>00513 <a class="code" href="structdtn__reg__info__t.html" title="Registration state.">dtn_reg_info_t</a> reginfo; <a name="l00514"></a>00514 <a name="l00515"></a>00515 memset(&reginfo, 0, <span class="keyword">sizeof</span>(reginfo)); <a name="l00516"></a>00516 <a name="l00517"></a>00517 <span class="comment">// unpack and parse the request</span> <a name="l00518"></a>00518 <span class="keywordflow">if</span> (!<a class="code" href="dtn__types_8h.html#b71cd0713a2f102c11345bb032ee09d3">xdr_dtn_reg_info_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#ace73b2d7a0e5c748ee9c1bf741c5b41">xdr_decode_</a>, &reginfo)) <a name="l00519"></a>00519 { <a name="l00520"></a>00520 log_err(<span class="stringliteral">"error in xdr unpacking arguments"</span>); <a name="l00521"></a>00521 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#2121e3f0d822e257e8d2e843a3524ef0">DTN_EXDR</a>; <a name="l00522"></a>00522 } <a name="l00523"></a>00523 <a name="l00524"></a>00524 <span class="comment">// make sure we free any dynamically-allocated bits in the</span> <a name="l00525"></a>00525 <span class="comment">// incoming structure before we exit the proc</span> <a name="l00526"></a>00526 oasys::ScopeXDRFree x((xdrproc_t)<a class="code" href="dtn__types_8h.html#b71cd0713a2f102c11345bb032ee09d3">xdr_dtn_reg_info_t</a>, (<span class="keywordtype">char</span>*)&reginfo); <a name="l00527"></a>00527 <a name="l00528"></a>00528 endpoint.<a class="code" href="classdtn_1_1EndpointID.html#ec39752e4da3107b16ff5da58d2aa5ab" title="Assign this endpoint ID as a copy of the other.">assign</a>(&reginfo.endpoint); <a name="l00529"></a>00529 <a name="l00530"></a>00530 <span class="keywordflow">if</span> (!endpoint.<a class="code" href="classdtn_1_1EndpointID.html#bbf47839fe5cc8cb425af9a257a92ef5">valid</a>()) { <a name="l00531"></a>00531 log_err(<span class="stringliteral">"invalid endpoint id in register: '%s'"</span>, <a name="l00532"></a>00532 reginfo.endpoint.uri); <a name="l00533"></a>00533 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l00534"></a>00534 } <a name="l00535"></a>00535 <a name="l00536"></a>00536 <span class="comment">// registration flags are a bitmask currently containing:</span> <a name="l00537"></a>00537 <span class="comment">//</span> <a name="l00538"></a>00538 <span class="comment">// [unused] [3 bits session flags] [2 bits failure action]</span> <a name="l00539"></a>00539 <a name="l00540"></a>00540 u_int <a class="code" href="dtnrecv_8c.html#54cdad81a486219f61493a49962ad684">failure_action</a> = reginfo.flags & 0x3; <a name="l00541"></a>00541 <span class="keywordflow">switch</span> (failure_action) { <a name="l00542"></a>00542 <span class="keywordflow">case</span> <a class="code" href="dtn__types_8h.html#a6d0071f396dd4ef85f6ad6332e37f00d21fdf39ccc69d6790aec0c70ce5f972">DTN_REG_DEFER</a>: action = <a class="code" href="classdtn_1_1Registration.html#7f4eb0e60d645c02fb6f7738de198cee7d49e789754ae6edd202ca69e1863c0c" title="Spool bundles until requested.">Registration::DEFER</a>; <span class="keywordflow">break</span>; <a name="l00543"></a>00543 <span class="keywordflow">case</span> <a class="code" href="dtn__types_8h.html#a6d0071f396dd4ef85f6ad6332e37f0067a5f773775540e3dbe22a87105d571e">DTN_REG_DROP</a>: action = <a class="code" href="classdtn_1_1Registration.html#7f4eb0e60d645c02fb6f7738de198cee823ba03e506c2eabc59bf5cec8d4d7c4" title="Drop bundles.">Registration::DROP</a>; <span class="keywordflow">break</span>; <a name="l00544"></a>00544 <span class="keywordflow">case</span> <a class="code" href="dtn__types_8h.html#a6d0071f396dd4ef85f6ad6332e37f00f0a80ca0e5203c09e1634a4a791be4bd">DTN_REG_EXEC</a>: action = <a class="code" href="classdtn_1_1Registration.html#7f4eb0e60d645c02fb6f7738de198ceeab6ca7835f129fdc409b2fc31c19a192" title="Execute the specified callback procedure.">Registration::EXEC</a>; <span class="keywordflow">break</span>; <a name="l00545"></a>00545 <span class="keywordflow">default</span>: { <a name="l00546"></a>00546 log_err(<span class="stringliteral">"invalid registration flags 0x%x"</span>, reginfo.flags); <a name="l00547"></a>00547 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l00548"></a>00548 } <a name="l00549"></a>00549 } <a name="l00550"></a>00550 <a name="l00551"></a>00551 <a name="l00552"></a>00552 u_int32_t <a class="code" href="dtncat_8c.html#7508c434c1f2152c7fd03381726d0a2a">session_flags</a> = 0; <a name="l00553"></a>00553 <span class="keywordflow">if</span> (reginfo.flags & <a class="code" href="dtn__types_8h.html#a6d0071f396dd4ef85f6ad6332e37f00739f876353ef5e8cff7b56e4cb8ad8af">DTN_SESSION_CUSTODY</a>) { <a name="l00554"></a>00554 session_flags |= <a class="code" href="classdtn_1_1Session.html#a795473f389a203d6e15058da8d9498c1ccfadd042afba693bbcf1e5980667d9">Session::CUSTODY</a>; <a name="l00555"></a>00555 } <a name="l00556"></a>00556 <span class="keywordflow">if</span> (reginfo.flags & <a class="code" href="dtn__types_8h.html#a6d0071f396dd4ef85f6ad6332e37f003c2e2090965814efabe47f3f2a358e33">DTN_SESSION_SUBSCRIBE</a>) { <a name="l00557"></a>00557 session_flags |= <a class="code" href="classdtn_1_1Session.html#a795473f389a203d6e15058da8d9498cadd5836fef35cca7c207e710e8e13239">Session::SUBSCRIBE</a>; <a name="l00558"></a>00558 } <a name="l00559"></a>00559 <span class="keywordflow">if</span> (reginfo.flags & <a class="code" href="dtn__types_8h.html#a6d0071f396dd4ef85f6ad6332e37f000b1aebf4fb3e0186630c9cd5a702538a">DTN_SESSION_PUBLISH</a>) { <a name="l00560"></a>00560 session_flags |= <a class="code" href="classdtn_1_1Session.html#a795473f389a203d6e15058da8d9498c1978e38ca305c80fe009dd50fe24a3be">Session::PUBLISH</a>; <a name="l00561"></a>00561 } <a name="l00562"></a>00562 <a name="l00563"></a>00563 u_int other_flags = reginfo.flags & ~0x1f; <a name="l00564"></a>00564 <span class="keywordflow">if</span> (other_flags != 0) { <a name="l00565"></a>00565 log_err(<span class="stringliteral">"invalid registration flags 0x%x"</span>, reginfo.flags); <a name="l00566"></a>00566 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l00567"></a>00567 } <a name="l00568"></a>00568 <a name="l00569"></a>00569 <span class="keywordflow">if</span> (action == <a class="code" href="classdtn_1_1Registration.html#7f4eb0e60d645c02fb6f7738de198ceeab6ca7835f129fdc409b2fc31c19a192" title="Execute the specified callback procedure.">Registration::EXEC</a>) { <a name="l00570"></a>00570 script.assign(reginfo.script.script_val, reginfo.script.script_len); <a name="l00571"></a>00571 } <a name="l00572"></a>00572 <a name="l00573"></a>00573 u_int32_t <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a> = <a class="code" href="classdtn_1_1GlobalStore.html#84112e55922524eb85a143be7d5197a0" title="Singleton instance accessor.">GlobalStore::instance</a>()-><a class="code" href="classdtn_1_1GlobalStore.html#0cd22769f4f62af9ef5779f453814d16" title="Get a new unique registration id, updating the running value in the persistent table...">next_regid</a>(); <a name="l00574"></a>00574 reg = <span class="keyword">new</span> <a class="code" href="classdtn_1_1APIRegistration.html" title="Registration class to represent an actual attached application over the client api...">APIRegistration</a>(regid, endpoint, action, session_flags, <a name="l00575"></a>00575 reginfo.expiration, script); <a name="l00576"></a>00576 <a name="l00577"></a>00577 <span class="keywordflow">if</span> (! reginfo.init_passive) { <a name="l00578"></a>00578 <span class="comment">// store the registration in the list for this session</span> <a name="l00579"></a>00579 <a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>->push_back(reg); <a name="l00580"></a>00580 reg-><a class="code" href="classdtn_1_1Registration.html#ab703ed5afcd162fd7295954867a3fba" title="Accessors.">set_active</a>(<span class="keyword">true</span>); <a name="l00581"></a>00581 } <a name="l00582"></a>00582 <a name="l00583"></a>00583 <span class="keywordflow">if</span> (session_flags & <a class="code" href="classdtn_1_1Session.html#a795473f389a203d6e15058da8d9498c1ccfadd042afba693bbcf1e5980667d9">Session::CUSTODY</a>) { <a name="l00584"></a>00584 <a class="code" href="classdtn_1_1APIClient.html#5448e687c48be53a1df5d5246b0f7e3f">sessions_</a>->push_back(reg); <a name="l00585"></a>00585 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(reg-><a class="code" href="classdtn_1_1APIRegistration.html#dd7acdd55f2afbe277a26258195dc0a2" title="Accessor for notification of session subscribers / unsubscribers (currently just...">session_notify_list</a>() != NULL); <a name="l00586"></a>00586 } <a name="l00587"></a>00587 <a name="l00588"></a>00588 <a class="code" href="classdtn_1_1BundleDaemon.html#bb88ebba32e4e95a96ee76b3f91d9052" title="Post the given event and wait for it to be processed by the daemon thread or for...">BundleDaemon::post_and_wait</a>(<span class="keyword">new</span> <a class="code" href="classdtn_1_1RegistrationAddedEvent.html" title="Event class for new registration arrivals.">RegistrationAddedEvent</a>(reg, <a class="code" href="namespacedtn.html#60ee39c9672604f59fe1b12d4e1d142bf3e56dfb4e624d4f62d7099b60472072" title="a local application">EVENTSRC_APP</a>), <a name="l00589"></a>00589 &<a class="code" href="classdtn_1_1APIClient.html#0a59d9aaa708622f03224ba11e27c43f">notifier_</a>); <a name="l00590"></a>00590 <a name="l00591"></a>00591 <span class="comment">// fill the response with the new registration id</span> <a name="l00592"></a>00592 <span class="keywordflow">if</span> (!<a class="code" href="dtn__types_8h.html#9fa23bbd89d3ddf6df49a4fae6ebf28e">xdr_dtn_reg_id_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#913a8a0ef9793ca0ad9742be58aaa5e9">xdr_encode_</a>, &regid)) { <a name="l00593"></a>00593 log_err(<span class="stringliteral">"internal error in xdr: xdr_dtn_reg_id_t"</span>); <a name="l00594"></a>00594 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#2121e3f0d822e257e8d2e843a3524ef0">DTN_EXDR</a>; <a name="l00595"></a>00595 } <a name="l00596"></a>00596 <a name="l00597"></a>00597 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>; <a name="l00598"></a>00598 } <a name="l00599"></a>00599 <a name="l00600"></a>00600 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00601"></a>00601 <span class="keywordtype">int</span> <a name="l00602"></a><a class="code" href="classdtn_1_1APIClient.html#3ace90f9a37789ba35368c9f2f7d5489">00602</a> <a class="code" href="classdtn_1_1APIClient.html#3ace90f9a37789ba35368c9f2f7d5489">APIClient::handle_unregister</a>() <a name="l00603"></a>00603 { <a name="l00604"></a>00604 <a class="code" href="classdtn_1_1Registration.html" title="Class used to represent an &quot;application&quot; registration, loosely defined...">Registration</a>* reg; <a name="l00605"></a>00605 <a class="code" href="dtn__types_8h.html#d9378ff6ab7ee699568e037a8105f9b6" title="A registration cookie.">dtn_reg_id_t</a> <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a>; <a name="l00606"></a>00606 <a name="l00607"></a>00607 <span class="comment">// unpack and parse the request</span> <a name="l00608"></a>00608 <span class="keywordflow">if</span> (!<a class="code" href="dtn__types_8h.html#9fa23bbd89d3ddf6df49a4fae6ebf28e">xdr_dtn_reg_id_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#ace73b2d7a0e5c748ee9c1bf741c5b41">xdr_decode_</a>, &regid)) <a name="l00609"></a>00609 { <a name="l00610"></a>00610 log_err(<span class="stringliteral">"error in xdr unpacking arguments"</span>); <a name="l00611"></a>00611 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#2121e3f0d822e257e8d2e843a3524ef0">DTN_EXDR</a>; <a name="l00612"></a>00612 } <a name="l00613"></a>00613 <a name="l00614"></a>00614 reg = BundleDaemon::instance()->reg_table()->get(regid); <a name="l00615"></a>00615 <span class="keywordflow">if</span> (reg == NULL) { <a name="l00616"></a>00616 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#58a067b3ff3eba74fc55d6d7e7866d5a">DTN_ENOTFOUND</a>; <a name="l00617"></a>00617 } <a name="l00618"></a>00618 <a name="l00619"></a>00619 <span class="comment">// handle the special case in which we're unregistering a</span> <a name="l00620"></a>00620 <span class="comment">// currently bound registration, in which we actually leave it</span> <a name="l00621"></a>00621 <span class="comment">// around in the expired state, soit will be cleaned up when the</span> <a name="l00622"></a>00622 <span class="comment">// application either calls dtn_unbind() or closes the api socket</span> <a name="l00623"></a>00623 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1APIClient.html#02902ee6c5e3a406c7c579ed21bcf205">is_bound</a>(reg-><a class="code" href="classdtn_1_1Registration.html#d1cd25dd8e4c512591849f44e7c8090b" title="Accessors.">regid</a>()) && reg-><a class="code" href="classdtn_1_1Registration.html#76d7e69abd93971f58ef49eee4b9abfc" title="Accessors.">active</a>()) { <a name="l00624"></a>00624 <span class="keywordflow">if</span> (reg-><a class="code" href="classdtn_1_1Registration.html#8222b37765e97aa6447469668c992b42" title="Accessors.">expired</a>()) { <a name="l00625"></a>00625 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l00626"></a>00626 } <a name="l00627"></a>00627 <a name="l00628"></a>00628 reg-><a class="code" href="classdtn_1_1Registration.html#2dfc54d1c5139cfde1f4ea714ae8e036" title="Force the registration to expire immediately.">force_expire</a>(); <a name="l00629"></a>00629 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(reg-><a class="code" href="classdtn_1_1Registration.html#8222b37765e97aa6447469668c992b42" title="Accessors.">expired</a>()); <a name="l00630"></a>00630 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>; <a name="l00631"></a>00631 } <a name="l00632"></a>00632 <a name="l00633"></a>00633 <span class="comment">// otherwise it's an error to call unregister on a registration</span> <a name="l00634"></a>00634 <span class="comment">// that's in-use by someone else</span> <a name="l00635"></a>00635 <span class="keywordflow">if</span> (reg-><a class="code" href="classdtn_1_1Registration.html#76d7e69abd93971f58ef49eee4b9abfc" title="Accessors.">active</a>()) { <a name="l00636"></a>00636 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#a76777ac1a395f962da37788ced6fc47">DTN_EBUSY</a>; <a name="l00637"></a>00637 } <a name="l00638"></a>00638 <a name="l00639"></a>00639 <a class="code" href="classdtn_1_1BundleDaemon.html#bb88ebba32e4e95a96ee76b3f91d9052" title="Post the given event and wait for it to be processed by the daemon thread or for...">BundleDaemon::post_and_wait</a>(<span class="keyword">new</span> <a class="code" href="classdtn_1_1RegistrationRemovedEvent.html" title="Event class for registration removals.">RegistrationRemovedEvent</a>(reg), <a name="l00640"></a>00640 &<a class="code" href="classdtn_1_1APIClient.html#0a59d9aaa708622f03224ba11e27c43f">notifier_</a>); <a name="l00641"></a>00641 <a name="l00642"></a>00642 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>; <a name="l00643"></a>00643 } <a name="l00644"></a>00644 <a name="l00645"></a>00645 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00646"></a>00646 <span class="keywordtype">int</span> <a name="l00647"></a><a class="code" href="classdtn_1_1APIClient.html#262746ba8158df642ab53a2083c51e77">00647</a> <a class="code" href="classdtn_1_1APIClient.html#262746ba8158df642ab53a2083c51e77">APIClient::handle_find_registration</a>() <a name="l00648"></a>00648 { <a name="l00649"></a>00649 <a class="code" href="classdtn_1_1Registration.html" title="Class used to represent an &quot;application&quot; registration, loosely defined...">Registration</a>* reg; <a name="l00650"></a>00650 <a class="code" href="classdtn_1_1EndpointIDPattern.html" title="A Distinct class for endpoint patterns (i.e.">EndpointIDPattern</a> <a class="code" href="dtnperf-server_8c.html#6d2d1c31529bee906473fcabaffff34f">endpoint</a>; <a name="l00651"></a>00651 <a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a> app_eid; <a name="l00652"></a>00652 <a name="l00653"></a>00653 <span class="comment">// unpack and parse the request</span> <a name="l00654"></a>00654 <span class="keywordflow">if</span> (!<a class="code" href="dtn__types_8h.html#16c5a6f4fcdc988f54f034bb1961b342">xdr_dtn_endpoint_id_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#ace73b2d7a0e5c748ee9c1bf741c5b41">xdr_decode_</a>, &app_eid)) <a name="l00655"></a>00655 { <a name="l00656"></a>00656 log_err(<span class="stringliteral">"error in xdr unpacking arguments"</span>); <a name="l00657"></a>00657 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#2121e3f0d822e257e8d2e843a3524ef0">DTN_EXDR</a>; <a name="l00658"></a>00658 } <a name="l00659"></a>00659 <a name="l00660"></a>00660 endpoint.<a class="code" href="classdtn_1_1EndpointID.html#ec39752e4da3107b16ff5da58d2aa5ab" title="Assign this endpoint ID as a copy of the other.">assign</a>(&app_eid); <a name="l00661"></a>00661 <span class="keywordflow">if</span> (!endpoint.<a class="code" href="classdtn_1_1EndpointID.html#bbf47839fe5cc8cb425af9a257a92ef5">valid</a>()) { <a name="l00662"></a>00662 log_err(<span class="stringliteral">"invalid endpoint id in find_registration: '%s'"</span>, <a name="l00663"></a>00663 app_eid.<a class="code" href="structdtn__endpoint__id__t.html#d2e7d5788ae778c77b4041f1f8b1dc80">uri</a>); <a name="l00664"></a>00664 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l00665"></a>00665 } <a name="l00666"></a>00666 <a name="l00667"></a>00667 reg = BundleDaemon::instance()->reg_table()->get(endpoint); <a name="l00668"></a>00668 <span class="keywordflow">if</span> (reg == NULL) { <a name="l00669"></a>00669 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#58a067b3ff3eba74fc55d6d7e7866d5a">DTN_ENOTFOUND</a>; <a name="l00670"></a>00670 } <a name="l00671"></a>00671 <a name="l00672"></a>00672 u_int32_t <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a> = reg-><a class="code" href="classdtn_1_1Registration.html#d1cd25dd8e4c512591849f44e7c8090b" title="Accessors.">regid</a>(); <a name="l00673"></a>00673 <a name="l00674"></a>00674 <span class="comment">// fill the response with the new registration id</span> <a name="l00675"></a>00675 <span class="keywordflow">if</span> (!<a class="code" href="dtn__types_8h.html#9fa23bbd89d3ddf6df49a4fae6ebf28e">xdr_dtn_reg_id_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#913a8a0ef9793ca0ad9742be58aaa5e9">xdr_encode_</a>, &regid)) { <a name="l00676"></a>00676 log_err(<span class="stringliteral">"internal error in xdr: xdr_dtn_reg_id_t"</span>); <a name="l00677"></a>00677 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#2121e3f0d822e257e8d2e843a3524ef0">DTN_EXDR</a>; <a name="l00678"></a>00678 } <a name="l00679"></a>00679 <a name="l00680"></a>00680 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>; <a name="l00681"></a>00681 } <a name="l00682"></a>00682 <a name="l00683"></a>00683 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00684"></a>00684 <span class="keywordtype">int</span> <a name="l00685"></a><a class="code" href="classdtn_1_1APIClient.html#98e793d1feb9e5254578bdbc357f7489">00685</a> <a class="code" href="classdtn_1_1APIClient.html#98e793d1feb9e5254578bdbc357f7489">APIClient::handle_bind</a>() <a name="l00686"></a>00686 { <a name="l00687"></a>00687 <a class="code" href="dtn__types_8h.html#d9378ff6ab7ee699568e037a8105f9b6" title="A registration cookie.">dtn_reg_id_t</a> <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a>; <a name="l00688"></a>00688 <a name="l00689"></a>00689 <span class="comment">// unpack the request</span> <a name="l00690"></a>00690 <span class="keywordflow">if</span> (!<a class="code" href="dtn__types_8h.html#9fa23bbd89d3ddf6df49a4fae6ebf28e">xdr_dtn_reg_id_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#ace73b2d7a0e5c748ee9c1bf741c5b41">xdr_decode_</a>, &regid)) { <a name="l00691"></a>00691 log_err(<span class="stringliteral">"error in xdr unpacking arguments"</span>); <a name="l00692"></a>00692 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#2121e3f0d822e257e8d2e843a3524ef0">DTN_EXDR</a>; <a name="l00693"></a>00693 } <a name="l00694"></a>00694 <a name="l00695"></a>00695 <span class="comment">// look up the registration</span> <a name="l00696"></a>00696 <span class="keyword">const</span> <a class="code" href="classdtn_1_1RegistrationTable.html" title="Class for the in-memory registration table.">RegistrationTable</a>* regtable = BundleDaemon::instance()->reg_table(); <a name="l00697"></a>00697 <a class="code" href="classdtn_1_1Registration.html" title="Class used to represent an &quot;application&quot; registration, loosely defined...">Registration</a>* reg = regtable-><a class="code" href="classdtn_1_1RegistrationTable.html#f8d5a24ad0b05ab853f80cfea3a1fce1" title="Look up a matching registration.">get</a>(regid); <a name="l00698"></a>00698 <a name="l00699"></a>00699 <span class="keywordflow">if</span> (!reg) { <a name="l00700"></a>00700 log_err(<span class="stringliteral">"can't find registration %d"</span>, regid); <a name="l00701"></a>00701 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#58a067b3ff3eba74fc55d6d7e7866d5a">DTN_ENOTFOUND</a>; <a name="l00702"></a>00702 } <a name="l00703"></a>00703 <a name="l00704"></a>00704 <a class="code" href="classdtn_1_1APIRegistration.html" title="Registration class to represent an actual attached application over the client api...">APIRegistration</a>* api_reg = <span class="keyword">dynamic_cast<</span><a class="code" href="classdtn_1_1APIRegistration.html" title="Registration class to represent an actual attached application over the client api...">APIRegistration</a>*<span class="keyword">></span>(reg); <a name="l00705"></a>00705 <span class="keywordflow">if</span> (api_reg == NULL) { <a name="l00706"></a>00706 log_crit(<span class="stringliteral">"registration %d is not an API registration!!"</span>, <a name="l00707"></a>00707 regid); <a name="l00708"></a>00708 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#58a067b3ff3eba74fc55d6d7e7866d5a">DTN_ENOTFOUND</a>; <a name="l00709"></a>00709 } <a name="l00710"></a>00710 <a name="l00711"></a>00711 <span class="keywordflow">if</span> (api_reg-><a class="code" href="classdtn_1_1Registration.html#76d7e69abd93971f58ef49eee4b9abfc" title="Accessors.">active</a>()) { <a name="l00712"></a>00712 log_err(<span class="stringliteral">"registration %d is already in active mode"</span>, regid); <a name="l00713"></a>00713 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#a76777ac1a395f962da37788ced6fc47">DTN_EBUSY</a>; <a name="l00714"></a>00714 } <a name="l00715"></a>00715 <a name="l00716"></a>00716 <span class="comment">// store the registration in the list for this session</span> <a name="l00717"></a>00717 <a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>->push_back(api_reg); <a name="l00718"></a>00718 api_reg-><a class="code" href="classdtn_1_1Registration.html#ab703ed5afcd162fd7295954867a3fba" title="Accessors.">set_active</a>(<span class="keyword">true</span>); <a name="l00719"></a>00719 <a name="l00720"></a>00720 log_info(<span class="stringliteral">"DTN_BIND: bound to registration %d"</span>, reg-><a class="code" href="classdtn_1_1Registration.html#d1cd25dd8e4c512591849f44e7c8090b" title="Accessors.">regid</a>()); <a name="l00721"></a>00721 <a name="l00722"></a>00722 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>; <a name="l00723"></a>00723 } <a name="l00724"></a>00724 <a name="l00725"></a>00725 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00726"></a>00726 <span class="keywordtype">int</span> <a name="l00727"></a><a class="code" href="classdtn_1_1APIClient.html#fa8cf363d0568517bf082ef60a485938">00727</a> <a class="code" href="classdtn_1_1APIClient.html#fa8cf363d0568517bf082ef60a485938">APIClient::handle_unbind</a>() <a name="l00728"></a>00728 { <a name="l00729"></a>00729 <a class="code" href="dtn__types_8h.html#d9378ff6ab7ee699568e037a8105f9b6" title="A registration cookie.">dtn_reg_id_t</a> <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a>; <a name="l00730"></a>00730 <a name="l00731"></a>00731 <span class="comment">// unpack the request</span> <a name="l00732"></a>00732 <span class="keywordflow">if</span> (!<a class="code" href="dtn__types_8h.html#9fa23bbd89d3ddf6df49a4fae6ebf28e">xdr_dtn_reg_id_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#ace73b2d7a0e5c748ee9c1bf741c5b41">xdr_decode_</a>, &regid)) { <a name="l00733"></a>00733 log_err(<span class="stringliteral">"error in xdr unpacking arguments"</span>); <a name="l00734"></a>00734 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#2121e3f0d822e257e8d2e843a3524ef0">DTN_EXDR</a>; <a name="l00735"></a>00735 } <a name="l00736"></a>00736 <a name="l00737"></a>00737 <span class="comment">// look up the registration</span> <a name="l00738"></a>00738 <span class="keyword">const</span> <a class="code" href="classdtn_1_1RegistrationTable.html" title="Class for the in-memory registration table.">RegistrationTable</a>* regtable = BundleDaemon::instance()->reg_table(); <a name="l00739"></a>00739 <a class="code" href="classdtn_1_1Registration.html" title="Class used to represent an &quot;application&quot; registration, loosely defined...">Registration</a>* reg = regtable-><a class="code" href="classdtn_1_1RegistrationTable.html#f8d5a24ad0b05ab853f80cfea3a1fce1" title="Look up a matching registration.">get</a>(regid); <a name="l00740"></a>00740 <a name="l00741"></a>00741 <span class="keywordflow">if</span> (!reg) { <a name="l00742"></a>00742 log_err(<span class="stringliteral">"can't find registration %d"</span>, regid); <a name="l00743"></a>00743 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#58a067b3ff3eba74fc55d6d7e7866d5a">DTN_ENOTFOUND</a>; <a name="l00744"></a>00744 } <a name="l00745"></a>00745 <a name="l00746"></a>00746 <a class="code" href="classdtn_1_1APIRegistration.html" title="Registration class to represent an actual attached application over the client api...">APIRegistration</a>* api_reg = <span class="keyword">dynamic_cast<</span><a class="code" href="classdtn_1_1APIRegistration.html" title="Registration class to represent an actual attached application over the client api...">APIRegistration</a>*<span class="keyword">></span>(reg); <a name="l00747"></a>00747 <span class="keywordflow">if</span> (api_reg == NULL) { <a name="l00748"></a>00748 log_crit(<span class="stringliteral">"registration %d is not an API registration!!"</span>, <a name="l00749"></a>00749 regid); <a name="l00750"></a>00750 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#58a067b3ff3eba74fc55d6d7e7866d5a">DTN_ENOTFOUND</a>; <a name="l00751"></a>00751 } <a name="l00752"></a>00752 <a name="l00753"></a>00753 APIRegistrationList::iterator iter; <a name="l00754"></a>00754 <span class="keywordflow">for</span> (iter = <a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>->begin(); iter != <a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>->end(); ++iter) { <a name="l00755"></a>00755 <span class="keywordflow">if</span> (*iter == api_reg) { <a name="l00756"></a>00756 <a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>->erase(iter); <a name="l00757"></a>00757 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(api_reg-><a class="code" href="classdtn_1_1Registration.html#76d7e69abd93971f58ef49eee4b9abfc" title="Accessors.">active</a>()); <a name="l00758"></a>00758 api_reg-><a class="code" href="classdtn_1_1Registration.html#ab703ed5afcd162fd7295954867a3fba" title="Accessors.">set_active</a>(<span class="keyword">false</span>); <a name="l00759"></a>00759 <a name="l00760"></a>00760 <span class="keywordflow">if</span> (reg-><a class="code" href="classdtn_1_1Registration.html#8222b37765e97aa6447469668c992b42" title="Accessors.">expired</a>()) { <a name="l00761"></a>00761 log_debug(<span class="stringliteral">"removing expired registration %d"</span>, reg-><a class="code" href="classdtn_1_1Registration.html#d1cd25dd8e4c512591849f44e7c8090b" title="Accessors.">regid</a>()); <a name="l00762"></a>00762 <a class="code" href="classdtn_1_1BundleDaemon.html#370a80f7dd9fd9297e76d7f830d737a8" title="Queues the event at the tail of the queue for processing by the daemon thread.">BundleDaemon::post</a>(<span class="keyword">new</span> <a class="code" href="classdtn_1_1RegistrationExpiredEvent.html" title="Event class for registration expiration.">RegistrationExpiredEvent</a>(reg)); <a name="l00763"></a>00763 } <a name="l00764"></a>00764 <a name="l00765"></a>00765 log_info(<span class="stringliteral">"DTN_UNBIND: unbound from registration %d"</span>, regid); <a name="l00766"></a>00766 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>; <a name="l00767"></a>00767 } <a name="l00768"></a>00768 } <a name="l00769"></a>00769 <a name="l00770"></a>00770 log_err(<span class="stringliteral">"registration %d not bound to this api client"</span>, regid); <a name="l00771"></a>00771 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#58a067b3ff3eba74fc55d6d7e7866d5a">DTN_ENOTFOUND</a>; <a name="l00772"></a>00772 } <a name="l00773"></a>00773 <a name="l00774"></a>00774 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00775"></a>00775 <span class="keywordtype">int</span> <a name="l00776"></a><a class="code" href="classdtn_1_1APIClient.html#6961c3dcfe571414d3da893554ec7176">00776</a> <a class="code" href="classdtn_1_1APIClient.html#6961c3dcfe571414d3da893554ec7176">APIClient::handle_send</a>() <a name="l00777"></a>00777 { <a name="l00778"></a>00778 <a class="code" href="dtn__types_8h.html#d9378ff6ab7ee699568e037a8105f9b6" title="A registration cookie.">dtn_reg_id_t</a> <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a>; <a name="l00779"></a>00779 <a class="code" href="structdtn__bundle__spec__t.html" title="Bundle metadata.">dtn_bundle_spec_t</a> spec; <a name="l00780"></a>00780 <a class="code" href="structdtn__bundle__payload__t.html">dtn_bundle_payload_t</a> payload; <a name="l00781"></a>00781 <a name="l00782"></a>00782 memset(&spec, 0, <span class="keyword">sizeof</span>(spec)); <a name="l00783"></a>00783 memset(&payload, 0, <span class="keyword">sizeof</span>(payload)); <a name="l00784"></a>00784 <a name="l00785"></a>00785 <span class="comment">/* Unpack the arguments */</span> <a name="l00786"></a>00786 <span class="keywordflow">if</span> (!<a class="code" href="dtn__types_8h.html#9fa23bbd89d3ddf6df49a4fae6ebf28e">xdr_dtn_reg_id_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#ace73b2d7a0e5c748ee9c1bf741c5b41">xdr_decode_</a>, &regid) || <a name="l00787"></a>00787 !<a class="code" href="dtn__types_8h.html#54a4fbc50daeb79cc615af82793cbdc8">xdr_dtn_bundle_spec_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#ace73b2d7a0e5c748ee9c1bf741c5b41">xdr_decode_</a>, &spec) || <a name="l00788"></a>00788 !<a class="code" href="dtn__types_8h.html#52d9e9ef1e11bf39693baced9c591d67">xdr_dtn_bundle_payload_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#ace73b2d7a0e5c748ee9c1bf741c5b41">xdr_decode_</a>, &payload)) <a name="l00789"></a>00789 { <a name="l00790"></a>00790 log_err(<span class="stringliteral">"error in xdr unpacking arguments"</span>); <a name="l00791"></a>00791 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#2121e3f0d822e257e8d2e843a3524ef0">DTN_EXDR</a>; <a name="l00792"></a>00792 } <a name="l00793"></a>00793 <a name="l00794"></a>00794 <a class="code" href="namespacedtn.html#87094f3b26b9f1d469e616d311ae57b1" title="Class definition for a Bundle reference.">BundleRef</a> b(<span class="stringliteral">"APIClient::handle_send"</span>); <a name="l00795"></a>00795 b = <span class="keyword">new</span> <a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>(); <a name="l00796"></a>00796 <a name="l00797"></a>00797 <span class="comment">// make sure any xdr calls to malloc are cleaned up</span> <a name="l00798"></a>00798 oasys::ScopeXDRFree f1((xdrproc_t)<a class="code" href="dtn__types_8h.html#54a4fbc50daeb79cc615af82793cbdc8">xdr_dtn_bundle_spec_t</a>, <a name="l00799"></a>00799 (<span class="keywordtype">char</span>*)&spec); <a name="l00800"></a>00800 oasys::ScopeXDRFree f2((xdrproc_t)<a class="code" href="dtn__types_8h.html#52d9e9ef1e11bf39693baced9c591d67">xdr_dtn_bundle_payload_t</a>, <a name="l00801"></a>00801 (<span class="keywordtype">char</span>*)&payload); <a name="l00802"></a>00802 <a name="l00803"></a>00803 <span class="comment">// assign the addressing fields...</span> <a name="l00804"></a>00804 <a name="l00805"></a>00805 <span class="comment">// source and destination are always specified</span> <a name="l00806"></a>00806 b->mutable_source()->assign(&spec.source); <a name="l00807"></a>00807 b->mutable_dest()->assign(&spec.dest); <a name="l00808"></a>00808 <a name="l00809"></a>00809 <span class="comment">// replyto defaults to null</span> <a name="l00810"></a>00810 <span class="keywordflow">if</span> (spec.replyto.uri[0] == <span class="charliteral">'\0'</span>) { <a name="l00811"></a>00811 b->mutable_replyto()->assign(<a class="code" href="classdtn_1_1EndpointID.html#31bd1844cae5e71cc2393a139c9bec4c" title="Return the special endpoint id used for the null endpoint, namely &quot;dtn:none&quot;...">EndpointID::NULL_EID</a>()); <a name="l00812"></a>00812 } <span class="keywordflow">else</span> { <a name="l00813"></a>00813 b->mutable_replyto()->assign(&spec.replyto); <a name="l00814"></a>00814 } <a name="l00815"></a>00815 <a name="l00816"></a>00816 <span class="comment">// custodian is always null</span> <a name="l00817"></a>00817 b->mutable_custodian()->assign(<a class="code" href="classdtn_1_1EndpointID.html#31bd1844cae5e71cc2393a139c9bec4c" title="Return the special endpoint id used for the null endpoint, namely &quot;dtn:none&quot;...">EndpointID::NULL_EID</a>()); <a name="l00818"></a>00818 <a name="l00819"></a>00819 <span class="comment">// set the is_singleton bit, first checking if the application</span> <a name="l00820"></a>00820 <span class="comment">// specified a value, then seeing if the scheme is known and can</span> <a name="l00821"></a>00821 <span class="comment">// therefore determine for itself, and finally, checking the</span> <a name="l00822"></a>00822 <span class="comment">// global default</span> <a name="l00823"></a>00823 <span class="keywordflow">if</span> (spec.dopts & <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f00042ca1f06713b276573b676f296c7c7de">DOPTS_SINGLETON_DEST</a>) <a name="l00824"></a>00824 { <a name="l00825"></a>00825 b->set_singleton_dest(<span class="keyword">true</span>); <a name="l00826"></a>00826 } <a name="l00827"></a>00827 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (spec.dopts & <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f0009f7df92dc460cb5dbf1e59a342ce0be7">DOPTS_MULTINODE_DEST</a>) <a name="l00828"></a>00828 { <a name="l00829"></a>00829 b->set_singleton_dest(<span class="keyword">false</span>); <a name="l00830"></a>00830 } <a name="l00831"></a>00831 <span class="keywordflow">else</span> <a name="l00832"></a>00832 { <a name="l00833"></a>00833 <a class="code" href="classdtn_1_1EndpointID.html#43d537f639ac64ca9b401701dae46f28" title="Typedef for the return value possibilities from is_singleton.">EndpointID::singleton_info_t</a> <a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>; <a name="l00834"></a>00834 <a name="l00835"></a>00835 <span class="keywordflow">if</span> (b->dest().known_scheme()) { <a name="l00836"></a>00836 info = b->dest().is_singleton(); <a name="l00837"></a>00837 <a name="l00838"></a>00838 <span class="comment">// all schemes must make a decision one way or the other</span> <a name="l00839"></a>00839 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(info != <a class="code" href="classdtn_1_1EndpointID.html#43d537f639ac64ca9b401701dae46f2856402133ecae8d16614aafc9f7e8d62d">EndpointID::UNKNOWN</a>); <a name="l00840"></a>00840 } <span class="keywordflow">else</span> { <a name="l00841"></a>00841 info = <a class="code" href="classdtn_1_1EndpointID.html#c94e40b9c0eb93b7dc8d9aed1574ffda" title="Default setting for endpoint ids in unknown schemes.">EndpointID::is_singleton_default_</a>; <a name="l00842"></a>00842 } <a name="l00843"></a>00843 <a name="l00844"></a>00844 <span class="keywordflow">switch</span> (info) { <a name="l00845"></a>00845 <span class="keywordflow">case</span> <a class="code" href="classdtn_1_1EndpointID.html#43d537f639ac64ca9b401701dae46f2856402133ecae8d16614aafc9f7e8d62d">EndpointID::UNKNOWN</a>: <a name="l00846"></a>00846 log_err(<span class="stringliteral">"bundle destination %s in unknown scheme and "</span> <a name="l00847"></a>00847 <span class="stringliteral">"app did not assert singleton/multipoint"</span>, <a name="l00848"></a>00848 b->dest().c_str()); <a name="l00849"></a>00849 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l00850"></a>00850 <a name="l00851"></a>00851 <span class="keywordflow">case</span> <a class="code" href="classdtn_1_1EndpointID.html#43d537f639ac64ca9b401701dae46f287fc9114949151beb443fe5b9b92eac2d">EndpointID::SINGLETON</a>: <a name="l00852"></a>00852 b->set_singleton_dest(<span class="keyword">true</span>); <a name="l00853"></a>00853 <span class="keywordflow">break</span>; <a name="l00854"></a>00854 <a name="l00855"></a>00855 <span class="keywordflow">case</span> <a class="code" href="classdtn_1_1EndpointID.html#43d537f639ac64ca9b401701dae46f28bc86c59b022718d9c03053b5f9600707">EndpointID::MULTINODE</a>: <a name="l00856"></a>00856 b->set_singleton_dest(<span class="keyword">false</span>); <a name="l00857"></a>00857 <span class="keywordflow">break</span>; <a name="l00858"></a>00858 } <a name="l00859"></a>00859 } <a name="l00860"></a>00860 <a name="l00861"></a>00861 <span class="comment">// the priority code</span> <a name="l00862"></a>00862 <span class="keywordflow">switch</span> (spec.priority) { <a name="l00863"></a>00863 <span class="preprocessor">#define COS(_cos) case _cos: b->set_priority(Bundle::_cos); break;</span> <a name="l00864"></a>00864 <span class="preprocessor"></span> <a class="code" href="APIServer_8cc.html#286ea633ad1fab9b26482f79fe8fb364">COS</a>(<a class="code" href="dtn__types_8h.html#993858e35739619750a07d5dc1c275e06779af0a27e4d14a809e52f4810cdddb">COS_BULK</a>); <a name="l00865"></a>00865 <a class="code" href="APIServer_8cc.html#286ea633ad1fab9b26482f79fe8fb364">COS</a>(<a class="code" href="dtn__types_8h.html#993858e35739619750a07d5dc1c275e0f5a0479d0c742791ecd3827d8bf82bfc">COS_NORMAL</a>); <a name="l00866"></a>00866 <a class="code" href="APIServer_8cc.html#286ea633ad1fab9b26482f79fe8fb364">COS</a>(<a class="code" href="dtn__types_8h.html#993858e35739619750a07d5dc1c275e0c926b03ca05898bf8c5d655c29d82935">COS_EXPEDITED</a>); <a name="l00867"></a>00867 <a class="code" href="APIServer_8cc.html#286ea633ad1fab9b26482f79fe8fb364">COS</a>(<a class="code" href="dtn__types_8h.html#993858e35739619750a07d5dc1c275e0019a5adb66c82e1816a9fee6a45939f6">COS_RESERVED</a>); <a name="l00868"></a>00868 <span class="preprocessor">#undef COS</span> <a name="l00869"></a>00869 <span class="preprocessor"></span> <span class="keywordflow">default</span>: <a name="l00870"></a>00870 log_err(<span class="stringliteral">"invalid priority level %d"</span>, (<span class="keywordtype">int</span>)spec.priority); <a name="l00871"></a>00871 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l00872"></a>00872 }; <a name="l00873"></a>00873 <a name="l00874"></a>00874 <span class="comment">// The bundle's source EID must be either dtn:none or an EID</span> <a name="l00875"></a>00875 <span class="comment">// registered at this node so check that now.</span> <a name="l00876"></a>00876 <span class="keyword">const</span> <a class="code" href="classdtn_1_1RegistrationTable.html" title="Class for the in-memory registration table.">RegistrationTable</a>* reg_table = BundleDaemon::instance()->reg_table(); <a name="l00877"></a>00877 <a class="code" href="classdtn_1_1RegistrationList.html" title="Typedef for a list of Registrations.">RegistrationList</a> unused; <a name="l00878"></a>00878 <span class="keywordflow">if</span> (b->source() == <a class="code" href="classdtn_1_1EndpointID.html#31bd1844cae5e71cc2393a139c9bec4c" title="Return the special endpoint id used for the null endpoint, namely &quot;dtn:none&quot;...">EndpointID::NULL_EID</a>()) <a name="l00879"></a>00879 { <a name="l00880"></a>00880 <span class="comment">// Bundles with a null source EID are not allowed to request reports or</span> <a name="l00881"></a>00881 <span class="comment">// custody transfer, and must not be fragmented.</span> <a name="l00882"></a>00882 <span class="keywordflow">if</span> (spec.dopts) { <a name="l00883"></a>00883 log_err(<span class="stringliteral">"bundle with null source EID requested reports and/or "</span> <a name="l00884"></a>00884 <span class="stringliteral">"custody transfer"</span>); <a name="l00885"></a>00885 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l00886"></a>00886 } <a name="l00887"></a>00887 <a name="l00888"></a>00888 b->set_do_not_fragment(<span class="keyword">true</span>); <a name="l00889"></a>00889 } <a name="l00890"></a>00890 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (reg_table-><a class="code" href="classdtn_1_1RegistrationTable.html#334df3b83d924f97cc547f39372380ed" title="Populate the given reglist with all registrations with an endpoint id that matches...">get_matching</a>(b->source(), &unused) != 0) <a name="l00891"></a>00891 { <a name="l00892"></a>00892 <span class="comment">// Local registration -- don't do anything</span> <a name="l00893"></a>00893 } <a name="l00894"></a>00894 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (b->source().subsume(BundleDaemon::instance()->local_eid())) <a name="l00895"></a>00895 { <a name="l00896"></a>00896 <span class="comment">// Allow source EIDs that subsume the local eid</span> <a name="l00897"></a>00897 } <a name="l00898"></a>00898 <span class="keywordflow">else</span> <a name="l00899"></a>00899 { <a name="l00900"></a>00900 log_err(<span class="stringliteral">"this node is not a member of the bundle's source EID (%s)"</span>, <a name="l00901"></a>00901 b->source().str().c_str()); <a name="l00902"></a>00902 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l00903"></a>00903 } <a name="l00904"></a>00904 <a name="l00905"></a>00905 <span class="comment">// Now look up the registration ID passed in to see if the bundle</span> <a name="l00906"></a>00906 <span class="comment">// was sent as part of a session</span> <a name="l00907"></a>00907 <a class="code" href="classdtn_1_1Registration.html" title="Class used to represent an &quot;application&quot; registration, loosely defined...">Registration</a>* reg = reg_table-><a class="code" href="classdtn_1_1RegistrationTable.html#f8d5a24ad0b05ab853f80cfea3a1fce1" title="Look up a matching registration.">get</a>(regid); <a name="l00908"></a>00908 <span class="keywordflow">if</span> (reg && reg-><a class="code" href="classdtn_1_1Registration.html#577ef221608a47ba828daad128c2b263" title="Accessors.">session_flags</a>() != 0) { <a name="l00909"></a>00909 b->mutable_session_eid()->assign(reg-><a class="code" href="classdtn_1_1Registration.html#590e683ae3d0a33456e7f0fa0a2a89d5" title="Accessors.">endpoint</a>().<a class="code" href="classdtn_1_1EndpointID.html#e214dda88bf43a3576cfcdf76c77c5a9">str</a>()); <a name="l00910"></a>00910 } <a name="l00911"></a>00911 <a name="l00912"></a>00912 <span class="comment">// delivery options</span> <a name="l00913"></a>00913 <span class="keywordflow">if</span> (spec.dopts & <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f000cf365df7de1d4ff463456b4adbafaf0c">DOPTS_CUSTODY</a>) <a name="l00914"></a>00914 b->set_custody_requested(<span class="keyword">true</span>); <a name="l00915"></a>00915 <a name="l00916"></a>00916 <span class="keywordflow">if</span> (spec.dopts & <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f000961c42551cde98aaccb2272d32f0a06c">DOPTS_DELIVERY_RCPT</a>) <a name="l00917"></a>00917 b->set_delivery_rcpt(<span class="keyword">true</span>); <a name="l00918"></a>00918 <a name="l00919"></a>00919 <span class="keywordflow">if</span> (spec.dopts & <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f0001240065bb26608579eedd4b022f3397f">DOPTS_RECEIVE_RCPT</a>) <a name="l00920"></a>00920 b->set_receive_rcpt(<span class="keyword">true</span>); <a name="l00921"></a>00921 <a name="l00922"></a>00922 <span class="keywordflow">if</span> (spec.dopts & <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f000f1140b2789c648d104e6ec8a78bc3cea">DOPTS_FORWARD_RCPT</a>) <a name="l00923"></a>00923 b->set_forward_rcpt(<span class="keyword">true</span>); <a name="l00924"></a>00924 <a name="l00925"></a>00925 <span class="keywordflow">if</span> (spec.dopts & <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f000df337d9033e6091548861d7197ea1ae1">DOPTS_CUSTODY_RCPT</a>) <a name="l00926"></a>00926 b->set_custody_rcpt(<span class="keyword">true</span>); <a name="l00927"></a>00927 <a name="l00928"></a>00928 <span class="keywordflow">if</span> (spec.dopts & <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f000649fe8cc9d73bd2d36f2da1f322fa0c2">DOPTS_DELETE_RCPT</a>) <a name="l00929"></a>00929 b->set_deletion_rcpt(<span class="keyword">true</span>); <a name="l00930"></a>00930 <a name="l00931"></a>00931 <span class="keywordflow">if</span> (spec.dopts & <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f000d479de6d9c2a9798ef1c90f1226c691c">DOPTS_DO_NOT_FRAGMENT</a>) <a name="l00932"></a>00932 b->set_do_not_fragment(<span class="keyword">true</span>); <a name="l00933"></a>00933 <a name="l00934"></a>00934 <span class="comment">// expiration time</span> <a name="l00935"></a>00935 b->set_expiration(spec.expiration); <a name="l00936"></a>00936 <a name="l00937"></a>00937 <span class="comment">// sequence id and obsoletes id</span> <a name="l00938"></a>00938 <span class="keywordflow">if</span> (spec.sequence_id.data.data_len != 0) <a name="l00939"></a>00939 { <a name="l00940"></a>00940 std::string str(spec.sequence_id.data.data_val, <a name="l00941"></a>00941 spec.sequence_id.data.data_len); <a name="l00942"></a>00942 <a name="l00943"></a>00943 <span class="keywordtype">bool</span> ok = b->mutable_sequence_id()->parse(str); <a name="l00944"></a>00944 <span class="keywordflow">if</span> (! ok) { <a name="l00945"></a>00945 log_err(<span class="stringliteral">"invalid sequence id '%s'"</span>, str.c_str()); <a name="l00946"></a>00946 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l00947"></a>00947 } <a name="l00948"></a>00948 } <a name="l00949"></a>00949 <a name="l00950"></a>00950 <span class="keywordflow">if</span> (spec.obsoletes_id.data.data_len != 0) <a name="l00951"></a>00951 { <a name="l00952"></a>00952 std::string str(spec.obsoletes_id.data.data_val, <a name="l00953"></a>00953 spec.obsoletes_id.data.data_len); <a name="l00954"></a>00954 <a name="l00955"></a>00955 <span class="keywordtype">bool</span> ok = b->mutable_obsoletes_id()->parse(str); <a name="l00956"></a>00956 <span class="keywordflow">if</span> (! ok) { <a name="l00957"></a>00957 log_err(<span class="stringliteral">"invalid obsoletes id '%s'"</span>, str.c_str()); <a name="l00958"></a>00958 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l00959"></a>00959 } <a name="l00960"></a>00960 } <a name="l00961"></a>00961 <a name="l00962"></a>00962 <span class="comment">// extension blocks</span> <a name="l00963"></a>00963 <span class="keywordflow">for</span> (u_int i = 0; i < spec.blocks.blocks_len; i++) { <a name="l00964"></a>00964 <a class="code" href="structdtn__extension__block__t.html" title="Extension block.">dtn_extension_block_t</a>* block = &spec.blocks.blocks_val[i]; <a name="l00965"></a>00965 <a name="l00966"></a>00966 <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>* <a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a> = <a name="l00967"></a>00967 b->api_blocks()->append_block(APIBlockProcessor::instance()); <a name="l00968"></a>00968 APIBlockProcessor::instance()-> <a name="l00969"></a>00969 init_block(info, b->api_blocks(), <a name="l00970"></a>00970 block-><a class="code" href="structdtn__extension__block__t.html#9ac2b2982467cb09a318b6ddff15c277">type</a>, block-><a class="code" href="structdtn__extension__block__t.html#159ebefbde5821997852b0c0ffdfcf40">flags</a>, <a name="l00971"></a>00971 (u_char*)block-><a class="code" href="structdtn__extension__block__t.html#d8fbf518570b1b1983f4959671bb8a1c">data</a>.<a class="code" href="structdtn__extension__block__t.html#cd95216754ff5f457ae6c66be0e1df98">data_val</a>, <a name="l00972"></a>00972 block-><a class="code" href="structdtn__extension__block__t.html#d8fbf518570b1b1983f4959671bb8a1c">data</a>.<a class="code" href="structdtn__extension__block__t.html#4d068ab3029931cddd110013ae3c8cd3">data_len</a>); <a name="l00973"></a>00973 } <a name="l00974"></a>00974 <a name="l00975"></a>00975 <span class="comment">// metadata blocks</span> <a name="l00976"></a>00976 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i < spec.metadata.metadata_len; ++i) { <a name="l00977"></a>00977 <a class="code" href="structdtn__extension__block__t.html" title="Extension block.">dtn_extension_block_t</a>* block = &spec.metadata.metadata_val[i]; <a name="l00978"></a>00978 <a name="l00979"></a>00979 <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a> null_link(<span class="stringliteral">"APIServer::handle_send"</span>); <a name="l00980"></a>00980 <a class="code" href="classdtn_1_1MetadataVec.html" title="A vector of Metadata Block references.">MetadataVec</a> * vec = b->generated_metadata().find_blocks(null_link); <a name="l00981"></a>00981 <span class="keywordflow">if</span> (vec == NULL) { <a name="l00982"></a>00982 vec = b->mutable_generated_metadata()->create_blocks(null_link); <a name="l00983"></a>00983 } <a name="l00984"></a>00984 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(vec != NULL); <a name="l00985"></a>00985 <a name="l00986"></a>00986 <a class="code" href="classdtn_1_1MetadataBlock.html" title="The representation of a metadata extension block.">MetadataBlock</a> * meta_block = <span class="keyword">new</span> <a class="code" href="classdtn_1_1MetadataBlock.html" title="The representation of a metadata extension block.">MetadataBlock</a>( <a name="l00987"></a>00987 (u_int64_t)block-><a class="code" href="structdtn__extension__block__t.html#9ac2b2982467cb09a318b6ddff15c277">type</a>, <a name="l00988"></a>00988 (u_char *)block-><a class="code" href="structdtn__extension__block__t.html#d8fbf518570b1b1983f4959671bb8a1c">data</a>.<a class="code" href="structdtn__extension__block__t.html#cd95216754ff5f457ae6c66be0e1df98">data_val</a>, <a name="l00989"></a>00989 (u_int32_t)block-><a class="code" href="structdtn__extension__block__t.html#d8fbf518570b1b1983f4959671bb8a1c">data</a>.<a class="code" href="structdtn__extension__block__t.html#4d068ab3029931cddd110013ae3c8cd3">data_len</a>); <a name="l00990"></a>00990 meta_block-><a class="code" href="classdtn_1_1MetadataBlock.html#6653acdff2cce9ff358376646dc41fc4">set_flags</a>((u_int64_t)block-><a class="code" href="structdtn__extension__block__t.html#159ebefbde5821997852b0c0ffdfcf40">flags</a>); <a name="l00991"></a>00991 <a name="l00992"></a>00992 <span class="comment">// XXX/demmer currently this block needs to be stuck on the</span> <a name="l00993"></a>00993 <span class="comment">// outgoing metadata for the null link (so it's transmit to</span> <a name="l00994"></a>00994 <span class="comment">// all destinations) as well as on the recv_metadata vector so</span> <a name="l00995"></a>00995 <span class="comment">// it's conveyed to local applications. this should really be</span> <a name="l00996"></a>00996 <span class="comment">// cleaned up...</span> <a name="l00997"></a>00997 vec-><a class="code" href="classdtn_1_1MetadataVec.html#c07f1f60e7dcdd37fb101886e6b174ab" title="Wrapper around push_back that takes a vanilla MetadataBlock pointer.">push_back</a>(meta_block); <a name="l00998"></a>00998 b->mutable_recv_metadata()->push_back(meta_block); <a name="l00999"></a>00999 } <a name="l01000"></a>01000 <a name="l01001"></a>01001 <span class="comment">// validate the bundle metadata</span> <a name="l01002"></a>01002 oasys::StringBuffer error; <a name="l01003"></a>01003 <span class="keywordflow">if</span> (!b->validate(&error)) { <a name="l01004"></a>01004 log_err(<span class="stringliteral">"bundle validation failed: %s"</span>, error.data()); <a name="l01005"></a>01005 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l01006"></a>01006 } <a name="l01007"></a>01007 <a name="l01008"></a>01008 <span class="comment">// set up the payload, including calculating its length, but don't</span> <a name="l01009"></a>01009 <span class="comment">// copy it in yet</span> <a name="l01010"></a>01010 <span class="keywordtype">size_t</span> payload_len; <a name="l01011"></a>01011 <span class="keywordtype">char</span> <a class="code" href="dtnrecv_8c.html#b49244970ed5ca30989c2dab2129de34">filename</a>[<a class="code" href="dtnrecv_8c.html#e688d728e1acdfe5988c7db45d6f0166">PATH_MAX</a>]; <a name="l01012"></a>01012 <a name="l01013"></a>01013 <span class="keywordflow">switch</span> (payload.location) { <a name="l01014"></a>01014 <span class="keywordflow">case</span> <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7628f773bbfb80857bd5a11f09665fa9b03">DTN_PAYLOAD_MEM</a>: <a name="l01015"></a>01015 payload_len = payload.buf.buf_len; <a name="l01016"></a>01016 <span class="keywordflow">break</span>; <a name="l01017"></a>01017 <a name="l01018"></a>01018 <span class="keywordflow">case</span> <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7621ff9272291ffe7d9f8083e7c5a548909">DTN_PAYLOAD_FILE</a>: <a name="l01019"></a>01019 <span class="keywordflow">case</span> <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7621630b57529624e53a8f257763ad78503">DTN_PAYLOAD_TEMP_FILE</a>: <a name="l01020"></a>01020 <span class="keyword">struct </span>stat finfo; <a name="l01021"></a>01021 sprintf(filename, <span class="stringliteral">"%.*s"</span>, <a name="l01022"></a>01022 (<span class="keywordtype">int</span>)payload.filename.filename_len, <a name="l01023"></a>01023 payload.filename.filename_val); <a name="l01024"></a>01024 <a name="l01025"></a>01025 <span class="keywordflow">if</span> (stat(filename, &finfo) != 0) <a name="l01026"></a>01026 { <a name="l01027"></a>01027 log_err(<span class="stringliteral">"payload file %s does not exist!"</span>, filename); <a name="l01028"></a>01028 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l01029"></a>01029 } <a name="l01030"></a>01030 <a name="l01031"></a>01031 payload_len = finfo.st_size; <a name="l01032"></a>01032 <span class="keywordflow">break</span>; <a name="l01033"></a>01033 <a name="l01034"></a>01034 <span class="keywordflow">default</span>: <a name="l01035"></a>01035 log_err(<span class="stringliteral">"payload.location of %d unknown"</span>, payload.location); <a name="l01036"></a>01036 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l01037"></a>01037 } <a name="l01038"></a>01038 <a name="l01039"></a>01039 b->mutable_payload()->set_length(payload_len); <a name="l01040"></a>01040 <a name="l01041"></a>01041 <span class="comment">// before filling in the payload, we first probe the router to</span> <a name="l01042"></a>01042 <span class="comment">// determine if there's sufficient storage for the bundle</span> <a name="l01043"></a>01043 <span class="keywordtype">bool</span> result; <a name="l01044"></a>01044 <span class="keywordtype">int</span> reason; <a name="l01045"></a>01045 <a class="code" href="classdtn_1_1BundleDaemon.html#bb88ebba32e4e95a96ee76b3f91d9052" title="Post the given event and wait for it to be processed by the daemon thread or for...">BundleDaemon::post_and_wait</a>( <a name="l01046"></a>01046 <span class="keyword">new</span> <a class="code" href="classdtn_1_1BundleAcceptRequest.html" title="Event class to optionally probe if a bundle can be accepted by the system before...">BundleAcceptRequest</a>(b, <a class="code" href="namespacedtn.html#60ee39c9672604f59fe1b12d4e1d142bf3e56dfb4e624d4f62d7099b60472072" title="a local application">EVENTSRC_APP</a>, &result, &reason), <a name="l01047"></a>01047 &<a class="code" href="classdtn_1_1APIClient.html#0a59d9aaa708622f03224ba11e27c43f">notifier_</a>); <a name="l01048"></a>01048 <a name="l01049"></a>01049 <span class="keywordflow">if</span> (!result) { <a name="l01050"></a>01050 log_info(<span class="stringliteral">"DTN_SEND bundle not accepted: reason %s"</span>, <a name="l01051"></a>01051 <a class="code" href="classdtn_1_1BundleStatusReport.html#c01eebd70430ee5eaf44240097a765cf" title="Return a string version of the reason code.">BundleStatusReport::reason_to_str</a>(reason)); <a name="l01052"></a>01052 <a name="l01053"></a>01053 <span class="keywordflow">switch</span> (reason) { <a name="l01054"></a>01054 <span class="keywordflow">case</span> <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f9176e886c084e3e545573e435ef04760c1a">BundleProtocol::REASON_DEPLETED_STORAGE</a>: <a name="l01055"></a>01055 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#03f2f10c4e3ceeaa48f397c0d42b2b1a">DTN_ENOSPACE</a>; <a name="l01056"></a>01056 <span class="keywordflow">default</span>: <a name="l01057"></a>01057 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#951a074861ce082706b57c300413042b">DTN_EINTERNAL</a>; <a name="l01058"></a>01058 } <a name="l01059"></a>01059 } <a name="l01060"></a>01060 <a name="l01061"></a>01061 <span class="keywordflow">switch</span> (payload.location) { <a name="l01062"></a>01062 <span class="keywordflow">case</span> <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7628f773bbfb80857bd5a11f09665fa9b03">DTN_PAYLOAD_MEM</a>: <a name="l01063"></a>01063 b->mutable_payload()->set_data((u_char*)payload.buf.buf_val, <a name="l01064"></a>01064 payload.buf.buf_len); <a name="l01065"></a>01065 <span class="keywordflow">break</span>; <a name="l01066"></a>01066 <a name="l01067"></a>01067 <span class="keywordflow">case</span> <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7621ff9272291ffe7d9f8083e7c5a548909">DTN_PAYLOAD_FILE</a>: <a name="l01068"></a>01068 FILE* file; <a name="l01069"></a>01069 <span class="keywordtype">int</span> r, left; <a name="l01070"></a>01070 u_char buffer[4096]; <a name="l01071"></a>01071 <span class="keywordtype">size_t</span> offset; <a name="l01072"></a>01072 <a name="l01073"></a>01073 <span class="keywordflow">if</span> ((file = fopen(filename, <span class="stringliteral">"r"</span>)) == NULL) <a name="l01074"></a>01074 { <a name="l01075"></a>01075 log_err(<span class="stringliteral">"payload file %s can't be opened: %s"</span>, <a name="l01076"></a>01076 filename, strerror(<a class="code" href="IPDiscovery_8cc.html#d65a8842cc674e3ddf69355898c0ecbf">errno</a>)); <a name="l01077"></a>01077 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l01078"></a>01078 } <a name="l01079"></a>01079 <a name="l01080"></a>01080 left = payload_len; <a name="l01081"></a>01081 r = 0; <a name="l01082"></a>01082 offset = 0; <a name="l01083"></a>01083 <span class="keywordflow">while</span> (left > 0) <a name="l01084"></a>01084 { <a name="l01085"></a>01085 r = fread(buffer, 1, (left>4096)?4096:left, file); <a name="l01086"></a>01086 <a name="l01087"></a>01087 <span class="keywordflow">if</span> (r) <a name="l01088"></a>01088 { <a name="l01089"></a>01089 b->mutable_payload()->write_data(buffer, offset, r); <a name="l01090"></a>01090 left -= r; <a name="l01091"></a>01091 offset += r; <a name="l01092"></a>01092 } <a name="l01093"></a>01093 <span class="keywordflow">else</span> <a name="l01094"></a>01094 { <a name="l01095"></a>01095 sleep(1); <span class="comment">// pause before re-reading</span> <a name="l01096"></a>01096 } <a name="l01097"></a>01097 } <a name="l01098"></a>01098 <a name="l01099"></a>01099 fclose(file); <a name="l01100"></a>01100 <span class="keywordflow">break</span>; <a name="l01101"></a>01101 <a name="l01102"></a>01102 <span class="keywordflow">case</span> <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7621630b57529624e53a8f257763ad78503">DTN_PAYLOAD_TEMP_FILE</a>: <a name="l01103"></a>01103 <span class="keywordflow">if</span> (! b->mutable_payload()->replace_with_file(filename)) { <a name="l01104"></a>01104 log_err(<span class="stringliteral">"payload file %s can't be linked or copied"</span>, <a name="l01105"></a>01105 filename); <a name="l01106"></a>01106 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l01107"></a>01107 } <a name="l01108"></a>01108 <a name="l01109"></a>01109 <span class="keywordflow">if</span> (::unlink(filename) != 0) { <a name="l01110"></a>01110 log_err(<span class="stringliteral">"error unlinking payload temp file: %s"</span>, <a name="l01111"></a>01111 strerror(<a class="code" href="IPDiscovery_8cc.html#d65a8842cc674e3ddf69355898c0ecbf">errno</a>)); <a name="l01112"></a>01112 <span class="comment">// continue on since this is non-fatal</span> <a name="l01113"></a>01113 } <a name="l01114"></a>01114 } <a name="l01115"></a>01115 <a name="l01116"></a>01116 <span class="comment">// before posting the received event, fill in the bundle id struct</span> <a name="l01117"></a>01117 <a class="code" href="structdtn__bundle__id__t.html" title="Type definition for a unique bundle identifier.">dtn_bundle_id_t</a> id; <a name="l01118"></a>01118 memcpy(&<span class="keywordtype">id</span>.source, &spec.source, <span class="keyword">sizeof</span>(<a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a>)); <a name="l01119"></a>01119 <span class="keywordtype">id</span>.creation_ts.secs = b->creation_ts().seconds_; <a name="l01120"></a>01120 <span class="keywordtype">id</span>.creation_ts.seqno = b->creation_ts().seqno_; <a name="l01121"></a>01121 <span class="keywordtype">id</span>.frag_offset = 0; <a name="l01122"></a>01122 <span class="keywordtype">id</span>.orig_length = 0; <a name="l01123"></a>01123 <a name="l01124"></a>01124 log_info(<span class="stringliteral">"DTN_SEND bundle *%p"</span>, b.object()); <a name="l01125"></a>01125 <a name="l01126"></a>01126 <span class="comment">// deliver the bundle</span> <a name="l01127"></a>01127 <span class="comment">// Note: the bundle state may change once it has been posted</span> <a name="l01128"></a>01128 <a class="code" href="classdtn_1_1BundleDaemon.html#bb88ebba32e4e95a96ee76b3f91d9052" title="Post the given event and wait for it to be processed by the daemon thread or for...">BundleDaemon::post_and_wait</a>( <a name="l01129"></a>01129 <span class="keyword">new</span> <a class="code" href="classdtn_1_1BundleReceivedEvent.html" title="Event class for new bundle arrivals.">BundleReceivedEvent</a>(b.object(), <a class="code" href="namespacedtn.html#60ee39c9672604f59fe1b12d4e1d142bf3e56dfb4e624d4f62d7099b60472072" title="a local application">EVENTSRC_APP</a>), <a name="l01130"></a>01130 &<a class="code" href="classdtn_1_1APIClient.html#0a59d9aaa708622f03224ba11e27c43f">notifier_</a>); <a name="l01131"></a>01131 <a name="l01132"></a>01132 <span class="comment">// return the bundle id struct</span> <a name="l01133"></a>01133 <span class="keywordflow">if</span> (!<a class="code" href="dtn__types_8h.html#c51906327f0c0e0571243a5dceffc0af">xdr_dtn_bundle_id_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#913a8a0ef9793ca0ad9742be58aaa5e9">xdr_encode_</a>, &<span class="keywordtype">id</span>)) { <a name="l01134"></a>01134 log_err(<span class="stringliteral">"internal error in xdr: xdr_dtn_bundle_id_t"</span>); <a name="l01135"></a>01135 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#2121e3f0d822e257e8d2e843a3524ef0">DTN_EXDR</a>; <a name="l01136"></a>01136 } <a name="l01137"></a>01137 <a name="l01138"></a>01138 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>; <a name="l01139"></a>01139 } <a name="l01140"></a>01140 <a name="l01141"></a>01141 <span class="comment">//----------------------------------------------------------------------</span> <a name="l01142"></a>01142 <span class="keywordtype">int</span> <a name="l01143"></a><a class="code" href="classdtn_1_1APIClient.html#55108097eb6498f788eebadd3311725f">01143</a> <a class="code" href="classdtn_1_1APIClient.html#55108097eb6498f788eebadd3311725f">APIClient::handle_cancel</a>() <a name="l01144"></a>01144 { <a name="l01145"></a>01145 <a class="code" href="structdtn__bundle__id__t.html" title="Type definition for a unique bundle identifier.">dtn_bundle_id_t</a> id; <a name="l01146"></a>01146 <a name="l01147"></a>01147 memset(&<span class="keywordtype">id</span>, 0, <span class="keyword">sizeof</span>(<span class="keywordtype">id</span>)); <a name="l01148"></a>01148 <a name="l01149"></a>01149 <span class="comment">/* Unpack the arguments */</span> <a name="l01150"></a>01150 <span class="keywordflow">if</span> (!<a class="code" href="dtn__types_8h.html#c51906327f0c0e0571243a5dceffc0af">xdr_dtn_bundle_id_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#ace73b2d7a0e5c748ee9c1bf741c5b41">xdr_decode_</a>, &<span class="keywordtype">id</span>)) <a name="l01151"></a>01151 { <a name="l01152"></a>01152 log_err(<span class="stringliteral">"error in xdr unpacking arguments"</span>); <a name="l01153"></a>01153 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#2121e3f0d822e257e8d2e843a3524ef0">DTN_EXDR</a>; <a name="l01154"></a>01154 } <a name="l01155"></a>01155 <a name="l01156"></a>01156 <a class="code" href="classdtn_1_1GbofId.html" title="Class definition for a GBOF ID (Global Bundle Or Fragment ID).">GbofId</a> gbof_id; <a name="l01157"></a>01157 gbof_id.<a class="code" href="classdtn_1_1GbofId.html#b23fa799884754b7a33a9a021746aede" title="Source eid.">source_</a> = <a class="code" href="classdtn_1_1EndpointID.html">EndpointID</a>( std::string(<span class="keywordtype">id</span>.source.uri) ); <a name="l01158"></a>01158 gbof_id.<a class="code" href="classdtn_1_1GbofId.html#2ec5932b728feb93be48c8cb25f288a1" title="Creation timestamp.">creation_ts_</a>.<a class="code" href="structdtn_1_1BundleTimestamp.html#02c8a347150620243240655bdcd2f42d" title="Seconds since 1/1/2000.">seconds_</a> = <span class="keywordtype">id</span>.creation_ts.secs; <a name="l01159"></a>01159 gbof_id.<a class="code" href="classdtn_1_1GbofId.html#2ec5932b728feb93be48c8cb25f288a1" title="Creation timestamp.">creation_ts_</a>.<a class="code" href="structdtn_1_1BundleTimestamp.html#ebc8cea66862d7f6056da450db410347" title="Sub-second sequence number.">seqno_</a> = <span class="keywordtype">id</span>.creation_ts.seqno; <a name="l01160"></a>01160 gbof_id.<a class="code" href="classdtn_1_1GbofId.html#2d9ffb7531f5c1eee5a54880df3198ab" title="Fragmentary Bundle.">is_fragment_</a> = (<span class="keywordtype">id</span>.orig_length > 0); <a name="l01161"></a>01161 gbof_id.<a class="code" href="classdtn_1_1GbofId.html#5dad8a08de8f01612cfcd571ca46923c" title="Length of original bundle.">frag_length_</a> = <span class="keywordtype">id</span>.orig_length; <a name="l01162"></a>01162 gbof_id.<a class="code" href="classdtn_1_1GbofId.html#14689eb9eb2e00493a4753bcb4f687c7" title="Offset of fragment in original bundle.">frag_offset_</a> = <span class="keywordtype">id</span>.frag_offset; <a name="l01163"></a>01163 <a name="l01164"></a>01164 <a class="code" href="namespacedtn.html#87094f3b26b9f1d469e616d311ae57b1" title="Class definition for a Bundle reference.">BundleRef</a> bundle; <a name="l01165"></a>01165 oasys::ScopeLock pending_lock( <a name="l01166"></a>01166 BundleDaemon::instance()->pending_bundles()->lock(), <span class="stringliteral">"handle_cancel"</span>); <a name="l01167"></a>01167 bundle = BundleDaemon::instance()->pending_bundles()->find(gbof_id); <a name="l01168"></a>01168 <a name="l01169"></a>01169 <span class="keywordflow">if</span> (!bundle.object()) { <a name="l01170"></a>01170 log_warn(<span class="stringliteral">"no bundle matching [%s]; cannot cancel"</span>, <a name="l01171"></a>01171 gbof_id.<a class="code" href="classdtn_1_1GbofId.html#2358b7efa2881e951a3ffd15ef30ff01" title="Returns a string version of the gbof.">str</a>().c_str()); <a name="l01172"></a>01172 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#58a067b3ff3eba74fc55d6d7e7866d5a">DTN_ENOTFOUND</a>; <a name="l01173"></a>01173 } <a name="l01174"></a>01174 <a name="l01175"></a>01175 log_info(<span class="stringliteral">"DTN_CANCEL bundle *%p"</span>, bundle.object()); <a name="l01176"></a>01176 <a name="l01177"></a>01177 <a class="code" href="classdtn_1_1BundleDaemon.html#370a80f7dd9fd9297e76d7f830d737a8" title="Queues the event at the tail of the queue for processing by the daemon thread.">BundleDaemon::post</a>(<span class="keyword">new</span> <a class="code" href="classdtn_1_1BundleCancelRequest.html" title="Event class for canceling a bundle transmission.">BundleCancelRequest</a>(bundle, std::string())); <a name="l01178"></a>01178 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>; <a name="l01179"></a>01179 } <a name="l01180"></a>01180 <a name="l01181"></a>01181 <span class="comment">// Size for temporary memory buffer used when delivering bundles</span> <a name="l01182"></a>01182 <span class="comment">// via files.</span> <a name="l01183"></a><a class="code" href="APIServer_8cc.html#04711a5f2ceb50925b41f3293dbcd794">01183</a> <span class="preprocessor">#define DTN_FILE_DELIVERY_BUF_SIZE 1000</span> <a name="l01184"></a>01184 <span class="preprocessor"></span> <a name="l01185"></a>01185 <span class="comment">//----------------------------------------------------------------------</span> <a name="l01186"></a>01186 <span class="keywordtype">int</span> <a name="l01187"></a><a class="code" href="classdtn_1_1APIClient.html#62bed4eeeb10a011c0dca071d32b1aff">01187</a> <a class="code" href="classdtn_1_1APIClient.html#62bed4eeeb10a011c0dca071d32b1aff">APIClient::handle_recv</a>() <a name="l01188"></a>01188 { <a name="l01189"></a>01189 <a class="code" href="structdtn__bundle__spec__t.html" title="Bundle metadata.">dtn_bundle_spec_t</a> spec; <a name="l01190"></a>01190 <a class="code" href="structdtn__bundle__payload__t.html">dtn_bundle_payload_t</a> payload; <a name="l01191"></a>01191 <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e762" title="The payload of a bundle can be sent or received either in a file, in which case the...">dtn_bundle_payload_location_t</a> location; <a name="l01192"></a>01192 <a class="code" href="structdtn__bundle__status__report__t.html" title="Type definition for a bundle status report.">dtn_bundle_status_report_t</a> status_report; <a name="l01193"></a>01193 <a class="code" href="dtn__types_8h.html#8865a20f2e713bb38e35736e32e1653c" title="DTN timeouts are specified in seconds.">dtn_timeval_t</a> timeout; <a name="l01194"></a>01194 oasys::ScratchBuffer<u_char*> <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>; <a name="l01195"></a>01195 <a class="code" href="classdtn_1_1APIRegistration.html" title="Registration class to represent an actual attached application over the client api...">APIRegistration</a>* reg = NULL; <a name="l01196"></a>01196 <span class="keywordtype">bool</span> sock_ready = <span class="keyword">false</span>; <a name="l01197"></a>01197 oasys::FileIOClient tmpfile; <a name="l01198"></a>01198 <a name="l01199"></a>01199 <span class="comment">// unpack the arguments</span> <a name="l01200"></a>01200 <span class="keywordflow">if</span> ((!<a class="code" href="dtn__types_8h.html#d98f93d0953484b7b74e2bf33aa0d3a7">xdr_dtn_bundle_payload_location_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#ace73b2d7a0e5c748ee9c1bf741c5b41">xdr_decode_</a>, &location)) || <a name="l01201"></a>01201 (!<a class="code" href="dtn__types_8h.html#62ea0edc92ab755946bef6dcfaf1f611">xdr_dtn_timeval_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#ace73b2d7a0e5c748ee9c1bf741c5b41">xdr_decode_</a>, &timeout))) <a name="l01202"></a>01202 { <a name="l01203"></a>01203 log_err(<span class="stringliteral">"error in xdr unpacking arguments"</span>); <a name="l01204"></a>01204 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#2121e3f0d822e257e8d2e843a3524ef0">DTN_EXDR</a>; <a name="l01205"></a>01205 } <a name="l01206"></a>01206 <a name="l01207"></a>01207 <span class="keywordtype">int</span> err = <a class="code" href="classdtn_1_1APIClient.html#684680789390fa8e03f98a0abd5cb518">wait_for_notify</a>(<span class="stringliteral">"recv"</span>, timeout, &reg, NULL, &sock_ready); <a name="l01208"></a>01208 <span class="keywordflow">if</span> (err != 0) { <a name="l01209"></a>01209 <span class="keywordflow">return</span> err; <a name="l01210"></a>01210 } <a name="l01211"></a>01211 <a name="l01212"></a>01212 <span class="comment">// if there's data on the socket, that either means the socket was</span> <a name="l01213"></a>01213 <span class="comment">// closed by an exiting application or the app is violating the</span> <a name="l01214"></a>01214 <span class="comment">// protocol...</span> <a name="l01215"></a>01215 <span class="keywordflow">if</span> (sock_ready) { <a name="l01216"></a>01216 <span class="keywordflow">return</span> <a class="code" href="classdtn_1_1APIClient.html#bfb85bb3e353ab67949514ea0aa72059">handle_unexpected_data</a>(<span class="stringliteral">"handle_recv"</span>); <a name="l01217"></a>01217 } <a name="l01218"></a>01218 <a name="l01219"></a>01219 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(reg != NULL); <a name="l01220"></a>01220 <a name="l01221"></a>01221 <a class="code" href="namespacedtn.html#87094f3b26b9f1d469e616d311ae57b1" title="Class definition for a Bundle reference.">BundleRef</a> bref(<span class="stringliteral">"APIClient::handle_recv"</span>); <a name="l01222"></a>01222 bref = reg-><a class="code" href="classdtn_1_1APIRegistration.html#3aad0d8a4f5603f63cb9f09adc1050e6" title="Accessor for the queue of bundles for the registration.">bundle_list</a>()-><a class="code" href="classdtn_1_1BundleList.html#265a9efd0831be3094f815eed22aec42" title="Remove (and return) a reference to the first bundle on the list.">pop_front</a>(); <a name="l01223"></a>01223 <a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* b = bref.object(); <a name="l01224"></a>01224 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(b != NULL); <a name="l01225"></a>01225 <a name="l01226"></a>01226 log_debug(<span class="stringliteral">"handle_recv: popped *%p for registration %d (timeout %d)"</span>, <a name="l01227"></a>01227 b, reg-><a class="code" href="classdtn_1_1Registration.html#d1cd25dd8e4c512591849f44e7c8090b" title="Accessors.">regid</a>(), timeout); <a name="l01228"></a>01228 <a name="l01229"></a>01229 memset(&spec, 0, <span class="keyword">sizeof</span>(spec)); <a name="l01230"></a>01230 memset(&payload, 0, <span class="keyword">sizeof</span>(payload)); <a name="l01231"></a>01231 memset(&status_report, 0, <span class="keyword">sizeof</span>(status_report)); <a name="l01232"></a>01232 <a name="l01233"></a>01233 <span class="comment">// copyto will malloc string buffer space that needs to be freed</span> <a name="l01234"></a>01234 <span class="comment">// at the end of the fn</span> <a name="l01235"></a>01235 b-><a class="code" href="classdtn_1_1Bundle.html#2dae8a97270a95799acf45d859eaf866" title="Accessors.">source</a>().<a class="code" href="classdtn_1_1EndpointID.html#618dc017f7a791f7aa64b5be6cb002f8" title="Copy the endpoint id contents out to the API type dtn_endpoint_id_t.">copyto</a>(&spec.<a class="code" href="structdtn__bundle__spec__t.html#3e0a3530457d11bea38b06d00dea30fa">source</a>); <a name="l01236"></a>01236 b-><a class="code" href="classdtn_1_1Bundle.html#507241e8ac766e1900009ed6243e2aa3" title="Accessors.">dest</a>().<a class="code" href="classdtn_1_1EndpointID.html#618dc017f7a791f7aa64b5be6cb002f8" title="Copy the endpoint id contents out to the API type dtn_endpoint_id_t.">copyto</a>(&spec.<a class="code" href="structdtn__bundle__spec__t.html#8c2816b3ce9b92489b3b34c325a4cb4c">dest</a>); <a name="l01237"></a>01237 b-><a class="code" href="classdtn_1_1Bundle.html#a2ffacc40d2afe751142e9fd64ab5fdf" title="Accessors.">replyto</a>().<a class="code" href="classdtn_1_1EndpointID.html#618dc017f7a791f7aa64b5be6cb002f8" title="Copy the endpoint id contents out to the API type dtn_endpoint_id_t.">copyto</a>(&spec.<a class="code" href="structdtn__bundle__spec__t.html#f76b43d28b76b155d48df0abe82c6913">replyto</a>); <a name="l01238"></a>01238 <a name="l01239"></a>01239 spec.<a class="code" href="structdtn__bundle__spec__t.html#476482803410f3a19b40cbff91e1e56c">dopts</a> = 0; <a name="l01240"></a>01240 <span class="keywordflow">if</span> (b-><a class="code" href="classdtn_1_1Bundle.html#2261b28c9315c50a85bc35c1bcb6ace4" title="Accessors.">custody_requested</a>()) spec.<a class="code" href="structdtn__bundle__spec__t.html#476482803410f3a19b40cbff91e1e56c">dopts</a> |= <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f000cf365df7de1d4ff463456b4adbafaf0c">DOPTS_CUSTODY</a>; <a name="l01241"></a>01241 if (b-><a class="code" href="classdtn_1_1Bundle.html#a48fd652ab931a694f79cc1c6e47985d" title="Accessors.">delivery_rcpt</a>()) spec.<a class="code" href="structdtn__bundle__spec__t.html#476482803410f3a19b40cbff91e1e56c">dopts</a> |= <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f000961c42551cde98aaccb2272d32f0a06c">DOPTS_DELIVERY_RCPT</a>; <a name="l01242"></a>01242 if (b-><a class="code" href="classdtn_1_1Bundle.html#62e71f87a0f72127045bf18a0284843b" title="Accessors.">receive_rcpt</a>()) spec.<a class="code" href="structdtn__bundle__spec__t.html#476482803410f3a19b40cbff91e1e56c">dopts</a> |= <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f0001240065bb26608579eedd4b022f3397f">DOPTS_RECEIVE_RCPT</a>; <a name="l01243"></a>01243 if (b-><a class="code" href="classdtn_1_1Bundle.html#93c641bdb9a4beda553d8f28e60c99fd" title="Accessors.">forward_rcpt</a>()) spec.<a class="code" href="structdtn__bundle__spec__t.html#476482803410f3a19b40cbff91e1e56c">dopts</a> |= <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f000f1140b2789c648d104e6ec8a78bc3cea">DOPTS_FORWARD_RCPT</a>; <a name="l01244"></a>01244 if (b-><a class="code" href="classdtn_1_1Bundle.html#108fb7cb162dcc1fdcfdad3ca477692d" title="Accessors.">custody_rcpt</a>()) spec.<a class="code" href="structdtn__bundle__spec__t.html#476482803410f3a19b40cbff91e1e56c">dopts</a> |= <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f000df337d9033e6091548861d7197ea1ae1">DOPTS_CUSTODY_RCPT</a>; <a name="l01245"></a>01245 if (b-><a class="code" href="classdtn_1_1Bundle.html#fa1f7ffd4437c3a9213c60e7bbef39d3" title="Accessors.">deletion_rcpt</a>()) spec.<a class="code" href="structdtn__bundle__spec__t.html#476482803410f3a19b40cbff91e1e56c">dopts</a> |= <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f000649fe8cc9d73bd2d36f2da1f322fa0c2">DOPTS_DELETE_RCPT</a>; <a name="l01246"></a>01246 <a name="l01247"></a>01247 spec.<a class="code" href="structdtn__bundle__spec__t.html#57f2d6068db6a5b38a73416ea721e814">expiration</a> = b-><a class="code" href="classdtn_1_1Bundle.html#21879e67b7f065975cbd942807500746" title="Accessors.">expiration</a>(); <a name="l01248"></a>01248 spec.<a class="code" href="structdtn__bundle__spec__t.html#5289539985d68cbbac8ff80d18b0170e">creation_ts</a>.<a class="code" href="structdtn__timestamp__t.html#68d91d87e4f7e4d1c17b68338331609b">secs</a> = b-><a class="code" href="classdtn_1_1Bundle.html#13cd9ab7b010f09562170e2a57242209" title="Accessors.">creation_ts</a>().<a class="code" href="structdtn_1_1BundleTimestamp.html#02c8a347150620243240655bdcd2f42d" title="Seconds since 1/1/2000.">seconds_</a>; <a name="l01249"></a>01249 spec.<a class="code" href="structdtn__bundle__spec__t.html#5289539985d68cbbac8ff80d18b0170e">creation_ts</a>.<a class="code" href="structdtn__timestamp__t.html#406e2588feaa0826c76526e872347fd5">seqno</a> = b-><a class="code" href="classdtn_1_1Bundle.html#13cd9ab7b010f09562170e2a57242209" title="Accessors.">creation_ts</a>().<a class="code" href="structdtn_1_1BundleTimestamp.html#ebc8cea66862d7f6056da450db410347" title="Sub-second sequence number.">seqno_</a>; <a name="l01250"></a>01250 spec.<a class="code" href="structdtn__bundle__spec__t.html#ec17bbdc51eeb06b8097a62369eef9ab">delivery_regid</a> = reg-><a class="code" href="classdtn_1_1Registration.html#d1cd25dd8e4c512591849f44e7c8090b" title="Accessors.">regid</a>(); <a name="l01251"></a>01251 <a name="l01252"></a>01252 <span class="comment">// copy out the sequence id and obsoletes id</span> <a name="l01253"></a>01253 std::string sequence_id_str, obsoletes_id_str; <a name="l01254"></a>01254 <span class="keywordflow">if</span> (! b-><a class="code" href="classdtn_1_1Bundle.html#ce91f55a3fece4d4a562b665a462a5d0" title="Accessors.">sequence_id</a>().<a class="code" href="classdtn_1_1SequenceID.html#41640a4837fab3c5ca5fce05f371bbd2" title="Typedefs and wrappers for the entry vector and iterators.">empty</a>()) { <a name="l01255"></a>01255 sequence_id_str = b-><a class="code" href="classdtn_1_1Bundle.html#ce91f55a3fece4d4a562b665a462a5d0" title="Accessors.">sequence_id</a>().<a class="code" href="classdtn_1_1SequenceID.html#7b9bd398514f902641e1930c60653c37" title="Get a string representation.">to_str</a>(); <a name="l01256"></a>01256 spec.<a class="code" href="structdtn__bundle__spec__t.html#60a24eed29224ad842136b87241108b7">sequence_id</a>.<a class="code" href="structdtn__sequence__id__t.html#bdbb1a6df2afea41dccb74f4ea8bbadc">data</a>.<a class="code" href="structdtn__sequence__id__t.html#aaf2850ca5853b9b1bca2791d16e969a">data_val</a> = <span class="keyword">const_cast<</span><span class="keywordtype">char</span>*<span class="keyword">></span>(sequence_id_str.c_str()); <a name="l01257"></a>01257 spec.<a class="code" href="structdtn__bundle__spec__t.html#60a24eed29224ad842136b87241108b7">sequence_id</a>.<a class="code" href="structdtn__sequence__id__t.html#bdbb1a6df2afea41dccb74f4ea8bbadc">data</a>.<a class="code" href="structdtn__sequence__id__t.html#7ea9c5585efae94220749c79f41080d7">data_len</a> = sequence_id_str.length(); <a name="l01258"></a>01258 } <a name="l01259"></a>01259 <a name="l01260"></a>01260 <span class="keywordflow">if</span> (! b-><a class="code" href="classdtn_1_1Bundle.html#d483159c19f31132c5597de34c9ca409" title="Accessors.">obsoletes_id</a>().<a class="code" href="classdtn_1_1SequenceID.html#41640a4837fab3c5ca5fce05f371bbd2" title="Typedefs and wrappers for the entry vector and iterators.">empty</a>()) { <a name="l01261"></a>01261 obsoletes_id_str = b-><a class="code" href="classdtn_1_1Bundle.html#d483159c19f31132c5597de34c9ca409" title="Accessors.">obsoletes_id</a>().<a class="code" href="classdtn_1_1SequenceID.html#7b9bd398514f902641e1930c60653c37" title="Get a string representation.">to_str</a>(); <a name="l01262"></a>01262 spec.<a class="code" href="structdtn__bundle__spec__t.html#a3239046abcbbb355b8b3d136769078a">obsoletes_id</a>.<a class="code" href="structdtn__sequence__id__t.html#bdbb1a6df2afea41dccb74f4ea8bbadc">data</a>.<a class="code" href="structdtn__sequence__id__t.html#aaf2850ca5853b9b1bca2791d16e969a">data_val</a> = <span class="keyword">const_cast<</span><span class="keywordtype">char</span>*<span class="keyword">></span>(obsoletes_id_str.c_str()); <a name="l01263"></a>01263 spec.<a class="code" href="structdtn__bundle__spec__t.html#a3239046abcbbb355b8b3d136769078a">obsoletes_id</a>.<a class="code" href="structdtn__sequence__id__t.html#bdbb1a6df2afea41dccb74f4ea8bbadc">data</a>.<a class="code" href="structdtn__sequence__id__t.html#7ea9c5585efae94220749c79f41080d7">data_len</a> = obsoletes_id_str.length(); <a name="l01264"></a>01264 } <a name="l01265"></a>01265 <a name="l01266"></a>01266 <span class="comment">// copy extension blocks</span> <a name="l01267"></a>01267 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> blocks_found = 0; <a name="l01268"></a>01268 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> data_len = 0; <a name="l01269"></a>01269 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i < b-><a class="code" href="classdtn_1_1Bundle.html#ec3c2ef7670fb2d34d46ab547bf9fb80" title="Accessors.">recv_blocks</a>().size(); ++i) { <a name="l01270"></a>01270 <span class="keywordflow">if</span> ((b-><a class="code" href="classdtn_1_1Bundle.html#ec3c2ef7670fb2d34d46ab547bf9fb80" title="Accessors.">recv_blocks</a>()[i].type() == <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca753097979cfe600d2c1dfb5cf3629b195" title="INTERNAL ONLY -- NOT IN SPEC.">BundleProtocol::PRIMARY_BLOCK</a>) || <a name="l01271"></a>01271 (b-><a class="code" href="classdtn_1_1Bundle.html#ec3c2ef7670fb2d34d46ab547bf9fb80" title="Accessors.">recv_blocks</a>()[i].type() == <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca711ba3c0a764c41add8e738d757393d60">BundleProtocol::PAYLOAD_BLOCK</a>) || <a name="l01272"></a>01272 (b-><a class="code" href="classdtn_1_1Bundle.html#ec3c2ef7670fb2d34d46ab547bf9fb80" title="Accessors.">recv_blocks</a>()[i].type() == <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca7f69759524468f2b1c3f7f1c2f6619f39" title="NOT IN SPEC YET.">BundleProtocol::METADATA_BLOCK</a>)) { <a name="l01273"></a>01273 <span class="keywordflow">continue</span>; <a name="l01274"></a>01274 } <a name="l01275"></a>01275 blocks_found++; <a name="l01276"></a>01276 data_len += b-><a class="code" href="classdtn_1_1Bundle.html#ec3c2ef7670fb2d34d46ab547bf9fb80" title="Accessors.">recv_blocks</a>()[i].data_length(); <a name="l01277"></a>01277 } <a name="l01278"></a>01278 <a name="l01279"></a>01279 <span class="keywordflow">if</span> (blocks_found > 0) { <a name="l01280"></a>01280 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> buf_len = (blocks_found * <span class="keyword">sizeof</span>(<a class="code" href="structdtn__extension__block__t.html" title="Extension block.">dtn_extension_block_t</a>)) + <a name="l01281"></a>01281 data_len; <a name="l01282"></a>01282 <span class="keywordtype">void</span> * buf = malloc(buf_len); <a name="l01283"></a>01283 memset(buf, 0, buf_len); <a name="l01284"></a>01284 <a name="l01285"></a>01285 <a class="code" href="structdtn__extension__block__t.html" title="Extension block.">dtn_extension_block_t</a> * bp = (<a class="code" href="structdtn__extension__block__t.html" title="Extension block.">dtn_extension_block_t</a> *)buf; <a name="l01286"></a>01286 <span class="keywordtype">char</span> * dp = (<span class="keywordtype">char</span>*)buf + (blocks_found * <span class="keyword">sizeof</span>(<a class="code" href="structdtn__extension__block__t.html" title="Extension block.">dtn_extension_block_t</a>)); <a name="l01287"></a>01287 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i < b-><a class="code" href="classdtn_1_1Bundle.html#ec3c2ef7670fb2d34d46ab547bf9fb80" title="Accessors.">recv_blocks</a>().size(); ++i) { <a name="l01288"></a>01288 <span class="keywordflow">if</span> ((b-><a class="code" href="classdtn_1_1Bundle.html#ec3c2ef7670fb2d34d46ab547bf9fb80" title="Accessors.">recv_blocks</a>()[i].type() == <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca753097979cfe600d2c1dfb5cf3629b195" title="INTERNAL ONLY -- NOT IN SPEC.">BundleProtocol::PRIMARY_BLOCK</a>) || <a name="l01289"></a>01289 (b-><a class="code" href="classdtn_1_1Bundle.html#ec3c2ef7670fb2d34d46ab547bf9fb80" title="Accessors.">recv_blocks</a>()[i].type() == <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca711ba3c0a764c41add8e738d757393d60">BundleProtocol::PAYLOAD_BLOCK</a>) || <a name="l01290"></a>01290 (b-><a class="code" href="classdtn_1_1Bundle.html#ec3c2ef7670fb2d34d46ab547bf9fb80" title="Accessors.">recv_blocks</a>()[i].type() == <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca7f69759524468f2b1c3f7f1c2f6619f39" title="NOT IN SPEC YET.">BundleProtocol::METADATA_BLOCK</a>)) { <a name="l01291"></a>01291 <span class="keywordflow">continue</span>; <a name="l01292"></a>01292 } <a name="l01293"></a>01293 <a name="l01294"></a>01294 bp-><a class="code" href="structdtn__extension__block__t.html#9ac2b2982467cb09a318b6ddff15c277">type</a> = b-><a class="code" href="classdtn_1_1Bundle.html#ec3c2ef7670fb2d34d46ab547bf9fb80" title="Accessors.">recv_blocks</a>()[i].type(); <a name="l01295"></a>01295 bp-><a class="code" href="structdtn__extension__block__t.html#159ebefbde5821997852b0c0ffdfcf40">flags</a> = b-><a class="code" href="classdtn_1_1Bundle.html#ec3c2ef7670fb2d34d46ab547bf9fb80" title="Accessors.">recv_blocks</a>()[i].flags(); <a name="l01296"></a>01296 bp-><a class="code" href="structdtn__extension__block__t.html#d8fbf518570b1b1983f4959671bb8a1c">data</a>.<a class="code" href="structdtn__extension__block__t.html#4d068ab3029931cddd110013ae3c8cd3">data_len</a> = b-><a class="code" href="classdtn_1_1Bundle.html#ec3c2ef7670fb2d34d46ab547bf9fb80" title="Accessors.">recv_blocks</a>()[i].data_length(); <a name="l01297"></a>01297 bp-><a class="code" href="structdtn__extension__block__t.html#d8fbf518570b1b1983f4959671bb8a1c">data</a>.<a class="code" href="structdtn__extension__block__t.html#cd95216754ff5f457ae6c66be0e1df98">data_val</a> = dp; <a name="l01298"></a>01298 memcpy(dp, b-><a class="code" href="classdtn_1_1Bundle.html#ec3c2ef7670fb2d34d46ab547bf9fb80" title="Accessors.">recv_blocks</a>()[i].data(), bp-><a class="code" href="structdtn__extension__block__t.html#d8fbf518570b1b1983f4959671bb8a1c">data</a>.<a class="code" href="structdtn__extension__block__t.html#4d068ab3029931cddd110013ae3c8cd3">data_len</a>); <a name="l01299"></a>01299 <a name="l01300"></a>01300 bp++; <a name="l01301"></a>01301 dp += bp-><a class="code" href="structdtn__extension__block__t.html#d8fbf518570b1b1983f4959671bb8a1c">data</a>.<a class="code" href="structdtn__extension__block__t.html#4d068ab3029931cddd110013ae3c8cd3">data_len</a>; <a name="l01302"></a>01302 } <a name="l01303"></a>01303 <a name="l01304"></a>01304 spec.<a class="code" href="structdtn__bundle__spec__t.html#303dc16abb2318a93f67cf629fac17f9">blocks</a>.<a class="code" href="structdtn__bundle__spec__t.html#c9fecf5ff8b72cca1a31bde62fa53dcf">blocks_len</a> = blocks_found; <a name="l01305"></a>01305 spec.<a class="code" href="structdtn__bundle__spec__t.html#303dc16abb2318a93f67cf629fac17f9">blocks</a>.<a class="code" href="structdtn__bundle__spec__t.html#7165123249010765be66ab32137e88ba">blocks_val</a> = (<a class="code" href="structdtn__extension__block__t.html" title="Extension block.">dtn_extension_block_t</a> *)buf; <a name="l01306"></a>01306 } <a name="l01307"></a>01307 <a name="l01308"></a>01308 <span class="comment">// copy metadata extension blocks</span> <a name="l01309"></a>01309 blocks_found = 0; <a name="l01310"></a>01310 data_len = 0; <a name="l01311"></a>01311 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i < b-><a class="code" href="classdtn_1_1Bundle.html#212b7cf608e211050ca40ec0e6f0259d" title="Accessors.">recv_metadata</a>().size(); ++i) { <a name="l01312"></a>01312 blocks_found++; <a name="l01313"></a>01313 data_len += b-><a class="code" href="classdtn_1_1Bundle.html#212b7cf608e211050ca40ec0e6f0259d" title="Accessors.">recv_metadata</a>()[i]->metadata_len(); <a name="l01314"></a>01314 } <a name="l01315"></a>01315 <a name="l01316"></a>01316 <span class="keywordflow">if</span> (blocks_found > 0) { <a name="l01317"></a>01317 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> buf_len = (blocks_found * <span class="keyword">sizeof</span>(<a class="code" href="structdtn__extension__block__t.html" title="Extension block.">dtn_extension_block_t</a>)) + <a name="l01318"></a>01318 data_len; <a name="l01319"></a>01319 <span class="keywordtype">void</span> * buf = (<span class="keywordtype">char</span> *)malloc(buf_len); <a name="l01320"></a>01320 memset(buf, 0, buf_len); <a name="l01321"></a>01321 <a name="l01322"></a>01322 <a class="code" href="structdtn__extension__block__t.html" title="Extension block.">dtn_extension_block_t</a> * bp = (<a class="code" href="structdtn__extension__block__t.html" title="Extension block.">dtn_extension_block_t</a> *)buf; <a name="l01323"></a>01323 <span class="keywordtype">char</span> * dp = (<span class="keywordtype">char</span>*)buf + (blocks_found * <span class="keyword">sizeof</span>(<a class="code" href="structdtn__extension__block__t.html" title="Extension block.">dtn_extension_block_t</a>)); <a name="l01324"></a>01324 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i < b-><a class="code" href="classdtn_1_1Bundle.html#212b7cf608e211050ca40ec0e6f0259d" title="Accessors.">recv_metadata</a>().size(); ++i) { <a name="l01325"></a>01325 bp-><a class="code" href="structdtn__extension__block__t.html#9ac2b2982467cb09a318b6ddff15c277">type</a> = b-><a class="code" href="classdtn_1_1Bundle.html#212b7cf608e211050ca40ec0e6f0259d" title="Accessors.">recv_metadata</a>()[i]->ontology(); <a name="l01326"></a>01326 bp-><a class="code" href="structdtn__extension__block__t.html#159ebefbde5821997852b0c0ffdfcf40">flags</a> = b-><a class="code" href="classdtn_1_1Bundle.html#212b7cf608e211050ca40ec0e6f0259d" title="Accessors.">recv_metadata</a>()[i]->flags(); <a name="l01327"></a>01327 bp-><a class="code" href="structdtn__extension__block__t.html#d8fbf518570b1b1983f4959671bb8a1c">data</a>.<a class="code" href="structdtn__extension__block__t.html#4d068ab3029931cddd110013ae3c8cd3">data_len</a> = b-><a class="code" href="classdtn_1_1Bundle.html#212b7cf608e211050ca40ec0e6f0259d" title="Accessors.">recv_metadata</a>()[i]->metadata_len(); <a name="l01328"></a>01328 bp-><a class="code" href="structdtn__extension__block__t.html#d8fbf518570b1b1983f4959671bb8a1c">data</a>.<a class="code" href="structdtn__extension__block__t.html#cd95216754ff5f457ae6c66be0e1df98">data_val</a> = dp; <a name="l01329"></a>01329 memcpy(dp, b-><a class="code" href="classdtn_1_1Bundle.html#212b7cf608e211050ca40ec0e6f0259d" title="Accessors.">recv_metadata</a>()[i]->metadata(), bp-><a class="code" href="structdtn__extension__block__t.html#d8fbf518570b1b1983f4959671bb8a1c">data</a>.<a class="code" href="structdtn__extension__block__t.html#4d068ab3029931cddd110013ae3c8cd3">data_len</a>); <a name="l01330"></a>01330 dp += bp-><a class="code" href="structdtn__extension__block__t.html#d8fbf518570b1b1983f4959671bb8a1c">data</a>.<a class="code" href="structdtn__extension__block__t.html#4d068ab3029931cddd110013ae3c8cd3">data_len</a>; <a name="l01331"></a>01331 bp++; <a name="l01332"></a>01332 } <a name="l01333"></a>01333 <a name="l01334"></a>01334 spec.<a class="code" href="structdtn__bundle__spec__t.html#41df879d0110475bea431d3225f508d6">metadata</a>.<a class="code" href="structdtn__bundle__spec__t.html#00bed400e243e63f9c078cffbd296504">metadata_len</a> = blocks_found; <a name="l01335"></a>01335 spec.<a class="code" href="structdtn__bundle__spec__t.html#41df879d0110475bea431d3225f508d6">metadata</a>.<a class="code" href="structdtn__bundle__spec__t.html#803cff6a07a015067a0f0a71958b6068">metadata_val</a> = (<a class="code" href="structdtn__extension__block__t.html" title="Extension block.">dtn_extension_block_t</a> *)buf; <a name="l01336"></a>01336 } <a name="l01337"></a>01337 <a name="l01338"></a>01338 <span class="keywordtype">size_t</span> payload_len = b-><a class="code" href="classdtn_1_1Bundle.html#3bc0b88b547620b4029eba4809a73447" title="Accessors.">payload</a>().<a class="code" href="classdtn_1_1BundlePayload.html#56b3851ad789c4dbf019a32d557b7453" title="The payload length.">length</a>(); <a name="l01339"></a>01339 <a name="l01340"></a>01340 <span class="keywordflow">if</span> (location == <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7628f773bbfb80857bd5a11f09665fa9b03">DTN_PAYLOAD_MEM</a> && payload_len > <a class="code" href="dtn__types_8h.html#35e670e5d1e8d12cc3c644b748fbef31">DTN_MAX_BUNDLE_MEM</a>) <a name="l01341"></a>01341 { <a name="l01342"></a>01342 log_debug(<span class="stringliteral">"app requested memory delivery but payload is too big (%zu bytes)... "</span> <a name="l01343"></a>01343 <span class="stringliteral">"using files instead"</span>, <a name="l01344"></a>01344 payload_len); <a name="l01345"></a>01345 location = <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7621ff9272291ffe7d9f8083e7c5a548909">DTN_PAYLOAD_FILE</a>; <a name="l01346"></a>01346 } <a name="l01347"></a>01347 <a name="l01348"></a>01348 <span class="keywordflow">if</span> (location == <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7628f773bbfb80857bd5a11f09665fa9b03">DTN_PAYLOAD_MEM</a>) { <a name="l01349"></a>01349 <span class="comment">// the app wants the payload in memory</span> <a name="l01350"></a>01350 payload.<a class="code" href="structdtn__bundle__payload__t.html#04e8c46c5b40f187e1fefed80853cc5c">buf</a>.<a class="code" href="structdtn__bundle__payload__t.html#c20a1cf6010dbd5855140373da5ce8c3">buf_len</a> = payload_len; <a name="l01351"></a>01351 <span class="keywordflow">if</span> (payload_len != 0) { <a name="l01352"></a>01352 buf.reserve(payload_len); <a name="l01353"></a>01353 payload.<a class="code" href="structdtn__bundle__payload__t.html#04e8c46c5b40f187e1fefed80853cc5c">buf</a>.<a class="code" href="structdtn__bundle__payload__t.html#45cd21fd96fced99995450f0fca848d5">buf_val</a> = <a name="l01354"></a>01354 (<span class="keywordtype">char</span>*)b-><a class="code" href="classdtn_1_1Bundle.html#3bc0b88b547620b4029eba4809a73447" title="Accessors.">payload</a>().<a class="code" href="classdtn_1_1BundlePayload.html#c4ce25f2d2d7ad54a9306ea2599731b4" title="Copy out a chunk of payload data into the supplied buffer.">read_data</a>(0, payload_len, buf.buf()); <a name="l01355"></a>01355 } <span class="keywordflow">else</span> { <a name="l01356"></a>01356 payload.<a class="code" href="structdtn__bundle__payload__t.html#04e8c46c5b40f187e1fefed80853cc5c">buf</a>.<a class="code" href="structdtn__bundle__payload__t.html#45cd21fd96fced99995450f0fca848d5">buf_val</a> = 0; <a name="l01357"></a>01357 } <a name="l01358"></a>01358 <a name="l01359"></a>01359 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (location == <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7621ff9272291ffe7d9f8083e7c5a548909">DTN_PAYLOAD_FILE</a>) { <a name="l01360"></a>01360 <span class="keywordtype">char</span> *tdir, templ[64]; <a name="l01361"></a>01361 <a name="l01362"></a>01362 tdir = getenv(<span class="stringliteral">"TMP"</span>); <a name="l01363"></a>01363 <span class="keywordflow">if</span> (tdir == NULL) { <a name="l01364"></a>01364 tdir = getenv(<span class="stringliteral">"TEMP"</span>); <a name="l01365"></a>01365 } <a name="l01366"></a>01366 <span class="keywordflow">if</span> (tdir == NULL) { <a name="l01367"></a>01367 tdir = <span class="stringliteral">"/tmp"</span>; <a name="l01368"></a>01368 } <a name="l01369"></a>01369 <a name="l01370"></a>01370 snprintf(templ, <span class="keyword">sizeof</span>(templ), <span class="stringliteral">"%s/bundlePayload_XXXXXX"</span>, tdir); <a name="l01371"></a>01371 <a name="l01372"></a>01372 <span class="keywordflow">if</span> (tmpfile.mkstemp(templ) == -1) { <a name="l01373"></a>01373 log_err(<span class="stringliteral">"can't open temporary file to deliver bundle"</span>); <a name="l01374"></a>01374 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#951a074861ce082706b57c300413042b">DTN_EINTERNAL</a>; <a name="l01375"></a>01375 } <a name="l01376"></a>01376 <a name="l01377"></a>01377 <span class="keywordflow">if</span> (chmod(tmpfile.path(), 0666) < 0) { <a name="l01378"></a>01378 log_warn(<span class="stringliteral">"can't set the permission of temp file to 0666: %s"</span>, <a name="l01379"></a>01379 strerror(<a class="code" href="IPDiscovery_8cc.html#d65a8842cc674e3ddf69355898c0ecbf">errno</a>)); <a name="l01380"></a>01380 } <a name="l01381"></a>01381 <a name="l01382"></a>01382 b-><a class="code" href="classdtn_1_1Bundle.html#3bc0b88b547620b4029eba4809a73447" title="Accessors.">payload</a>().<a class="code" href="classdtn_1_1BundlePayload.html#e7a1d894d64121fc15f7edd8ef85ba0b" title="Copy (or link) the payload to the given file client object.">copy_file</a>(&tmpfile); <a name="l01383"></a>01383 <a name="l01384"></a>01384 payload.<a class="code" href="structdtn__bundle__payload__t.html#f3a33fd2ae2b3b8eae2e675f1a038cec">filename</a>.<a class="code" href="structdtn__bundle__payload__t.html#0d824d13c3225cb59fa2e34623608b2a">filename_val</a> = (<span class="keywordtype">char</span>*)tmpfile.path(); <a name="l01385"></a>01385 payload.<a class="code" href="structdtn__bundle__payload__t.html#f3a33fd2ae2b3b8eae2e675f1a038cec">filename</a>.<a class="code" href="structdtn__bundle__payload__t.html#19a9fb6ab21fdc57d29fbdb0e61d0bbf">filename_len</a> = tmpfile.path_len() + 1; <a name="l01386"></a>01386 tmpfile.close(); <a name="l01387"></a>01387 <a name="l01388"></a>01388 } <span class="keywordflow">else</span> { <a name="l01389"></a>01389 log_err(<span class="stringliteral">"payload location %d not understood"</span>, location); <a name="l01390"></a>01390 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l01391"></a>01391 } <a name="l01392"></a>01392 <a name="l01393"></a>01393 payload.<a class="code" href="structdtn__bundle__payload__t.html#4877c653f99a90c38ae8fdb4a1774247">location</a> = location; <a name="l01394"></a>01394 <a name="l01395"></a>01395 <span class="comment">/*</span> <a name="l01396"></a>01396 <span class="comment"> * If the bundle is a status report, parse it and copy out the</span> <a name="l01397"></a>01397 <span class="comment"> * data into the status report.</span> <a name="l01398"></a>01398 <span class="comment"> */</span> <a name="l01399"></a>01399 <a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html" title="Specification of the contents of a Bundle Status Report.">BundleStatusReport::data_t</a> sr_data; <a name="l01400"></a>01400 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1BundleStatusReport.html#a9e6e466cf356e0550bd1f36def1f4dc" title="Parse a byte stream containing a Status Report Payload and store the fields in the...">BundleStatusReport::parse_status_report</a>(&sr_data, b)) <a name="l01401"></a>01401 { <a name="l01402"></a>01402 payload.<a class="code" href="structdtn__bundle__payload__t.html#2f104cdd7e463ca104b468fa98527f84">status_report</a> = &status_report; <a name="l01403"></a>01403 sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#a0e5648f21a9d7ded26521289c2e4aeb">orig_source_eid_</a>.<a class="code" href="classdtn_1_1EndpointID.html#618dc017f7a791f7aa64b5be6cb002f8" title="Copy the endpoint id contents out to the API type dtn_endpoint_id_t.">copyto</a>(&status_report.<a class="code" href="structdtn__bundle__status__report__t.html#d250d962fb57440a14a9b0488955faad">bundle_id</a>.<a class="code" href="structdtn__bundle__id__t.html#85fee9b6bc50f4b6aa397a0a31d1e896">source</a>); <a name="l01404"></a>01404 status_report.<a class="code" href="structdtn__bundle__status__report__t.html#d250d962fb57440a14a9b0488955faad">bundle_id</a>.<a class="code" href="structdtn__bundle__id__t.html#45c8507ca01c07300d6fe860b29332ef">creation_ts</a>.<a class="code" href="structdtn__timestamp__t.html#68d91d87e4f7e4d1c17b68338331609b">secs</a> = <a name="l01405"></a>01405 sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#24a8b16df7b3050f6ca8fb2479c6d574">orig_creation_tv_</a>.<a class="code" href="structdtn_1_1BundleTimestamp.html#02c8a347150620243240655bdcd2f42d" title="Seconds since 1/1/2000.">seconds_</a>; <a name="l01406"></a>01406 status_report.<a class="code" href="structdtn__bundle__status__report__t.html#d250d962fb57440a14a9b0488955faad">bundle_id</a>.<a class="code" href="structdtn__bundle__id__t.html#45c8507ca01c07300d6fe860b29332ef">creation_ts</a>.<a class="code" href="structdtn__timestamp__t.html#406e2588feaa0826c76526e872347fd5">seqno</a> = <a name="l01407"></a>01407 sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#24a8b16df7b3050f6ca8fb2479c6d574">orig_creation_tv_</a>.<a class="code" href="structdtn_1_1BundleTimestamp.html#ebc8cea66862d7f6056da450db410347" title="Sub-second sequence number.">seqno_</a>; <a name="l01408"></a>01408 status_report.<a class="code" href="structdtn__bundle__status__report__t.html#d250d962fb57440a14a9b0488955faad">bundle_id</a>.<a class="code" href="structdtn__bundle__id__t.html#4ac1bb6795c7b7b04b11bb013ebeec57">frag_offset</a> = sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#dc07b750280a3ffb45b922f6dd64bda2">orig_frag_offset_</a>; <a name="l01409"></a>01409 status_report.<a class="code" href="structdtn__bundle__status__report__t.html#d250d962fb57440a14a9b0488955faad">bundle_id</a>.<a class="code" href="structdtn__bundle__id__t.html#79af75224d17fda12ae60ca622d7028f">orig_length</a> = sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#aa5e604aa7f1e5309f33b3eaec40aaa5">orig_frag_length_</a>; <a name="l01410"></a>01410 <a name="l01411"></a>01411 status_report.<a class="code" href="structdtn__bundle__status__report__t.html#3de5598dc702b9375ed43c4f7335cf39">reason</a> = (<a class="code" href="dtn__types_8h.html#87e1a70c1e1b7872a0337ed40dc4f134" title="Bundle Status Report &quot;Reason Code&quot; flags.">dtn_status_report_reason_t</a>)sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#12fab47b69881fcc1ca2cb75c6941746">reason_code_</a>; <a name="l01412"></a>01412 status_report.<a class="code" href="structdtn__bundle__status__report__t.html#106f245fab47da2abee3d5b0fb413315">flags</a> = (<a class="code" href="dtn__types_8h.html#6d9484ac5d0ab5f3fd7383af0c7b9919" title="Bundle Status Report status flags that indicate which timestamps in the status report...">dtn_status_report_flags_t</a>)sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#3f1f30037f28bb8ad3de467df41d8a8d">status_flags_</a>; <a name="l01413"></a>01413 <a name="l01414"></a>01414 status_report.<a class="code" href="structdtn__bundle__status__report__t.html#5acf2262f0099eb9f5be29921a5a94dd">receipt_ts</a>.<a class="code" href="structdtn__timestamp__t.html#68d91d87e4f7e4d1c17b68338331609b">secs</a> = sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#304997abfd815cb4570ba38d5dc5a0f9">receipt_tv_</a>.<a class="code" href="structdtn_1_1BundleTimestamp.html#02c8a347150620243240655bdcd2f42d" title="Seconds since 1/1/2000.">seconds_</a>; <a name="l01415"></a>01415 status_report.<a class="code" href="structdtn__bundle__status__report__t.html#5acf2262f0099eb9f5be29921a5a94dd">receipt_ts</a>.<a class="code" href="structdtn__timestamp__t.html#406e2588feaa0826c76526e872347fd5">seqno</a> = sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#304997abfd815cb4570ba38d5dc5a0f9">receipt_tv_</a>.<a class="code" href="structdtn_1_1BundleTimestamp.html#ebc8cea66862d7f6056da450db410347" title="Sub-second sequence number.">seqno_</a>; <a name="l01416"></a>01416 status_report.<a class="code" href="structdtn__bundle__status__report__t.html#a295fd30ad4097cf7dec32a7c5e0db1a">custody_ts</a>.<a class="code" href="structdtn__timestamp__t.html#68d91d87e4f7e4d1c17b68338331609b">secs</a> = sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#a12c42c06734a0f27e09240cdcf40d5f">custody_tv_</a>.<a class="code" href="structdtn_1_1BundleTimestamp.html#02c8a347150620243240655bdcd2f42d" title="Seconds since 1/1/2000.">seconds_</a>; <a name="l01417"></a>01417 status_report.<a class="code" href="structdtn__bundle__status__report__t.html#a295fd30ad4097cf7dec32a7c5e0db1a">custody_ts</a>.<a class="code" href="structdtn__timestamp__t.html#406e2588feaa0826c76526e872347fd5">seqno</a> = sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#a12c42c06734a0f27e09240cdcf40d5f">custody_tv_</a>.<a class="code" href="structdtn_1_1BundleTimestamp.html#ebc8cea66862d7f6056da450db410347" title="Sub-second sequence number.">seqno_</a>; <a name="l01418"></a>01418 status_report.<a class="code" href="structdtn__bundle__status__report__t.html#d951191b5dc254cf1a5e7beaf53f1b08">forwarding_ts</a>.<a class="code" href="structdtn__timestamp__t.html#68d91d87e4f7e4d1c17b68338331609b">secs</a> = sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#8eb774a8ad59cdd6a3a91a87392b30da">forwarding_tv_</a>.<a class="code" href="structdtn_1_1BundleTimestamp.html#02c8a347150620243240655bdcd2f42d" title="Seconds since 1/1/2000.">seconds_</a>; <a name="l01419"></a>01419 status_report.<a class="code" href="structdtn__bundle__status__report__t.html#d951191b5dc254cf1a5e7beaf53f1b08">forwarding_ts</a>.<a class="code" href="structdtn__timestamp__t.html#406e2588feaa0826c76526e872347fd5">seqno</a> = sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#8eb774a8ad59cdd6a3a91a87392b30da">forwarding_tv_</a>.<a class="code" href="structdtn_1_1BundleTimestamp.html#ebc8cea66862d7f6056da450db410347" title="Sub-second sequence number.">seqno_</a>; <a name="l01420"></a>01420 status_report.<a class="code" href="structdtn__bundle__status__report__t.html#25d8c3507f8643f0b8be0e3aba50da31">delivery_ts</a>.<a class="code" href="structdtn__timestamp__t.html#68d91d87e4f7e4d1c17b68338331609b">secs</a> = sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#972b1e9695dd6d0ed5802170e22ff489">delivery_tv_</a>.<a class="code" href="structdtn_1_1BundleTimestamp.html#02c8a347150620243240655bdcd2f42d" title="Seconds since 1/1/2000.">seconds_</a>; <a name="l01421"></a>01421 status_report.<a class="code" href="structdtn__bundle__status__report__t.html#25d8c3507f8643f0b8be0e3aba50da31">delivery_ts</a>.<a class="code" href="structdtn__timestamp__t.html#406e2588feaa0826c76526e872347fd5">seqno</a> = sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#972b1e9695dd6d0ed5802170e22ff489">delivery_tv_</a>.<a class="code" href="structdtn_1_1BundleTimestamp.html#ebc8cea66862d7f6056da450db410347" title="Sub-second sequence number.">seqno_</a>; <a name="l01422"></a>01422 status_report.<a class="code" href="structdtn__bundle__status__report__t.html#391eb127c1b32e0fa25a14840b2155b0">deletion_ts</a>.<a class="code" href="structdtn__timestamp__t.html#68d91d87e4f7e4d1c17b68338331609b">secs</a> = sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#54689605e52b7c87e60f2ff0ab8fb413">deletion_tv_</a>.<a class="code" href="structdtn_1_1BundleTimestamp.html#02c8a347150620243240655bdcd2f42d" title="Seconds since 1/1/2000.">seconds_</a>; <a name="l01423"></a>01423 status_report.<a class="code" href="structdtn__bundle__status__report__t.html#391eb127c1b32e0fa25a14840b2155b0">deletion_ts</a>.<a class="code" href="structdtn__timestamp__t.html#406e2588feaa0826c76526e872347fd5">seqno</a> = sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#54689605e52b7c87e60f2ff0ab8fb413">deletion_tv_</a>.<a class="code" href="structdtn_1_1BundleTimestamp.html#ebc8cea66862d7f6056da450db410347" title="Sub-second sequence number.">seqno_</a>; <a name="l01424"></a>01424 status_report.<a class="code" href="structdtn__bundle__status__report__t.html#431f2cef195089aabeb9a4f50bb5ed31">ack_by_app_ts</a>.<a class="code" href="structdtn__timestamp__t.html#68d91d87e4f7e4d1c17b68338331609b">secs</a> = sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#d83b26f19b8246119e870453922ba151">ack_by_app_tv_</a>.<a class="code" href="structdtn_1_1BundleTimestamp.html#02c8a347150620243240655bdcd2f42d" title="Seconds since 1/1/2000.">seconds_</a>; <a name="l01425"></a>01425 status_report.<a class="code" href="structdtn__bundle__status__report__t.html#431f2cef195089aabeb9a4f50bb5ed31">ack_by_app_ts</a>.<a class="code" href="structdtn__timestamp__t.html#406e2588feaa0826c76526e872347fd5">seqno</a> = sr_data.<a class="code" href="structdtn_1_1BundleStatusReport_1_1data__t.html#d83b26f19b8246119e870453922ba151">ack_by_app_tv_</a>.<a class="code" href="structdtn_1_1BundleTimestamp.html#ebc8cea66862d7f6056da450db410347" title="Sub-second sequence number.">seqno_</a>; <a name="l01426"></a>01426 } <a name="l01427"></a>01427 <a name="l01428"></a>01428 <span class="keywordflow">if</span> (!<a class="code" href="dtn__types_8h.html#54a4fbc50daeb79cc615af82793cbdc8">xdr_dtn_bundle_spec_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#913a8a0ef9793ca0ad9742be58aaa5e9">xdr_encode_</a>, &spec)) <a name="l01429"></a>01429 { <a name="l01430"></a>01430 log_err(<span class="stringliteral">"internal error in xdr: xdr_dtn_bundle_spec_t"</span>); <a name="l01431"></a>01431 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#2121e3f0d822e257e8d2e843a3524ef0">DTN_EXDR</a>; <a name="l01432"></a>01432 } <a name="l01433"></a>01433 <a name="l01434"></a>01434 <span class="keywordflow">if</span> (!<a class="code" href="dtn__types_8h.html#52d9e9ef1e11bf39693baced9c591d67">xdr_dtn_bundle_payload_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#913a8a0ef9793ca0ad9742be58aaa5e9">xdr_encode_</a>, &payload)) <a name="l01435"></a>01435 { <a name="l01436"></a>01436 log_err(<span class="stringliteral">"internal error in xdr: xdr_dtn_bundle_payload_t"</span>); <a name="l01437"></a>01437 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#2121e3f0d822e257e8d2e843a3524ef0">DTN_EXDR</a>; <a name="l01438"></a>01438 } <a name="l01439"></a>01439 <a name="l01440"></a>01440 <span class="comment">// prevent xdr_free of non-malloc'd pointer</span> <a name="l01441"></a>01441 payload.<a class="code" href="structdtn__bundle__payload__t.html#2f104cdd7e463ca104b468fa98527f84">status_report</a> = NULL; <a name="l01442"></a>01442 <a name="l01443"></a>01443 log_info(<span class="stringliteral">"DTN_RECV: "</span> <a name="l01444"></a>01444 <span class="stringliteral">"successfully delivered bundle %d to registration %d"</span>, <a name="l01445"></a>01445 b-><a class="code" href="classdtn_1_1Bundle.html#7031e2e5e4078445bf4ad39cdcdea3b2" title="Accessors.">bundleid</a>(), reg-><a class="code" href="classdtn_1_1Registration.html#d1cd25dd8e4c512591849f44e7c8090b" title="Accessors.">regid</a>()); <a name="l01446"></a>01446 <a name="l01447"></a>01447 <a class="code" href="classdtn_1_1BundleDaemon.html#370a80f7dd9fd9297e76d7f830d737a8" title="Queues the event at the tail of the queue for processing by the daemon thread.">BundleDaemon::post</a>(<span class="keyword">new</span> <a class="code" href="classdtn_1_1BundleDeliveredEvent.html" title="Event class for local bundle delivery.">BundleDeliveredEvent</a>(b, reg)); <a name="l01448"></a>01448 <a name="l01449"></a>01449 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>; <a name="l01450"></a>01450 } <a name="l01451"></a>01451 <a name="l01452"></a>01452 <span class="comment">//----------------------------------------------------------------------</span> <a name="l01453"></a>01453 <span class="keywordtype">int</span> <a name="l01454"></a><a class="code" href="classdtn_1_1APIClient.html#e082ab699cdd974eff4be0b3622342e4">01454</a> <a class="code" href="classdtn_1_1APIClient.html#e082ab699cdd974eff4be0b3622342e4">APIClient::handle_begin_poll</a>() <a name="l01455"></a>01455 { <a name="l01456"></a>01456 <a class="code" href="dtn__types_8h.html#8865a20f2e713bb38e35736e32e1653c" title="DTN timeouts are specified in seconds.">dtn_timeval_t</a> timeout; <a name="l01457"></a>01457 <a class="code" href="classdtn_1_1APIRegistration.html" title="Registration class to represent an actual attached application over the client api...">APIRegistration</a>* recv_reg = NULL; <a name="l01458"></a>01458 <a class="code" href="classdtn_1_1APIRegistration.html" title="Registration class to represent an actual attached application over the client api...">APIRegistration</a>* notify_reg = NULL; <a name="l01459"></a>01459 <span class="keywordtype">bool</span> sock_ready = <span class="keyword">false</span>; <a name="l01460"></a>01460 <a name="l01461"></a>01461 <span class="comment">// unpack the arguments</span> <a name="l01462"></a>01462 <span class="keywordflow">if</span> ((!<a class="code" href="dtn__types_8h.html#62ea0edc92ab755946bef6dcfaf1f611">xdr_dtn_timeval_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#ace73b2d7a0e5c748ee9c1bf741c5b41">xdr_decode_</a>, &timeout))) <a name="l01463"></a>01463 { <a name="l01464"></a>01464 log_err(<span class="stringliteral">"error in xdr unpacking arguments"</span>); <a name="l01465"></a>01465 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#2121e3f0d822e257e8d2e843a3524ef0">DTN_EXDR</a>; <a name="l01466"></a>01466 } <a name="l01467"></a>01467 <a name="l01468"></a>01468 <span class="keywordtype">int</span> err = <a class="code" href="classdtn_1_1APIClient.html#684680789390fa8e03f98a0abd5cb518">wait_for_notify</a>(<span class="stringliteral">"poll"</span>, timeout, &recv_reg, &notify_reg, <a name="l01469"></a>01469 &sock_ready); <a name="l01470"></a>01470 <span class="keywordflow">if</span> (err != 0) { <a name="l01471"></a>01471 <span class="keywordflow">return</span> err; <a name="l01472"></a>01472 } <a name="l01473"></a>01473 <a name="l01474"></a>01474 <span class="comment">// if there's data on the socket, then the application either quit</span> <a name="l01475"></a>01475 <span class="comment">// and closed the socket, or called dtn_poll_cancel</span> <a name="l01476"></a>01476 <span class="keywordflow">if</span> (sock_ready) { <a name="l01477"></a>01477 log_debug(<span class="stringliteral">"handle_begin_poll: "</span> <a name="l01478"></a>01478 <span class="stringliteral">"api socket ready -- trying to read one byte"</span>); <a name="l01479"></a>01479 <span class="keywordtype">char</span> type; <a name="l01480"></a>01480 <a name="l01481"></a>01481 <span class="keywordtype">int</span> ret = read(&type, 1); <a name="l01482"></a>01482 <span class="keywordflow">if</span> (ret == 0) { <a name="l01483"></a>01483 log_info(<span class="stringliteral">"IPC socket closed while blocked in read... "</span> <a name="l01484"></a>01484 <span class="stringliteral">"application must have exited"</span>); <a name="l01485"></a>01485 <span class="keywordflow">return</span> -1; <a name="l01486"></a>01486 } <a name="l01487"></a>01487 <a name="l01488"></a>01488 <span class="keywordflow">if</span> (ret == -1) { <a name="l01489"></a>01489 log_err(<span class="stringliteral">"handle_begin_poll: protocol error -- "</span> <a name="l01490"></a>01490 <span class="stringliteral">"error while blocked in poll"</span>); <a name="l01491"></a>01491 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#b4ae5bb2a6256b2dac33962e688584de">DTN_ECOMM</a>; <a name="l01492"></a>01492 } <a name="l01493"></a>01493 <a name="l01494"></a>01494 <span class="keywordflow">if</span> (type != <a class="code" href="dtn__ipc_8h.html#c05301bf9560764f5e97fba507ef9e5df37b9c7e51b4309e5f3ca74a8b743c3b">DTN_CANCEL_POLL</a>) { <a name="l01495"></a>01495 log_err(<span class="stringliteral">"handle_poll: error got unexpected message '%s' "</span> <a name="l01496"></a>01496 <span class="stringliteral">"while blocked in poll"</span>, <a class="code" href="dtn__ipc_8c.html#c5707d2923063f6fe2bde512f525f72b" title="Type code to string conversion routine.">dtnipc_msgtoa</a>(type)); <a name="l01497"></a>01497 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#b4ae5bb2a6256b2dac33962e688584de">DTN_ECOMM</a>; <a name="l01498"></a>01498 } <a name="l01499"></a>01499 <a name="l01500"></a>01500 <span class="comment">// read in the length which must be zero</span> <a name="l01501"></a>01501 u_int32_t <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>; <a name="l01502"></a>01502 ret = read((<span class="keywordtype">char</span>*)&len, 4); <a name="l01503"></a>01503 <span class="keywordflow">if</span> (ret != 4 || len != 0) { <a name="l01504"></a>01504 log_err(<span class="stringliteral">"handle_begin_poll: protocol error -- "</span> <a name="l01505"></a>01505 <span class="stringliteral">"error getting cancel poll length"</span>); <a name="l01506"></a>01506 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#b4ae5bb2a6256b2dac33962e688584de">DTN_ECOMM</a>; <a name="l01507"></a>01507 } <a name="l01508"></a>01508 <a name="l01509"></a>01509 <a class="code" href="classdtn_1_1APIClient.html#64c975c94dafb44c3d761065498aa62f">total_rcvd_</a> += 5; <a name="l01510"></a>01510 <a name="l01511"></a>01511 log_debug(<span class="stringliteral">"got DTN_CANCEL_POLL while blocked in poll"</span>); <a name="l01512"></a>01512 <span class="comment">// immediately send the response to the poll cancel, then</span> <a name="l01513"></a>01513 <span class="comment">// we return from the handler which will follow it with the</span> <a name="l01514"></a>01514 <span class="comment">// response code to the original poll request</span> <a name="l01515"></a>01515 <a class="code" href="classdtn_1_1APIClient.html#476beb5eb7b7073738e3a9c18de1ab5f">send_response</a>(<a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>); <a name="l01516"></a>01516 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (recv_reg != NULL) { <a name="l01517"></a>01517 log_debug(<span class="stringliteral">"handle_begin_poll: bundle arrived"</span>); <a name="l01518"></a>01518 <a name="l01519"></a>01519 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (notify_reg != NULL) { <a name="l01520"></a>01520 log_debug(<span class="stringliteral">"handle_begin_poll: subscriber notify arrived"</span>); <a name="l01521"></a>01521 <a name="l01522"></a>01522 } <span class="keywordflow">else</span> { <a name="l01523"></a>01523 <span class="comment">// wait_for_notify must have returned one of the above cases</span> <a name="l01524"></a>01524 NOTREACHED; <a name="l01525"></a>01525 } <a name="l01526"></a>01526 <a name="l01527"></a>01527 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>; <a name="l01528"></a>01528 } <a name="l01529"></a>01529 <a name="l01530"></a>01530 <span class="comment">//----------------------------------------------------------------------</span> <a name="l01531"></a>01531 <span class="keywordtype">int</span> <a name="l01532"></a><a class="code" href="classdtn_1_1APIClient.html#67898f3771df3d7780d7dd7f3baf0f14">01532</a> <a class="code" href="classdtn_1_1APIClient.html#67898f3771df3d7780d7dd7f3baf0f14">APIClient::handle_cancel_poll</a>() <a name="l01533"></a>01533 { <a name="l01534"></a>01534 <span class="comment">// the only reason we should get in here is if the call to</span> <a name="l01535"></a>01535 <span class="comment">// dtn_begin_poll() returned but the app still called cancel_poll</span> <a name="l01536"></a>01536 <span class="comment">// and so the messages crossed. but, since there's nothing wrong</span> <a name="l01537"></a>01537 <span class="comment">// with this, we just return success in both cases</span> <a name="l01538"></a>01538 <a name="l01539"></a>01539 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>; <a name="l01540"></a>01540 } <a name="l01541"></a>01541 <a name="l01542"></a>01542 <span class="comment">//----------------------------------------------------------------------</span> <a name="l01543"></a>01543 <span class="keywordtype">int</span> <a name="l01544"></a><a class="code" href="classdtn_1_1APIClient.html#ba38760ce21e619d3296059842f56928">01544</a> <a class="code" href="classdtn_1_1APIClient.html#ba38760ce21e619d3296059842f56928">APIClient::handle_close</a>() <a name="l01545"></a>01545 { <a name="l01546"></a>01546 log_info(<span class="stringliteral">"received DTN_CLOSE message; closing API handle"</span>); <a name="l01547"></a>01547 <span class="comment">// return -1 to force the session to close:</span> <a name="l01548"></a>01548 <span class="keywordflow">return</span> -1; <a name="l01549"></a>01549 } <a name="l01550"></a>01550 <a name="l01551"></a>01551 <span class="comment">//----------------------------------------------------------------------</span> <a name="l01552"></a>01552 <span class="keywordtype">int</span> <a name="l01553"></a><a class="code" href="classdtn_1_1APIClient.html#f19b929f413fea3504c794202068c4d7">01553</a> <a class="code" href="classdtn_1_1APIClient.html#f19b929f413fea3504c794202068c4d7">APIClient::handle_session_update</a>() <a name="l01554"></a>01554 { <a name="l01555"></a>01555 <a class="code" href="classdtn_1_1APIRegistration.html" title="Registration class to represent an actual attached application over the client api...">APIRegistration</a>* reg = NULL; <a name="l01556"></a>01556 <span class="keywordtype">bool</span> sock_ready = <span class="keyword">false</span>; <a name="l01557"></a>01557 <a class="code" href="dtn__types_8h.html#8865a20f2e713bb38e35736e32e1653c" title="DTN timeouts are specified in seconds.">dtn_timeval_t</a> timeout; <a name="l01558"></a>01558 <a name="l01559"></a>01559 <span class="comment">// unpack the arguments</span> <a name="l01560"></a>01560 <span class="keywordflow">if</span> ((!<a class="code" href="dtn__types_8h.html#62ea0edc92ab755946bef6dcfaf1f611">xdr_dtn_timeval_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#ace73b2d7a0e5c748ee9c1bf741c5b41">xdr_decode_</a>, &timeout))) <a name="l01561"></a>01561 { <a name="l01562"></a>01562 log_err(<span class="stringliteral">"error in xdr unpacking arguments"</span>); <a name="l01563"></a>01563 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#2121e3f0d822e257e8d2e843a3524ef0">DTN_EXDR</a>; <a name="l01564"></a>01564 } <a name="l01565"></a>01565 <a name="l01566"></a>01566 <span class="keywordtype">int</span> err = <a class="code" href="classdtn_1_1APIClient.html#684680789390fa8e03f98a0abd5cb518">wait_for_notify</a>(<span class="stringliteral">"session_update"</span>, timeout, NULL, &reg, <a name="l01567"></a>01567 &sock_ready); <a name="l01568"></a>01568 <span class="keywordflow">if</span> (err != 0) { <a name="l01569"></a>01569 <span class="keywordflow">return</span> err; <a name="l01570"></a>01570 } <a name="l01571"></a>01571 <a name="l01572"></a>01572 <span class="comment">// if there's data on the socket, that either means the socket was</span> <a name="l01573"></a>01573 <span class="comment">// closed by an exiting application or the app is violating the</span> <a name="l01574"></a>01574 <span class="comment">// protocol...</span> <a name="l01575"></a>01575 <span class="keywordflow">if</span> (sock_ready) { <a name="l01576"></a>01576 <span class="keywordflow">return</span> <a class="code" href="classdtn_1_1APIClient.html#bfb85bb3e353ab67949514ea0aa72059">handle_unexpected_data</a>(<span class="stringliteral">"handle_session_update"</span>); <a name="l01577"></a>01577 } <a name="l01578"></a>01578 <a name="l01579"></a>01579 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(reg != NULL); <a name="l01580"></a>01580 <a name="l01581"></a>01581 <a class="code" href="namespacedtn.html#87094f3b26b9f1d469e616d311ae57b1" title="Class definition for a Bundle reference.">BundleRef</a> bref(<span class="stringliteral">"APIClient::handle_session_update"</span>); <a name="l01582"></a>01582 bref = reg-><a class="code" href="classdtn_1_1APIRegistration.html#dd7acdd55f2afbe277a26258195dc0a2" title="Accessor for notification of session subscribers / unsubscribers (currently just...">session_notify_list</a>()-><a class="code" href="classdtn_1_1BundleList.html#265a9efd0831be3094f815eed22aec42" title="Remove (and return) a reference to the first bundle on the list.">pop_front</a>(); <a name="l01583"></a>01583 <a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* b = bref.object(); <a name="l01584"></a>01584 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(b != NULL); <a name="l01585"></a>01585 <a name="l01586"></a>01586 log_debug(<span class="stringliteral">"handle_session_update: "</span> <a name="l01587"></a>01587 <span class="stringliteral">"popped *%p for registration %d (timeout %d)"</span>, <a name="l01588"></a>01588 b, reg-><a class="code" href="classdtn_1_1Registration.html#d1cd25dd8e4c512591849f44e7c8090b" title="Accessors.">regid</a>(), timeout); <a name="l01589"></a>01589 <a name="l01590"></a>01590 <a name="l01591"></a>01591 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(b-><a class="code" href="classdtn_1_1Bundle.html#973ca2bfa07da25650c14c0b536b0665" title="Accessors.">session_flags</a>() != 0); <a name="l01592"></a>01592 <a name="l01593"></a>01593 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="dtncat_8c.html#7508c434c1f2152c7fd03381726d0a2a">session_flags</a> = 0; <a name="l01594"></a>01594 <span class="keywordflow">if</span> (b-><a class="code" href="classdtn_1_1Bundle.html#973ca2bfa07da25650c14c0b536b0665" title="Accessors.">session_flags</a>() & <a class="code" href="classdtn_1_1Session.html#a795473f389a203d6e15058da8d9498cadd5836fef35cca7c207e710e8e13239">Session::SUBSCRIBE</a>) { <a name="l01595"></a>01595 session_flags |= <a class="code" href="dtn__types_8h.html#a6d0071f396dd4ef85f6ad6332e37f003c2e2090965814efabe47f3f2a358e33">DTN_SESSION_SUBSCRIBE</a>; <a name="l01596"></a>01596 } <a name="l01597"></a>01597 <span class="comment">// XXX/demmer what to do about UNSUBSCRIBE/PUBLISH??</span> <a name="l01598"></a>01598 <a name="l01599"></a>01599 <a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a> session_eid; <a name="l01600"></a>01600 b-><a class="code" href="classdtn_1_1Bundle.html#9bdc5df0500ec9859132c917f48f7bb0" title="Accessors.">session_eid</a>().<a class="code" href="classdtn_1_1EndpointID.html#618dc017f7a791f7aa64b5be6cb002f8" title="Copy the endpoint id contents out to the API type dtn_endpoint_id_t.">copyto</a>(&session_eid); <a name="l01601"></a>01601 <a name="l01602"></a>01602 <span class="keywordflow">if</span> (!xdr_u_int(&<a class="code" href="classdtn_1_1APIClient.html#913a8a0ef9793ca0ad9742be58aaa5e9">xdr_encode_</a>, &session_flags) || <a name="l01603"></a>01603 !<a class="code" href="dtn__types_8h.html#16c5a6f4fcdc988f54f034bb1961b342">xdr_dtn_endpoint_id_t</a>(&<a class="code" href="classdtn_1_1APIClient.html#913a8a0ef9793ca0ad9742be58aaa5e9">xdr_encode_</a>, &session_eid)) <a name="l01604"></a>01604 { <a name="l01605"></a>01605 log_err(<span class="stringliteral">"internal error in xdr"</span>); <a name="l01606"></a>01606 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#2121e3f0d822e257e8d2e843a3524ef0">DTN_EXDR</a>; <a name="l01607"></a>01607 } <a name="l01608"></a>01608 <a name="l01609"></a>01609 log_info(<span class="stringliteral">"session_update: "</span> <a name="l01610"></a>01610 <span class="stringliteral">"notification for session %s status %s"</span>, <a name="l01611"></a>01611 b-><a class="code" href="classdtn_1_1Bundle.html#9bdc5df0500ec9859132c917f48f7bb0" title="Accessors.">session_eid</a>().<a class="code" href="classdtn_1_1EndpointID.html#c9d8a72806359621f4d2850c1e78269c">c_str</a>(), <a class="code" href="classdtn_1_1Session.html#f8421d3cc745b485e316195af331fe37" title="Pretty print function for session flags.">Session::flag_str</a>(b-><a class="code" href="classdtn_1_1Bundle.html#973ca2bfa07da25650c14c0b536b0665" title="Accessors.">session_flags</a>())); <a name="l01612"></a>01612 <a name="l01613"></a>01613 <a class="code" href="classdtn_1_1BundleDaemon.html#370a80f7dd9fd9297e76d7f830d737a8" title="Queues the event at the tail of the queue for processing by the daemon thread.">BundleDaemon::post</a>(<span class="keyword">new</span> <a class="code" href="classdtn_1_1BundleDeliveredEvent.html" title="Event class for local bundle delivery.">BundleDeliveredEvent</a>(b, reg)); <a name="l01614"></a>01614 <a name="l01615"></a>01615 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>; <a name="l01616"></a>01616 } <a name="l01617"></a>01617 <a name="l01618"></a>01618 <span class="comment">//----------------------------------------------------------------------</span> <a name="l01619"></a>01619 <span class="keywordtype">int</span> <a name="l01620"></a><a class="code" href="classdtn_1_1APIClient.html#684680789390fa8e03f98a0abd5cb518">01620</a> <a class="code" href="classdtn_1_1APIClient.html#684680789390fa8e03f98a0abd5cb518">APIClient::wait_for_notify</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* operation, <a name="l01621"></a>01621 <a class="code" href="dtn__types_8h.html#8865a20f2e713bb38e35736e32e1653c" title="DTN timeouts are specified in seconds.">dtn_timeval_t</a> dtn_timeout, <a name="l01622"></a>01622 <a class="code" href="classdtn_1_1APIRegistration.html" title="Registration class to represent an actual attached application over the client api...">APIRegistration</a>** recv_ready_reg, <a name="l01623"></a>01623 <a class="code" href="classdtn_1_1APIRegistration.html" title="Registration class to represent an actual attached application over the client api...">APIRegistration</a>** session_ready_reg, <a name="l01624"></a>01624 <span class="keywordtype">bool</span>* sock_ready) <a name="l01625"></a>01625 { <a name="l01626"></a>01626 <a class="code" href="classdtn_1_1APIRegistration.html" title="Registration class to represent an actual attached application over the client api...">APIRegistration</a>* reg; <a name="l01627"></a>01627 <a name="l01628"></a>01628 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(sock_ready != NULL); <a name="l01629"></a>01629 <span class="keywordflow">if</span> (recv_ready_reg) *recv_ready_reg = NULL; <a name="l01630"></a>01630 <span class="keywordflow">if</span> (session_ready_reg) *session_ready_reg = NULL; <a name="l01631"></a>01631 <a name="l01632"></a>01632 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>->empty()) { <a name="l01633"></a>01633 log_err(<span class="stringliteral">"wait_for_notify(%s): no bound registrations"</span>, operation); <a name="l01634"></a>01634 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l01635"></a>01635 } <a name="l01636"></a>01636 <a name="l01637"></a>01637 <span class="keywordtype">int</span> timeout = (int)dtn_timeout; <a name="l01638"></a>01638 <span class="keywordflow">if</span> (timeout < -1) { <a name="l01639"></a>01639 log_err(<span class="stringliteral">"wait_for_notify(%s): "</span> <a name="l01640"></a>01640 <span class="stringliteral">"invalid timeout value %d"</span>, operation, timeout); <a name="l01641"></a>01641 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#8db3fceccf291cdfc226b9bea2316346">DTN_EINVAL</a>; <a name="l01642"></a>01642 } <a name="l01643"></a>01643 <a name="l01644"></a>01644 <span class="comment">// try to optimize by using a statically sized pollfds array,</span> <a name="l01645"></a>01645 <span class="comment">// otherwise we need to malloc the array.</span> <a name="l01646"></a>01646 <span class="comment">//</span> <a name="l01647"></a>01647 <span class="comment">// XXX/demmer this would be cleaner by tweaking the</span> <a name="l01648"></a>01648 <span class="comment">// StaticScratchBuffer class to be handle arrays of arbitrary</span> <a name="l01649"></a>01649 <span class="comment">// sized structs</span> <a name="l01650"></a>01650 <span class="keyword">struct </span>pollfd static_pollfds[64]; <a name="l01651"></a>01651 <span class="keyword">struct </span>pollfd* pollfds; <a name="l01652"></a>01652 oasys::ScopeMalloc pollfd_malloc; <a name="l01653"></a>01653 <span class="keywordtype">size_t</span> npollfds = 1; <a name="l01654"></a>01654 <span class="keywordflow">if</span> (recv_ready_reg) npollfds += <a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>->size(); <a name="l01655"></a>01655 <span class="keywordflow">if</span> (session_ready_reg) npollfds += <a class="code" href="classdtn_1_1APIClient.html#5448e687c48be53a1df5d5246b0f7e3f">sessions_</a>->size(); <a name="l01656"></a>01656 <a name="l01657"></a>01657 <span class="keywordflow">if</span> (npollfds <= 64) { <a name="l01658"></a>01658 pollfds = &static_pollfds[0]; <a name="l01659"></a>01659 } <span class="keywordflow">else</span> { <a name="l01660"></a>01660 pollfds = (<span class="keyword">struct </span>pollfd*)malloc(npollfds * <span class="keyword">sizeof</span>(<span class="keyword">struct</span> pollfd)); <a name="l01661"></a>01661 pollfd_malloc = pollfds; <a name="l01662"></a>01662 } <a name="l01663"></a>01663 <a name="l01664"></a>01664 <span class="keyword">struct </span>pollfd* sock_poll = &pollfds[0]; <a name="l01665"></a>01665 sock_poll->fd = TCPClient::fd_; <a name="l01666"></a>01666 sock_poll->events = POLLIN | POLLERR; <a name="l01667"></a>01667 sock_poll->revents = 0; <a name="l01668"></a>01668 <a name="l01669"></a>01669 <span class="comment">// loop through all the registrations -- if one has bundles on its</span> <a name="l01670"></a>01670 <span class="comment">// list, we don't need to poll, just return it immediately.</span> <a name="l01671"></a>01671 <span class="comment">// otherwise we'll need to poll it</span> <a name="l01672"></a>01672 APIRegistrationList::iterator iter; <a name="l01673"></a>01673 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 1; <a name="l01674"></a>01674 <span class="keywordflow">if</span> (recv_ready_reg) { <a name="l01675"></a>01675 log_debug(<span class="stringliteral">"wait_for_notify(%s): checking %zu bindings"</span>, <a name="l01676"></a>01676 operation, <a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>->size()); <a name="l01677"></a>01677 <a name="l01678"></a>01678 <span class="keywordflow">for</span> (iter = <a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>->begin(); iter != <a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>->end(); ++iter) { <a name="l01679"></a>01679 reg = *iter; <a name="l01680"></a>01680 <a name="l01681"></a>01681 <span class="keywordflow">if</span> (! reg-><a class="code" href="classdtn_1_1APIRegistration.html#3aad0d8a4f5603f63cb9f09adc1050e6" title="Accessor for the queue of bundles for the registration.">bundle_list</a>()-><a class="code" href="classdtn_1_1BundleList.html#3ca5e173510164b46c8de9a95147f20d" title="Return whether or not the list is empty.">empty</a>()) { <a name="l01682"></a>01682 log_debug(<span class="stringliteral">"wait_for_notify(%s): "</span> <a name="l01683"></a>01683 <span class="stringliteral">"immediately returning bundle for reg %d"</span>, <a name="l01684"></a>01684 operation, reg-><a class="code" href="classdtn_1_1Registration.html#d1cd25dd8e4c512591849f44e7c8090b" title="Accessors.">regid</a>()); <a name="l01685"></a>01685 *recv_ready_reg = reg; <a name="l01686"></a>01686 <span class="keywordflow">return</span> 0; <a name="l01687"></a>01687 } <a name="l01688"></a>01688 <a name="l01689"></a>01689 pollfds[i].fd = reg-><a class="code" href="classdtn_1_1APIRegistration.html#3aad0d8a4f5603f63cb9f09adc1050e6" title="Accessor for the queue of bundles for the registration.">bundle_list</a>()-><a class="code" href="classdtn_1_1BlockingBundleList.html#77bf490a649453c36030dc6c8a359fe7" title="Accessor for the internal notifier.">notifier</a>()->read_fd(); <a name="l01690"></a>01690 pollfds[i].events = POLLIN; <a name="l01691"></a>01691 pollfds[i].revents = 0; <a name="l01692"></a>01692 ++i; <a name="l01693"></a>01693 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(i <= npollfds); <a name="l01694"></a>01694 } <a name="l01695"></a>01695 } <a name="l01696"></a>01696 <a name="l01697"></a>01697 <span class="comment">// ditto for sessions</span> <a name="l01698"></a>01698 <span class="keywordflow">if</span> (session_ready_reg) { <a name="l01699"></a>01699 log_debug(<span class="stringliteral">"wait_for_notify(%s): checking %zu sessions"</span>, <a name="l01700"></a>01700 operation, <a class="code" href="classdtn_1_1APIClient.html#5448e687c48be53a1df5d5246b0f7e3f">sessions_</a>->size()); <a name="l01701"></a>01701 <a name="l01702"></a>01702 <span class="keywordflow">for</span> (iter = <a class="code" href="classdtn_1_1APIClient.html#5448e687c48be53a1df5d5246b0f7e3f">sessions_</a>->begin(); iter != <a class="code" href="classdtn_1_1APIClient.html#5448e687c48be53a1df5d5246b0f7e3f">sessions_</a>->end(); ++iter) <a name="l01703"></a>01703 { <a name="l01704"></a>01704 reg = *iter; <a name="l01705"></a>01705 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(reg-><a class="code" href="classdtn_1_1APIRegistration.html#dd7acdd55f2afbe277a26258195dc0a2" title="Accessor for notification of session subscribers / unsubscribers (currently just...">session_notify_list</a>() != NULL); <a name="l01706"></a>01706 <span class="keywordflow">if</span> (! reg-><a class="code" href="classdtn_1_1APIRegistration.html#dd7acdd55f2afbe277a26258195dc0a2" title="Accessor for notification of session subscribers / unsubscribers (currently just...">session_notify_list</a>()-><a class="code" href="classdtn_1_1BundleList.html#3ca5e173510164b46c8de9a95147f20d" title="Return whether or not the list is empty.">empty</a>()) { <a name="l01707"></a>01707 log_debug(<span class="stringliteral">"wait_for_notify(%s): "</span> <a name="l01708"></a>01708 <span class="stringliteral">"immediately returning notified reg %d"</span>, <a name="l01709"></a>01709 operation, reg-><a class="code" href="classdtn_1_1Registration.html#d1cd25dd8e4c512591849f44e7c8090b" title="Accessors.">regid</a>()); <a name="l01710"></a>01710 *session_ready_reg = reg; <a name="l01711"></a>01711 <span class="keywordflow">return</span> 0; <a name="l01712"></a>01712 } <a name="l01713"></a>01713 <a name="l01714"></a>01714 pollfds[i].fd = reg-><a class="code" href="classdtn_1_1APIRegistration.html#dd7acdd55f2afbe277a26258195dc0a2" title="Accessor for notification of session subscribers / unsubscribers (currently just...">session_notify_list</a>()-><a class="code" href="classdtn_1_1BlockingBundleList.html#77bf490a649453c36030dc6c8a359fe7" title="Accessor for the internal notifier.">notifier</a>()->read_fd(); <a name="l01715"></a>01715 pollfds[i].events = POLLIN; <a name="l01716"></a>01716 pollfds[i].revents = 0; <a name="l01717"></a>01717 ++i; <a name="l01718"></a>01718 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(i <= npollfds); <a name="l01719"></a>01719 } <a name="l01720"></a>01720 } <a name="l01721"></a>01721 <a name="l01722"></a>01722 <span class="keywordflow">if</span> (timeout == 0) { <a name="l01723"></a>01723 log_debug(<span class="stringliteral">"wait_for_notify(%s): "</span> <a name="l01724"></a>01724 <span class="stringliteral">"no ready registrations and timeout=%d, returning immediately"</span>, <a name="l01725"></a>01725 operation, timeout); <a name="l01726"></a>01726 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#35b24187121ca003154518bba0a35e75">DTN_ETIMEOUT</a>; <a name="l01727"></a>01727 } <a name="l01728"></a>01728 <a name="l01729"></a>01729 log_debug(<span class="stringliteral">"wait_for_notify(%s): "</span> <a name="l01730"></a>01730 <span class="stringliteral">"blocking to get events from %zu sources (timeout %d)"</span>, <a name="l01731"></a>01731 operation, npollfds, timeout); <a name="l01732"></a>01732 <span class="keywordtype">int</span> nready = oasys::IO::poll_multiple(&pollfds[0], npollfds, timeout, <a name="l01733"></a>01733 NULL, logpath_); <a name="l01734"></a>01734 <a name="l01735"></a>01735 <span class="keywordflow">if</span> (nready == oasys::IOTIMEOUT) { <a name="l01736"></a>01736 log_debug(<span class="stringliteral">"wait_for_notify(%s): timeout waiting for events"</span>, <a name="l01737"></a>01737 operation); <a name="l01738"></a>01738 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#35b24187121ca003154518bba0a35e75">DTN_ETIMEOUT</a>; <a name="l01739"></a>01739 <a name="l01740"></a>01740 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (nready <= 0) { <a name="l01741"></a>01741 log_err(<span class="stringliteral">"wait_for_notify(%s): unexpected error polling for events"</span>, <a name="l01742"></a>01742 operation); <a name="l01743"></a>01743 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#951a074861ce082706b57c300413042b">DTN_EINTERNAL</a>; <a name="l01744"></a>01744 } <a name="l01745"></a>01745 <a name="l01746"></a>01746 <span class="comment">// if there's data on the socket, immediately exit without</span> <a name="l01747"></a>01747 <span class="comment">// checking the registrations</span> <a name="l01748"></a>01748 <span class="keywordflow">if</span> (sock_poll->revents != 0) { <a name="l01749"></a>01749 *sock_ready = <span class="keyword">true</span>; <a name="l01750"></a>01750 <span class="keywordflow">return</span> 0; <a name="l01751"></a>01751 } <a name="l01752"></a>01752 <a name="l01753"></a>01753 <span class="comment">// otherwise, there should be data on one (or more) bundle lists, so</span> <a name="l01754"></a>01754 <span class="comment">// scan the list to find the first one.</span> <a name="l01755"></a>01755 <span class="keywordflow">if</span> (recv_ready_reg) { <a name="l01756"></a>01756 <span class="keywordflow">for</span> (iter = <a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>->begin(); iter != <a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>->end(); ++iter) { <a name="l01757"></a>01757 reg = *iter; <a name="l01758"></a>01758 <span class="keywordflow">if</span> (! reg-><a class="code" href="classdtn_1_1APIRegistration.html#3aad0d8a4f5603f63cb9f09adc1050e6" title="Accessor for the queue of bundles for the registration.">bundle_list</a>()-><a class="code" href="classdtn_1_1BundleList.html#3ca5e173510164b46c8de9a95147f20d" title="Return whether or not the list is empty.">empty</a>()) { <a name="l01759"></a>01759 *recv_ready_reg = reg; <a name="l01760"></a>01760 <span class="keywordflow">break</span>; <a name="l01761"></a>01761 } <a name="l01762"></a>01762 } <a name="l01763"></a>01763 } <a name="l01764"></a>01764 <a name="l01765"></a>01765 <span class="keywordflow">if</span> (session_ready_reg) { <a name="l01766"></a>01766 <span class="keywordflow">for</span> (iter = <a class="code" href="classdtn_1_1APIClient.html#5448e687c48be53a1df5d5246b0f7e3f">sessions_</a>->begin(); iter != <a class="code" href="classdtn_1_1APIClient.html#5448e687c48be53a1df5d5246b0f7e3f">sessions_</a>->end(); ++iter) <a name="l01767"></a>01767 { <a name="l01768"></a>01768 reg = *iter; <a name="l01769"></a>01769 <span class="keywordflow">if</span> (! reg-><a class="code" href="classdtn_1_1APIRegistration.html#dd7acdd55f2afbe277a26258195dc0a2" title="Accessor for notification of session subscribers / unsubscribers (currently just...">session_notify_list</a>()-><a class="code" href="classdtn_1_1BundleList.html#3ca5e173510164b46c8de9a95147f20d" title="Return whether or not the list is empty.">empty</a>()) { <a name="l01770"></a>01770 *session_ready_reg = reg; <a name="l01771"></a>01771 <span class="keywordflow">break</span>; <a name="l01772"></a>01772 } <a name="l01773"></a>01773 } <a name="l01774"></a>01774 } <a name="l01775"></a>01775 <a name="l01776"></a>01776 <span class="keywordflow">if</span> ((recv_ready_reg && *recv_ready_reg == NULL) && <a name="l01777"></a>01777 (session_ready_reg && *session_ready_reg == NULL)) <a name="l01778"></a>01778 { <a name="l01779"></a>01779 log_err(<span class="stringliteral">"wait_for_notify(%s): error -- no lists have any events"</span>, <a name="l01780"></a>01780 operation); <a name="l01781"></a>01781 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#951a074861ce082706b57c300413042b">DTN_EINTERNAL</a>; <a name="l01782"></a>01782 } <a name="l01783"></a>01783 <a name="l01784"></a>01784 <span class="keywordflow">return</span> 0; <a name="l01785"></a>01785 } <a name="l01786"></a>01786 <a name="l01787"></a>01787 <span class="comment">//----------------------------------------------------------------------</span> <a name="l01788"></a>01788 <span class="keywordtype">int</span> <a name="l01789"></a><a class="code" href="classdtn_1_1APIClient.html#bfb85bb3e353ab67949514ea0aa72059">01789</a> <a class="code" href="classdtn_1_1APIClient.html#bfb85bb3e353ab67949514ea0aa72059">APIClient::handle_unexpected_data</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* operation) <a name="l01790"></a>01790 { <a name="l01791"></a>01791 log_debug(<span class="stringliteral">"%s: api socket ready -- trying to read one byte"</span>, <a name="l01792"></a>01792 operation); <a name="l01793"></a>01793 <span class="keywordtype">char</span> b; <a name="l01794"></a>01794 <span class="keywordflow">if</span> (read(&b, 1) != 0) { <a name="l01795"></a>01795 log_err(<span class="stringliteral">"%s: protocol error -- "</span> <a name="l01796"></a>01796 <span class="stringliteral">"data arrived or error while blocked in recv"</span>, <a name="l01797"></a>01797 operation); <a name="l01798"></a>01798 <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#b4ae5bb2a6256b2dac33962e688584de">DTN_ECOMM</a>; <a name="l01799"></a>01799 } <a name="l01800"></a>01800 <a name="l01801"></a>01801 log_info(<span class="stringliteral">"IPC socket closed while blocked in read... "</span> <a name="l01802"></a>01802 <span class="stringliteral">"application must have exited"</span>); <a name="l01803"></a>01803 <span class="keywordflow">return</span> -1; <a name="l01804"></a>01804 } <a name="l01805"></a>01805 <a name="l01806"></a>01806 } <span class="comment">// namespace dtn</span> </pre></div></div> <hr size="1"><address style="text-align: right;"><small>Generated on Mon Jul 21 14:09:37 2008 for DTN Reference Implementation by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address> </body> </html>