This file is indexed.

/usr/share/doc/libqb-dev/html/tcpserver_8c-example.html is in libqb-doc 1.0.1-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://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.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>libqb: tcpserver.c</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="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.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">libqb
   &#160;<span id="projectnumber">1.0.1</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">tcpserver.c</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * Copyright (c) 2011 Red Hat, Inc.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * All rights reserved.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * Author: Angus Salkeld &lt;asalkeld@redhat.com&gt;</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * libqb is free software: you can redistribute it and/or modify</span></div><div class="line"><span class="comment"> * it under the terms of the GNU Lesser General Public License as published by</span></div><div class="line"><span class="comment"> * the Free Software Foundation, either version 2.1 of the License, or</span></div><div class="line"><span class="comment"> * (at your option) any later version.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * libqb is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div><div class="line"><span class="comment"> * GNU Lesser General Public License for more details.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * You should have received a copy of the GNU Lesser General Public License</span></div><div class="line"><span class="comment"> * along with libqb.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="preprocessor">#include &quot;os_base.h&quot;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#ifdef HAVE_NETINET_IN_H</span></div><div class="line"><span class="preprocessor">#include &lt;netinet/in.h&gt;</span></div><div class="line"><span class="preprocessor">#endif </span><span class="comment">/* HAVE_NETINET_IN_H */</span><span class="preprocessor"></span></div><div class="line"><span class="preprocessor">#ifdef HAVE_ARPA_INET_H</span></div><div class="line"><span class="preprocessor">#include &lt;arpa/inet.h&gt;</span></div><div class="line"><span class="preprocessor">#endif </span><span class="comment">/* HAVE_ARPA_INET_H */</span><span class="preprocessor"></span></div><div class="line"><span class="preprocessor">#ifdef HAVE_NETDB_H</span></div><div class="line"><span class="preprocessor">#include &lt;netdb.h&gt;</span></div><div class="line"><span class="preprocessor">#endif </span><span class="comment">/* HAVE_NETDB_H */</span><span class="preprocessor"></span></div><div class="line"><span class="preprocessor">#ifdef HAVE_SYS_SOCKET_H</span></div><div class="line"><span class="preprocessor">#include &lt;sys/socket.h&gt;</span></div><div class="line"><span class="preprocessor">#endif </span><span class="comment">/* HAVE_SYS_SOCKET_H */</span><span class="preprocessor"></span></div><div class="line"><span class="preprocessor">#ifdef HAVE_SYS_POLL_H</span></div><div class="line"><span class="preprocessor">#include &lt;sys/poll.h&gt;</span></div><div class="line"><span class="preprocessor">#endif </span><span class="comment">/* HAVE_SYS_POLL_H */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="qbdefs_8h.html">qb/qbdefs.h</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="qbloop_8h.html">qb/qbloop.h</a>&gt;</span></div><div class="line"></div><div class="line"><span class="keyword">static</span> int32_t</div><div class="line">sock_read_fn(int32_t fd, int32_t revents, <span class="keywordtype">void</span> *data)</div><div class="line">{</div><div class="line">        <span class="keywordtype">char</span> recv_data[1024];</div><div class="line">        <span class="keywordtype">char</span> send_data[1024];</div><div class="line">        <span class="keywordtype">int</span> bytes_recieved;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (revents &amp; POLLHUP) {</div><div class="line">                printf(<span class="stringliteral">&quot;Socket %d peer closed\n&quot;</span>, fd);</div><div class="line">                close(fd);</div><div class="line">                <span class="keywordflow">return</span> <a name="a0"></a><a class="code" href="qbdefs_8h.html#a3adfa550658b3082a867536d5bcb87d8">QB_FALSE</a>;</div><div class="line">        }</div><div class="line"></div><div class="line">        bytes_recieved = recv(fd, recv_data, 1024, 0);</div><div class="line">        <span class="keywordflow">if</span> (bytes_recieved &lt; 0) {</div><div class="line">                perror(<span class="stringliteral">&quot;recv&quot;</span>);</div><div class="line">                <span class="keywordflow">return</span> <a name="a1"></a><a class="code" href="qbdefs_8h.html#aa53d378f26033634af24bd526090073e">QB_TRUE</a>;</div><div class="line">        }</div><div class="line">        recv_data[bytes_recieved] = <span class="charliteral">&#39;\0&#39;</span>;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (strcmp(recv_data, <span class="stringliteral">&quot;q&quot;</span>) == 0 || strcmp(recv_data, <span class="stringliteral">&quot;Q&quot;</span>) == 0) {</div><div class="line">                printf(<span class="stringliteral">&quot;Quiting connection from socket %d\n&quot;</span>, fd);</div><div class="line">                close(fd);</div><div class="line">                <span class="keywordflow">return</span> <a class="code" href="qbdefs_8h.html#a3adfa550658b3082a867536d5bcb87d8">QB_FALSE</a>;</div><div class="line">        } <span class="keywordflow">else</span> {</div><div class="line">                printf(<span class="stringliteral">&quot;Recieved: %s\n&quot;</span>, recv_data);</div><div class="line">                snprintf(send_data, 1024, <span class="stringliteral">&quot;ACK %d bytes&quot;</span>, bytes_recieved);</div><div class="line">                <span class="keywordflow">if</span> (send(fd, send_data, strlen(send_data), 0) &lt; 0) {</div><div class="line">                        close(fd);</div><div class="line">                        <span class="keywordflow">return</span> <a class="code" href="qbdefs_8h.html#a3adfa550658b3082a867536d5bcb87d8">QB_FALSE</a>;</div><div class="line">                }</div><div class="line">        }</div><div class="line">        <span class="keywordflow">return</span> <a class="code" href="qbdefs_8h.html#aa53d378f26033634af24bd526090073e">QB_TRUE</a>;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> int32_t</div><div class="line">sock_accept_fn(int32_t fd, int32_t revents, <span class="keywordtype">void</span> *data)</div><div class="line">{</div><div class="line">        <span class="keyword">struct </span>sockaddr_in client_addr;</div><div class="line">        <a class="code" href="qbloop_8h.html#aa6a331b04a08da926684e21c6fe25c9c">qb_loop_t</a> *ml = (<a class="code" href="qbloop_8h.html#aa6a331b04a08da926684e21c6fe25c9c">qb_loop_t</a> *) data;</div><div class="line">        socklen_t sin_size = <span class="keyword">sizeof</span>(<span class="keyword">struct </span>sockaddr_in);</div><div class="line">        <span class="keywordtype">int</span> connected = accept(fd, (<span class="keyword">struct</span> sockaddr *)&amp;client_addr, &amp;sin_size);</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (connected &lt; 0) {</div><div class="line">                perror(<span class="stringliteral">&quot;accept&quot;</span>);</div><div class="line">                <span class="keywordflow">return</span> <a class="code" href="qbdefs_8h.html#aa53d378f26033634af24bd526090073e">QB_TRUE</a>;</div><div class="line">        }</div><div class="line">        printf(<span class="stringliteral">&quot;I got a connection from (%s , %d)\n&quot;</span>,</div><div class="line">               inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));</div><div class="line"></div><div class="line">        <a name="a2"></a><a class="code" href="qbloop_8h.html#aa94a27975c1097d8adf866060c8b30fe">qb_loop_poll_add</a>(ml, <a name="a3"></a><a class="code" href="qbloop_8h.html#a89b8ba9120c5ed538b915c1213762ac8a6012cd302e8e1fbe20041269edb126ac">QB_LOOP_MED</a>, connected, POLLIN, ml, sock_read_fn);</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> <a class="code" href="qbdefs_8h.html#aa53d378f26033634af24bd526090073e">QB_TRUE</a>;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> int32_t</div><div class="line">please_exit_fn(int32_t rsignal, <span class="keywordtype">void</span> *data)</div><div class="line">{</div><div class="line">        <a class="code" href="qbloop_8h.html#aa6a331b04a08da926684e21c6fe25c9c">qb_loop_t</a> *ml = (<a class="code" href="qbloop_8h.html#aa6a331b04a08da926684e21c6fe25c9c">qb_loop_t</a> *) data;</div><div class="line"></div><div class="line">        printf(<span class="stringliteral">&quot;Shutting down at you request...\n&quot;</span>);</div><div class="line">        <a name="a4"></a><a class="code" href="qbloop_8h.html#a4e2462d99ca201b083d8c8c7d761460d">qb_loop_stop</a>(ml);</div><div class="line">        <span class="keywordflow">return</span> <a class="code" href="qbdefs_8h.html#a3adfa550658b3082a867536d5bcb87d8">QB_FALSE</a>;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span></div><div class="line">main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> sock;</div><div class="line">        <span class="keywordtype">int</span> true_opt = 1;</div><div class="line">        <span class="keyword">struct </span>sockaddr_in server_addr;</div><div class="line">        <a class="code" href="qbloop_8h.html#aa6a331b04a08da926684e21c6fe25c9c">qb_loop_t</a> *ml = <a name="a5"></a><a class="code" href="qbloop_8h.html#a3c8591d13b2666d9986cd2b0cbbbc8c6">qb_loop_create</a>();</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {</div><div class="line">                perror(<span class="stringliteral">&quot;Socket&quot;</span>);</div><div class="line">                exit(1);</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (setsockopt(sock,</div><div class="line">                       SOL_SOCKET,</div><div class="line">                       SO_REUSEADDR, &amp;true_opt, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) == -1) {</div><div class="line">                perror(<span class="stringliteral">&quot;Setsockopt&quot;</span>);</div><div class="line">                exit(1);</div><div class="line">        }</div><div class="line"></div><div class="line">        server_addr.sin_family = AF_INET;</div><div class="line">        server_addr.sin_port = htons(5000);</div><div class="line">        server_addr.sin_addr.s_addr = INADDR_ANY;</div><div class="line">        bzero(&amp;(server_addr.sin_zero), 8);</div><div class="line"></div><div class="line">        printf(<span class="stringliteral">&quot;TCPServer binding to port 5000\n&quot;</span>);</div><div class="line">        <span class="keywordflow">if</span> (bind(sock,</div><div class="line">                 (<span class="keyword">struct</span> sockaddr *)&amp;server_addr,</div><div class="line">                 <span class="keyword">sizeof</span>(<span class="keyword">struct</span> sockaddr)) == -1) {</div><div class="line">                perror(<span class="stringliteral">&quot;Unable to bind&quot;</span>);</div><div class="line">                exit(1);</div><div class="line">        }</div><div class="line"></div><div class="line">        printf(<span class="stringliteral">&quot;TCPServer Waiting for client on port 5000\n&quot;</span>);</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (listen(sock, 5) == -1) {</div><div class="line">                perror(<span class="stringliteral">&quot;Listen&quot;</span>);</div><div class="line">                exit(1);</div><div class="line">        }</div><div class="line"></div><div class="line">        <a class="code" href="qbloop_8h.html#aa94a27975c1097d8adf866060c8b30fe">qb_loop_poll_add</a>(ml, <a class="code" href="qbloop_8h.html#a89b8ba9120c5ed538b915c1213762ac8a6012cd302e8e1fbe20041269edb126ac">QB_LOOP_MED</a>, sock, POLLIN, ml, sock_accept_fn);</div><div class="line"></div><div class="line">        <a name="a6"></a><a class="code" href="qbloop_8h.html#a3e699e0d462fa4c70d3f827847c10f87">qb_loop_signal_add</a>(ml, <a name="a7"></a><a class="code" href="qbloop_8h.html#a89b8ba9120c5ed538b915c1213762ac8a081d525f719c01b95481dbc68fe1a3df">QB_LOOP_HIGH</a>, SIGINT, ml, please_exit_fn, NULL);</div><div class="line">        <a name="a8"></a><a class="code" href="qbloop_8h.html#abdc517fe737f9e90bc768ff728d5f6a9">qb_loop_run</a>(ml);</div><div class="line"></div><div class="line">        close(sock);</div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>