forked from pschatzmann/arduino-stk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSocket_8h_source.html
140 lines (140 loc) · 19 KB
/
Socket_8h_source.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Arduino STK: Socket.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">Arduino STK
 <span id="projectnumber">4.6.2</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Socket.h</div> </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="preprocessor">#ifndef STK_SOCKET_H</span></div>
<div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="preprocessor">#define STK_SOCKET_H</span></div>
<div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="preprocessor">#include "Stk.h"</span></div>
<div class="line"><a name="l00004"></a><span class="lineno"> 4</span>  </div>
<div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="preprocessor">#if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__))</span></div>
<div class="line"><a name="l00006"></a><span class="lineno"> 6</span>  </div>
<div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="preprocessor"> #include <sys/socket.h></span></div>
<div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="preprocessor"> #include <sys/types.h></span></div>
<div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="preprocessor"> #include <arpa/inet.h></span></div>
<div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="preprocessor"> #include <netdb.h></span></div>
<div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="preprocessor"> #include <unistd.h></span></div>
<div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="preprocessor"> #include <fcntl.h></span></div>
<div class="line"><a name="l00013"></a><span class="lineno"> 13</span> <span class="preprocessor"> #include <netinet/in.h></span></div>
<div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="preprocessor"> #include <netinet/tcp.h></span></div>
<div class="line"><a name="l00015"></a><span class="lineno"> 15</span>  </div>
<div class="line"><a name="l00016"></a><span class="lineno"> 16</span> <span class="preprocessor">#elif defined(__OS_WINDOWS__)</span></div>
<div class="line"><a name="l00017"></a><span class="lineno"> 17</span>  </div>
<div class="line"><a name="l00018"></a><span class="lineno"> 18</span> <span class="preprocessor"> #include <winsock.h></span></div>
<div class="line"><a name="l00019"></a><span class="lineno"> 19</span>  </div>
<div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="preprocessor">#elif defined(__LWIP__) </span></div>
<div class="line"><a name="l00021"></a><span class="lineno"> 21</span>  </div>
<div class="line"><a name="l00022"></a><span class="lineno"> 22</span> <span class="preprocessor"> #include <lwip/sockets.h></span></div>
<div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="preprocessor"> #include <lwip/dns.h></span></div>
<div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="preprocessor"> #include <lwip/netdb.h></span></div>
<div class="line"><a name="l00025"></a><span class="lineno"> 25</span>  </div>
<div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="preprocessor">#else </span></div>
<div class="line"><a name="l00027"></a><span class="lineno"> 27</span> <span class="preprocessor">#define __NOIP__</span></div>
<div class="line"><a name="l00028"></a><span class="lineno"> 28</span> <span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00029"></a><span class="lineno"> 29</span>  </div>
<div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="comment">// compile only if we have a valid environment</span></div>
<div class="line"><a name="l00031"></a><span class="lineno"> 31</span> <span class="preprocessor">#ifndef __NOIP__</span></div>
<div class="line"><a name="l00032"></a><span class="lineno"> 32</span>  </div>
<div class="line"><a name="l00033"></a><span class="lineno"> 33</span> <span class="keyword">namespace </span><a class="code" href="namespacestk.html">stk</a> {</div>
<div class="line"><a name="l00034"></a><span class="lineno"> 34</span>  </div>
<div class="line"><a name="l00035"></a><span class="lineno"> 35</span> <span class="comment">/***************************************************/</span></div>
<div class="line"><a name="l00046"></a><span class="lineno"> 46</span> <span class="comment">/***************************************************/</span></div>
<div class="line"><a name="l00047"></a><span class="lineno"> 47</span>  </div>
<div class="line"><a name="l00048"></a><span class="lineno"><a class="line" href="classstk_1_1Socket.html"> 48</a></span> <span class="keyword">class </span><a class="code" href="classstk_1_1Socket.html">Socket</a> : <span class="keyword">public</span> <a class="code" href="classstk_1_1Stk.html">Stk</a></div>
<div class="line"><a name="l00049"></a><span class="lineno"> 49</span> {</div>
<div class="line"><a name="l00050"></a><span class="lineno"> 50</span>  <span class="keyword">public</span>:</div>
<div class="line"><a name="l00051"></a><span class="lineno"> 51</span>  </div>
<div class="line"><a name="l00052"></a><span class="lineno"> 52</span>  <span class="keyword">enum</span> ProtocolType {</div>
<div class="line"><a name="l00053"></a><span class="lineno"> 53</span>  PROTO_TCP,</div>
<div class="line"><a name="l00054"></a><span class="lineno"> 54</span>  PROTO_UDP</div>
<div class="line"><a name="l00055"></a><span class="lineno"> 55</span>  };</div>
<div class="line"><a name="l00056"></a><span class="lineno"> 56</span>  </div>
<div class="line"><a name="l00058"></a><span class="lineno"><a class="line" href="classstk_1_1Socket.html#a2558d3b2001c07eeae9d3e301df399fe"> 58</a></span>  <a class="code" href="classstk_1_1Socket.html#a2558d3b2001c07eeae9d3e301df399fe">Socket</a>();</div>
<div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  </div>
<div class="line"><a name="l00061"></a><span class="lineno"><a class="line" href="classstk_1_1Socket.html#a8fb79fcfba5d1438575e0fb933f8b37b"> 61</a></span>  <span class="keyword">virtual</span> <a class="code" href="classstk_1_1Socket.html#a8fb79fcfba5d1438575e0fb933f8b37b">~Socket</a>();</div>
<div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  </div>
<div class="line"><a name="l00064"></a><span class="lineno"><a class="line" href="classstk_1_1Socket.html#a816c3dfae2549db692944042821d6019"> 64</a></span>  <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classstk_1_1Socket.html#a816c3dfae2549db692944042821d6019">close</a>( <span class="keywordtype">int</span> socket );</div>
<div class="line"><a name="l00065"></a><span class="lineno"> 65</span>  </div>
<div class="line"><a name="l00067"></a><span class="lineno"><a class="line" href="classstk_1_1Socket.html#a7dd9feabd5da4b1a7689b9debb3c75fb"> 67</a></span>  <span class="keywordtype">int</span> <a class="code" href="classstk_1_1Socket.html#a7dd9feabd5da4b1a7689b9debb3c75fb">id</a>( <span class="keywordtype">void</span> )<span class="keyword"> const </span>{ <span class="keywordflow">return</span> soket_; };</div>
<div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  </div>
<div class="line"><a name="l00070"></a><span class="lineno"><a class="line" href="classstk_1_1Socket.html#a1eeebb0e5e1f885658bd3644ec9a5e33"> 70</a></span>  <span class="keywordtype">int</span> <a class="code" href="classstk_1_1Socket.html#a1eeebb0e5e1f885658bd3644ec9a5e33">port</a>( <span class="keywordtype">void</span> )<span class="keyword"> const </span>{ <span class="keywordflow">return</span> port_; };</div>
<div class="line"><a name="l00071"></a><span class="lineno"> 71</span>  </div>
<div class="line"><a name="l00073"></a><span class="lineno"><a class="line" href="classstk_1_1Socket.html#a61375099d0d0811bf79c894587cc3724"> 73</a></span>  <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classstk_1_1Socket.html#a61375099d0d0811bf79c894587cc3724">isValid</a>( <span class="keywordtype">int</span> socket ) { <span class="keywordflow">return</span> socket != -1; };</div>
<div class="line"><a name="l00074"></a><span class="lineno"> 74</span>  </div>
<div class="line"><a name="l00076"></a><span class="lineno"><a class="line" href="classstk_1_1Socket.html#a12f0abb799fbf7d5d2ee6364627cb6ac"> 76</a></span>  <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classstk_1_1Socket.html#a12f0abb799fbf7d5d2ee6364627cb6ac">setBlocking</a>( <span class="keywordtype">int</span> socket, <span class="keywordtype">bool</span> enable );</div>
<div class="line"><a name="l00077"></a><span class="lineno"> 77</span>  </div>
<div class="line"><a name="l00079"></a><span class="lineno"><a class="line" href="classstk_1_1Socket.html#a7938202181552306d0ea74c6c04abf4a"> 79</a></span>  <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classstk_1_1Socket.html#a7938202181552306d0ea74c6c04abf4a">writeBuffer</a>(<span class="keyword">const</span> <span class="keywordtype">void</span> *buffer, <span class="keywordtype">long</span> bufferSize, <span class="keywordtype">int</span> flags = 0) = 0;</div>
<div class="line"><a name="l00080"></a><span class="lineno"> 80</span>  </div>
<div class="line"><a name="l00082"></a><span class="lineno"><a class="line" href="classstk_1_1Socket.html#aa99d0f4e1c0ebae768a9f3f124364906"> 82</a></span>  <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classstk_1_1Socket.html#aa99d0f4e1c0ebae768a9f3f124364906">readBuffer</a>(<span class="keywordtype">void</span> *buffer, <span class="keywordtype">long</span> bufferSize, <span class="keywordtype">int</span> flags = 0) = 0;</div>
<div class="line"><a name="l00083"></a><span class="lineno"> 83</span>  </div>
<div class="line"><a name="l00085"></a><span class="lineno"><a class="line" href="classstk_1_1Socket.html#aa9687b9332995717aa95022a133254a2"> 85</a></span>  <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="classstk_1_1Socket.html#aa9687b9332995717aa95022a133254a2">writeBuffer</a>(<span class="keywordtype">int</span> socket, <span class="keyword">const</span> <span class="keywordtype">void</span> *buffer, <span class="keywordtype">long</span> bufferSize, <span class="keywordtype">int</span> flags );</div>
<div class="line"><a name="l00086"></a><span class="lineno"> 86</span>  </div>
<div class="line"><a name="l00088"></a><span class="lineno"><a class="line" href="classstk_1_1Socket.html#a742cdc0d2ef4aed91c61f87be67cb38e"> 88</a></span>  <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="classstk_1_1Socket.html#a742cdc0d2ef4aed91c61f87be67cb38e">readBuffer</a>(<span class="keywordtype">int</span> socket, <span class="keywordtype">void</span> *buffer, <span class="keywordtype">long</span> bufferSize, <span class="keywordtype">int</span> flags );</div>
<div class="line"><a name="l00089"></a><span class="lineno"> 89</span>  </div>
<div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  <span class="keyword">protected</span>:</div>
<div class="line"><a name="l00091"></a><span class="lineno"> 91</span>  </div>
<div class="line"><a name="l00092"></a><span class="lineno"> 92</span>  <span class="keywordtype">int</span> soket_;</div>
<div class="line"><a name="l00093"></a><span class="lineno"> 93</span>  <span class="keywordtype">int</span> port_;</div>
<div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  </div>
<div class="line"><a name="l00095"></a><span class="lineno"> 95</span> };</div>
<div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  </div>
<div class="line"><a name="l00097"></a><span class="lineno"> 97</span> } <span class="comment">// stk namespace</span></div>
<div class="line"><a name="l00098"></a><span class="lineno"> 98</span>  </div>
<div class="line"><a name="l00099"></a><span class="lineno"> 99</span> <span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00100"></a><span class="lineno"> 100</span> <span class="preprocessor">#endif</span></div>
<div class="ttc" id="aclassstk_1_1Socket_html"><div class="ttname"><a href="classstk_1_1Socket.html">stk::Socket</a></div><div class="ttdoc">STK internet socket abstract base class.</div><div class="ttdef"><b>Definition:</b> Socket.h:49</div></div>
<div class="ttc" id="aclassstk_1_1Socket_html_a12f0abb799fbf7d5d2ee6364627cb6ac"><div class="ttname"><a href="classstk_1_1Socket.html#a12f0abb799fbf7d5d2ee6364627cb6ac">stk::Socket::setBlocking</a></div><div class="ttdeci">static void setBlocking(int socket, bool enable)</div><div class="ttdoc">If enable = false, the socket is set to non-blocking mode. When first created, sockets are by default...</div></div>
<div class="ttc" id="aclassstk_1_1Socket_html_a1eeebb0e5e1f885658bd3644ec9a5e33"><div class="ttname"><a href="classstk_1_1Socket.html#a1eeebb0e5e1f885658bd3644ec9a5e33">stk::Socket::port</a></div><div class="ttdeci">int port(void) const</div><div class="ttdoc">Return the socket port number.</div><div class="ttdef"><b>Definition:</b> Socket.h:70</div></div>
<div class="ttc" id="aclassstk_1_1Socket_html_a2558d3b2001c07eeae9d3e301df399fe"><div class="ttname"><a href="classstk_1_1Socket.html#a2558d3b2001c07eeae9d3e301df399fe">stk::Socket::Socket</a></div><div class="ttdeci">Socket()</div><div class="ttdoc">Class constructor.</div></div>
<div class="ttc" id="aclassstk_1_1Socket_html_a61375099d0d0811bf79c894587cc3724"><div class="ttname"><a href="classstk_1_1Socket.html#a61375099d0d0811bf79c894587cc3724">stk::Socket::isValid</a></div><div class="ttdeci">static bool isValid(int socket)</div><div class="ttdoc">Returns true if the socket descriptor is valid.</div><div class="ttdef"><b>Definition:</b> Socket.h:73</div></div>
<div class="ttc" id="aclassstk_1_1Socket_html_a742cdc0d2ef4aed91c61f87be67cb38e"><div class="ttname"><a href="classstk_1_1Socket.html#a742cdc0d2ef4aed91c61f87be67cb38e">stk::Socket::readBuffer</a></div><div class="ttdeci">static int readBuffer(int socket, void *buffer, long bufferSize, int flags)</div><div class="ttdoc">Read a buffer via the specified socket. Returns the number of bytes read or -1 if an error occurs.</div></div>
<div class="ttc" id="aclassstk_1_1Socket_html_a7938202181552306d0ea74c6c04abf4a"><div class="ttname"><a href="classstk_1_1Socket.html#a7938202181552306d0ea74c6c04abf4a">stk::Socket::writeBuffer</a></div><div class="ttdeci">virtual int writeBuffer(const void *buffer, long bufferSize, int flags=0)=0</div><div class="ttdoc">Write a buffer over the socket connection. Returns the number of bytes written or -1 if an error occu...</div></div>
<div class="ttc" id="aclassstk_1_1Socket_html_a7dd9feabd5da4b1a7689b9debb3c75fb"><div class="ttname"><a href="classstk_1_1Socket.html#a7dd9feabd5da4b1a7689b9debb3c75fb">stk::Socket::id</a></div><div class="ttdeci">int id(void) const</div><div class="ttdoc">Return the socket descriptor.</div><div class="ttdef"><b>Definition:</b> Socket.h:67</div></div>
<div class="ttc" id="aclassstk_1_1Socket_html_a816c3dfae2549db692944042821d6019"><div class="ttname"><a href="classstk_1_1Socket.html#a816c3dfae2549db692944042821d6019">stk::Socket::close</a></div><div class="ttdeci">static void close(int socket)</div><div class="ttdoc">Close the socket.</div></div>
<div class="ttc" id="aclassstk_1_1Socket_html_a8fb79fcfba5d1438575e0fb933f8b37b"><div class="ttname"><a href="classstk_1_1Socket.html#a8fb79fcfba5d1438575e0fb933f8b37b">stk::Socket::~Socket</a></div><div class="ttdeci">virtual ~Socket()</div><div class="ttdoc">Class destructor.</div></div>
<div class="ttc" id="aclassstk_1_1Socket_html_aa9687b9332995717aa95022a133254a2"><div class="ttname"><a href="classstk_1_1Socket.html#aa9687b9332995717aa95022a133254a2">stk::Socket::writeBuffer</a></div><div class="ttdeci">static int writeBuffer(int socket, const void *buffer, long bufferSize, int flags)</div><div class="ttdoc">Write a buffer via the specified socket. Returns the number of bytes written or -1 if an error occurs...</div></div>
<div class="ttc" id="aclassstk_1_1Socket_html_aa99d0f4e1c0ebae768a9f3f124364906"><div class="ttname"><a href="classstk_1_1Socket.html#aa99d0f4e1c0ebae768a9f3f124364906">stk::Socket::readBuffer</a></div><div class="ttdeci">virtual int readBuffer(void *buffer, long bufferSize, int flags=0)=0</div><div class="ttdoc">Read an input buffer, up to length bufferSize. Returns the number of bytes read or -1 if an error occ...</div></div>
<div class="ttc" id="aclassstk_1_1Stk_html"><div class="ttname"><a href="classstk_1_1Stk.html">stk::Stk</a></div><div class="ttdoc">STK base class.</div><div class="ttdef"><b>Definition:</b> Stk.h:144</div></div>
<div class="ttc" id="anamespacestk_html"><div class="ttname"><a href="namespacestk.html">stk</a></div><div class="ttdoc">The STK namespace.</div><div class="ttdef"><b>Definition:</b> ADSR.h:8</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1
</small></address>
</body>
</html>