~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/network-blockingfortuneclient.html

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
<!DOCTYPE html
3
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
 
<!-- /fasttmp/mkdist-qt-4.5.2-1245473805/qt-x11-opensource-src-4.5.2/doc/src/examples/blockingfortuneclient.qdoc -->
 
5
<!-- blockingfortuneclient.qdoc -->
6
6
<head>
7
 
  <title>Qt 4.5: Blocking Fortune Client Example</title>
 
7
  <title>Qt 4.6: Blocking Fortune Client Example</title>
8
8
  <link href="classic.css" rel="stylesheet" type="text/css" />
9
9
</head>
10
10
<body>
11
11
<table border="0" cellpadding="0" cellspacing="0" width="100%">
12
12
<tr>
13
 
<td align="left" valign="top" width="32"><a href="http://qtsoftware.com/products/qt"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
14
 
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="namespaces.html"><font color="#004faf">All&nbsp;Namespaces</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
15
 
<td align="right" valign="top" width="230"></td></tr></table><h1 class="title">Blocking Fortune Client Example<br /><span class="subtitle"></span>
 
13
<td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
 
14
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">All&nbsp;Functions</font></a>&nbsp;&middot; <a href="overviews.html"><font color="#004faf">Overviews</font></a></td><td class="searchBar" align="right" valign="center"><form action="http://www.google.com/cse" id="cse-search-box"><div><input type="hidden" name="cx" value="000136343326384750312:dhbxnqlakyu" /><input type="hidden" name="ie" value="UTF-8" /><input type="text" name="q" size="31" /><input type="submit" name="sa" value="Search" /></div></form></td>
 
15
</tr></table><h1 class="title">Blocking Fortune Client Example<br /><span class="subtitle"></span>
16
16
</h1>
17
17
<p>Files:</p>
18
18
<ul>
73
73
     QString serverName = hostName;
74
74
     quint16 serverPort = port;
75
75
     mutex.unlock();</pre>
76
 
<p>In the run() function, we start by acquiring the mutex lock, fetching the host name and port from the member data, and then releasing the lock again. The case that we are protecting ourselves against is that <tt>requestNewFortune()</tt> could be called at the same time as we are fetching this data. <a href="qstring.html">QString</a> is <a href="threads.html#reentrant">reentrant</a> but <i>not</i> <a href="threads.html#thread-safe">thread-safe</a>, and we must also avoid the unlikely risk of reading the host name from one request, and port of another. And as you might have guessed, FortuneThread can only handle one request at a time.</p>
 
76
<p>In the run() function, we start by acquiring the mutex lock, fetching the host name and port from the member data, and then releasing the lock again. The case that we are protecting ourselves against is that <tt>requestNewFortune()</tt> could be called at the same time as we are fetching this data. <a href="qstring.html">QString</a> is <a href="threads-reentrancy.html#reentrant">reentrant</a> but <i>not</i> <a href="threads-reentrancy.html#thread-safe">thread-safe</a>, and we must also avoid the unlikely risk of reading the host name from one request, and port of another. And as you might have guessed, FortuneThread can only handle one request at a time.</p>
77
77
<p>The run() function now enters a loop:</p>
78
78
<pre>     while (!quit) {
79
79
         const int Timeout = 5 * 1000;
190
190
<p>See also <a href="network-fortuneclient.html">Fortune Client Example</a> and <a href="network-fortuneserver.html">Fortune Server Example</a>.</p>
191
191
<p /><address><hr /><div align="center">
192
192
<table width="100%" cellspacing="0" border="0"><tr class="address">
193
 
<td width="30%" align="left">Copyright &copy; 2009 Nokia Corporation and/or its subsidiary(-ies)</td>
194
 
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
195
 
<td width="30%" align="right"><div align="right">Qt 4.5.2</div></td>
196
 
</tr></table></div></address></body>
 
193
<td width="40%" align="left">Copyright &copy; 2009 Nokia Corporation and/or its subsidiary(-ies)</td>
 
194
<td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
195
<td width="40%" align="right"><div align="right">Qt 4.6.0</div></td>
 
196
<script type="text/javascript" src="http://www.google.com/jsapi"></script><script type="text/javascript">google.load("elements", "1", {packages: "transliteration"});</script><script type="text/javascript" src="http://www.google.com/coop/cse/t13n?form=cse-search-box&t13n_langs=en"></script><script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script></tr></table></div></address></body>
197
197
</html>