slsDetectorPackage/slsDetectorSoftware/docs/html/MySocketTCP_8h-source.html
bergamaschi 3f148c52a1 some more details fixed
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@4 951219d9-93cf-4727-9268-0efd64621fa3
2009-12-01 14:32:14 +00:00

116 lines
13 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>MySocketTCP/MySocketTCP.h 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.4.7 -->
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li id="current"><a href="files.html"><span>Files</span></a></li>
<li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
</ul></div>
<div class="tabs">
<ul>
<li><a href="files.html"><span>File&nbsp;List</span></a></li>
<li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
</ul></div>
<h1>MySocketTCP/MySocketTCP.h</h1><a href="MySocketTCP_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">//version 1.0, base development ij 19/01/09</span>
<a name="l00002"></a>00002
<a name="l00003"></a>00003 <span class="comment">/* Modified by anna on 19.01.2008 */</span>
<a name="l00004"></a>00004 <span class="comment">/*</span>
<a name="l00005"></a>00005 <span class="comment"> canceled SetupParameters() and varaibles intialized in the constructors' headers;</span>
<a name="l00006"></a>00006 <span class="comment"> defined SEND_REC_MAX_SIZE (for compatibilty with mythen (and possibly other) pure C servers (i would move it to the common header file)</span>
<a name="l00007"></a>00007 <span class="comment"></span>
<a name="l00008"></a>00008 <span class="comment"> added #ifndef C_ONLY... to cutout class definition when including in pure C servers (can be removed if SEND_REC_MAX_SIZE is moved to the common header file)</span>
<a name="l00009"></a>00009 <span class="comment"></span>
<a name="l00010"></a>00010 <span class="comment"> defined private variables char hostname[1000] and int portno to store connection informations;</span>
<a name="l00011"></a>00011 <span class="comment"></span>
<a name="l00012"></a>00012 <span class="comment"> defined public functions int getHostname(char *name) and int getPortNumber() to retrieve connection informations</span>
<a name="l00013"></a>00013 <span class="comment"> </span>
<a name="l00014"></a>00014 <span class="comment"> added public function int getErrorStatus() returning 1 if socketDescriptor&lt;0</span>
<a name="l00015"></a>00015 <span class="comment"></span>
<a name="l00016"></a>00016 <span class="comment"> remove exits in the constructors and replace them with socketDescriptor=-1</span>
<a name="l00017"></a>00017 <span class="comment"></span>
<a name="l00018"></a>00018 <span class="comment"> replaced the argument of send/receive data with void (to avoid too much casting or compiler errors/warnings)</span>
<a name="l00019"></a>00019 <span class="comment"></span>
<a name="l00020"></a>00020 <span class="comment"> added a function which really does not close the socket between send/receive (senddataonly, receivedataonly)</span>
<a name="l00021"></a>00021 <span class="comment"></span>
<a name="l00022"></a>00022 <span class="comment">*/</span>
<a name="l00023"></a>00023 <span class="preprocessor">#ifndef MY_SOCKET_TCP_H</span>
<a name="l00024"></a>00024 <span class="preprocessor"></span><span class="preprocessor">#define MY_SOCKET_TCP_H </span>
<a name="l00025"></a>00025 <span class="preprocessor"></span>
<a name="l00026"></a><a class="code" href="MySocketTCP_8h.html#bb1295578cf74e08a721feb53b401551">00026</a> <span class="preprocessor">#define SEND_REC_MAX_SIZE 4096</span>
<a name="l00027"></a><a class="code" href="MySocketTCP_8h.html#50b86f9de42a975581ff978f42ff426d">00027</a> <span class="preprocessor"></span><span class="preprocessor">#define DEFAULT_PORTNO 1952</span>
<a name="l00028"></a>00028 <span class="preprocessor"></span>
<a name="l00029"></a>00029
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;arpa/inet.h&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;netdb.h&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;netinet/in.h&gt;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00034"></a>00034
<a name="l00035"></a>00035
<a name="l00036"></a>00036 <span class="preprocessor">#include &lt;math.h&gt;</span>
<a name="l00037"></a>00037
<a name="l00038"></a><a class="code" href="classMySocketTCP.html">00038</a> <span class="keyword">class </span><a class="code" href="classMySocketTCP.html">MySocketTCP</a>{
<a name="l00039"></a>00039
<a name="l00040"></a>00040 <span class="keyword">public</span>:
<a name="l00041"></a>00041 <a class="code" href="classMySocketTCP.html#4d44c3d3d93c2990bcdff6a58016a170">MySocketTCP</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* <span class="keyword">const</span> host_ip_or_name, <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> <span class="keywordtype">int</span> <span class="keyword">const</span> port_number); <span class="comment">// sender (client): where to? ip </span>
<a name="l00042"></a>00042 <a class="code" href="classMySocketTCP.html#4d44c3d3d93c2990bcdff6a58016a170">MySocketTCP</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> <span class="keywordtype">int</span> <span class="keyword">const</span> port_number); <span class="comment">// receiver (server) local no need for ip </span>
<a name="l00043"></a>00043 <a class="code" href="classMySocketTCP.html#20407e0c509b8e32e164f1780b98b51c">~MySocketTCP</a>();
<a name="l00044"></a>00044
<a name="l00045"></a>00045 <span class="keywordtype">int</span> <a class="code" href="classMySocketTCP.html#6c3f62f34cf58c78d58bcc788776afa5">getHostname</a>(<span class="keywordtype">char</span> *name);
<a name="l00046"></a><a class="code" href="classMySocketTCP.html#8d15a71679ab2f83822db875be1ad5cd">00046</a> <span class="keywordtype">int</span> <a class="code" href="classMySocketTCP.html#8d15a71679ab2f83822db875be1ad5cd">getPortNumber</a>(){<span class="keywordflow">return</span> <a class="code" href="classMySocketTCP.html#cc9182c599b55d4f081c31cb162d56f6">portno</a>;};
<a name="l00047"></a><a class="code" href="classMySocketTCP.html#8cd662e945f4a51e9f616fd5c196bdeb">00047</a> <span class="keywordtype">int</span> <a class="code" href="classMySocketTCP.html#8cd662e945f4a51e9f616fd5c196bdeb">getErrorStatus</a>(){<span class="keywordflow">if</span> (<a class="code" href="classMySocketTCP.html#7246bd46ad899956f39109e528da0567">socketDescriptor</a>&lt;0) <span class="keywordflow">return</span> 1; <span class="keywordflow">else</span> <span class="keywordflow">return</span> 0;};
<a name="l00048"></a>00048
<a name="l00049"></a>00049
<a name="l00050"></a>00050
<a name="l00051"></a>00051 <span class="keywordtype">int</span> <a class="code" href="classMySocketTCP.html#1debe73787357c6dcec52ca981298609">Connect</a>(); <span class="comment">//establish connection a Disconnect should always follow</span>
<a name="l00052"></a>00052 <span class="keywordtype">void</span> <a class="code" href="classMySocketTCP.html#69f0b72663378245f14e2872b92696a4">Disconnect</a>(); <span class="comment">//free connection</span>
<a name="l00053"></a>00053
<a name="l00054"></a>00054 <span class="comment">//The following two functions will connectioned-&gt;send/receive-&gt;disconnect</span>
<a name="l00055"></a>00055 <span class="keywordtype">int</span> <a class="code" href="classMySocketTCP.html#7777e909e20c47d38e32a174b0eae425">SendData</a>(<span class="keywordtype">void</span>* buf,<span class="keywordtype">int</span> length);<span class="comment">//length in characters</span>
<a name="l00056"></a>00056 <span class="keywordtype">int</span> <a class="code" href="classMySocketTCP.html#ed8a6a9435932659ed8793ff57b356c8">ReceiveData</a>(<span class="keywordtype">void</span>* buf,<span class="keywordtype">int</span> length);
<a name="l00057"></a>00057
<a name="l00058"></a>00058
<a name="l00059"></a>00059 <span class="comment">//The following two functions stay connected, blocking other connections, and must be manually disconnected,</span>
<a name="l00060"></a>00060 <span class="comment">// when the last call is a SendData() or ReceiveData() the disconnection will be done automatically</span>
<a name="l00061"></a>00061 <span class="comment">//These function will also automatically disconnect-&gt;reconnect if</span>
<a name="l00062"></a>00062 <span class="comment">// two reads (or two writes) are called in a row to preserve the data send/receive structure </span>
<a name="l00063"></a>00063 <span class="keywordtype">int</span> <a class="code" href="classMySocketTCP.html#1641bc23538af6849efeb195a1b33626">SendDataAndKeepConnection</a>(<span class="keywordtype">void</span>* buf,<span class="keywordtype">int</span> length);
<a name="l00064"></a>00064 <span class="keywordtype">int</span> <a class="code" href="classMySocketTCP.html#375171791400d7d60804b56852ff3611">ReceiveDataAndKeepConnection</a>(<span class="keywordtype">void</span>* buf,<span class="keywordtype">int</span> length);
<a name="l00065"></a>00065
<a name="l00066"></a>00066
<a name="l00067"></a>00067 <span class="comment">// Danger! These functions do not connect nor disconnect nor flush the data! be sure that send-receive match perfectly on both server and client side!</span>
<a name="l00068"></a>00068 <span class="keywordtype">int</span> <a class="code" href="classMySocketTCP.html#2f9ce7233ee4903127039d43b4a34886">SendDataOnly</a>(<span class="keywordtype">void</span>* buf,<span class="keywordtype">int</span> length);
<a name="l00069"></a>00069 <span class="keywordtype">int</span> <a class="code" href="classMySocketTCP.html#a8b6322845e72ffc6da44db774b19d73">ReceiveDataOnly</a>(<span class="keywordtype">void</span>* buf,<span class="keywordtype">int</span> length);
<a name="l00070"></a>00070
<a name="l00071"></a>00071 <span class="keyword">private</span>:
<a name="l00072"></a>00072
<a name="l00073"></a><a class="code" href="classMySocketTCP.html#bfd6f681b235f233d3203336a89d58f2">00073</a> <span class="keywordtype">char</span> <a class="code" href="classMySocketTCP.html#bfd6f681b235f233d3203336a89d58f2">hostname</a>[1000];
<a name="l00074"></a><a class="code" href="classMySocketTCP.html#cc9182c599b55d4f081c31cb162d56f6">00074</a> <span class="keywordtype">int</span> <a class="code" href="classMySocketTCP.html#cc9182c599b55d4f081c31cb162d56f6">portno</a>;
<a name="l00075"></a>00075
<a name="l00076"></a><a class="code" href="classMySocketTCP.html#e95406b86fb4f0e1978c49f0ac9d3821">00076</a> <span class="keywordtype">int</span> <a class="code" href="classMySocketTCP.html#e95406b86fb4f0e1978c49f0ac9d3821">is_a_server</a>;
<a name="l00077"></a><a class="code" href="classMySocketTCP.html#7246bd46ad899956f39109e528da0567">00077</a> <span class="keywordtype">int</span> <a class="code" href="classMySocketTCP.html#7246bd46ad899956f39109e528da0567">socketDescriptor</a>;
<a name="l00078"></a><a class="code" href="classMySocketTCP.html#02c455c28f7aff0075c954c43715dad2">00078</a> <span class="keyword">struct </span>sockaddr_in clientAddress, serverAddress;
<a name="l00079"></a><a class="code" href="classMySocketTCP.html#446008276e7be89c50bd78f9a3015a69">00079</a> socklen_t <a class="code" href="classMySocketTCP.html#446008276e7be89c50bd78f9a3015a69">clientAddress_length</a>;
<a name="l00080"></a>00080
<a name="l00081"></a><a class="code" href="classMySocketTCP.html#8a6787a3cdb6b4539184b92303958f30">00081</a> <span class="keywordtype">int</span> <a class="code" href="classMySocketTCP.html#8a6787a3cdb6b4539184b92303958f30">file_des</a>;
<a name="l00082"></a>00082
<a name="l00083"></a><a class="code" href="classMySocketTCP.html#702056a78e403d4931181d54e7263290">00083</a> <span class="keywordtype">int</span> <a class="code" href="classMySocketTCP.html#702056a78e403d4931181d54e7263290">send_rec_max_size</a>;
<a name="l00084"></a><a class="code" href="classMySocketTCP.html#e0cdfa6a0f0498c01d057ff5db10dca5">00084</a> <span class="keywordtype">bool</span> <a class="code" href="classMySocketTCP.html#e0cdfa6a0f0498c01d057ff5db10dca5">last_keep_connection_open_action_was_a_send</a>;
<a name="l00085"></a>00085
<a name="l00086"></a>00086
<a name="l00087"></a>00087 <span class="comment">// void SetupParameters();</span>
<a name="l00088"></a>00088
<a name="l00089"></a>00089 };
<a name="l00090"></a>00090 <span class="preprocessor">#endif</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Dec 1 15:31:44 2009 by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address>
</body>
</html>