Sophie

Sophie

distrib > Fedora > 13 > i386 > by-pkgid > 3ef085c66d4a743f8dec260630a0b19c > files > 322

pcsc-lite-doc-1.5.5-4.fc13.noarch.rpm

<!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"/>
<title>pcsc-lite: winscard_msg_srv.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.2-20100208 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</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>Globals</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="dir_c68a5dfdca54003c765e303a18006edb.html">src</a>
  </div>
</div>
<div class="contents">
<h1>winscard_msg_srv.c</h1><a href="winscard__msg__srv_8c.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"> * MUSCLE SmartCard Development ( http://www.linuxnet.com )</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2001-2004</span>
<a name="l00005"></a>00005 <span class="comment"> *  David Corcoran &lt;corcoran@linuxnet.com&gt;</span>
<a name="l00006"></a>00006 <span class="comment"> *  Damien Sauveron &lt;damien.sauveron@labri.fr&gt;</span>
<a name="l00007"></a>00007 <span class="comment"> *  Ludoic Rousseau &lt;ludovic.rousseau@free.fr&gt;</span>
<a name="l00008"></a>00008 <span class="comment"> *</span>
<a name="l00009"></a>00009 <span class="comment"> * $Id: winscard_msg_srv.c 3260 2009-01-02 15:19:59Z rousseau $</span>
<a name="l00010"></a>00010 <span class="comment"> */</span>
<a name="l00011"></a>00011 
<a name="l00021"></a>00021 <span class="preprocessor">#include &quot;config.h&quot;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;fcntl.h&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;sys/types.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;sys/stat.h&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;sys/socket.h&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;sys/time.h&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;sys/un.h&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;sys/ioctl.h&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;errno.h&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#ifdef HAVE_SYS_FILIO_H</span>
<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#include &lt;sys/filio.h&gt;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#endif</span>
<a name="l00037"></a>00037 <span class="preprocessor"></span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &quot;misc.h&quot;</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &quot;<a class="code" href="pcscd_8h.html" title="This keeps a list of defines for pcsc-lite.">pcscd.h</a>&quot;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &quot;<a class="code" href="winscard_8h.html" title="This handles smartcard reader communications.">winscard.h</a>&quot;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &quot;<a class="code" href="debuglog_8h.html" title="This handles debugging.">debuglog.h</a>&quot;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &quot;<a class="code" href="winscard__msg_8h.html" title="This defines some structures and #defines to be used over the transport layer.">winscard_msg.h</a>&quot;</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &quot;<a class="code" href="sys__generic_8h.html" title="This handles abstract system level calls.">sys_generic.h</a>&quot;</span>
<a name="l00044"></a>00044 
<a name="l00048"></a><a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c">00048</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c" title="Socket to a file, used for clients-server comminication.">commonSocket</a> = 0;
<a name="l00049"></a>00049 <span class="keyword">extern</span> <span class="keywordtype">char</span> AraKiri;
<a name="l00050"></a>00050 <span class="keyword">extern</span> <span class="keywordtype">char</span> ReCheckSerialReaders;
<a name="l00051"></a>00051 
<a name="l00052"></a>00052 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *CommandsText[] = {
<a name="l00053"></a>00053     <span class="stringliteral">&quot;CMD_VERSION&quot;</span>,  <span class="comment">/* mtype = 0xF8 and command = 0x00 */</span>
<a name="l00054"></a>00054     <span class="stringliteral">&quot;ESTABLISH_CONTEXT&quot;</span>,    <span class="comment">/* mtype = 0xF1 */</span>
<a name="l00055"></a>00055     <span class="stringliteral">&quot;RELEASE_CONTEXT&quot;</span>,
<a name="l00056"></a>00056     <span class="stringliteral">&quot;LIST_READERS&quot;</span>,
<a name="l00057"></a>00057     <span class="stringliteral">&quot;CONNECT&quot;</span>,
<a name="l00058"></a>00058     <span class="stringliteral">&quot;RECONNECT&quot;</span>,
<a name="l00059"></a>00059     <span class="stringliteral">&quot;DISCONNECT&quot;</span>,
<a name="l00060"></a>00060     <span class="stringliteral">&quot;BEGIN_TRANSACTION&quot;</span>,
<a name="l00061"></a>00061     <span class="stringliteral">&quot;END_TRANSACTION&quot;</span>,
<a name="l00062"></a>00062     <span class="stringliteral">&quot;TRANSMIT&quot;</span>,
<a name="l00063"></a>00063     <span class="stringliteral">&quot;CONTROL&quot;</span>,
<a name="l00064"></a>00064     <span class="stringliteral">&quot;STATUS&quot;</span>,
<a name="l00065"></a>00065     <span class="stringliteral">&quot;GET_STATUS_CHANGE&quot;</span>,
<a name="l00066"></a>00066     <span class="stringliteral">&quot;CANCEL&quot;</span>,
<a name="l00067"></a>00067     <span class="stringliteral">&quot;CANCEL_TRANSACTION&quot;</span>,
<a name="l00068"></a>00068     <span class="stringliteral">&quot;GET_ATTRIB&quot;</span>,
<a name="l00069"></a>00069     <span class="stringliteral">&quot;SET_ATTRIB&quot;</span>,
<a name="l00070"></a>00070     <span class="stringliteral">&quot;TRANSMIT_EXTENDED&quot;</span>,
<a name="l00071"></a>00071     <span class="stringliteral">&quot;CONTROL_EXTENDED&quot;</span>,
<a name="l00072"></a>00072     <span class="stringliteral">&quot;NULL&quot;</span>
<a name="l00073"></a>00073 };
<a name="l00074"></a>00074 
<a name="l00087"></a><a class="code" href="winscard__msg__srv_8c.html#a9daf00a9f46d3e86afb2ab1e17470547">00087</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="winscard__msg__srv_8c.html#a9daf00a9f46d3e86afb2ab1e17470547" title="Accepts a Client connection.">SHMProcessCommonChannelRequest</a>(<span class="comment">/*@out@*/</span> uint32_t *pdwClientID)
<a name="l00088"></a>00088 {
<a name="l00089"></a>00089     socklen_t clnt_len;
<a name="l00090"></a>00090     <span class="keywordtype">int</span> new_sock;
<a name="l00091"></a>00091     <span class="keyword">struct </span>sockaddr_un clnt_addr;
<a name="l00092"></a>00092     <span class="keywordtype">int</span> one;
<a name="l00093"></a>00093 
<a name="l00094"></a>00094     clnt_len = <span class="keyword">sizeof</span>(clnt_addr);
<a name="l00095"></a>00095 
<a name="l00096"></a>00096     <span class="keywordflow">if</span> ((new_sock = accept(<a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c" title="Socket to a file, used for clients-server comminication.">commonSocket</a>, (<span class="keyword">struct</span> sockaddr *) &amp;clnt_addr,
<a name="l00097"></a>00097                 &amp;clnt_len)) &lt; 0)
<a name="l00098"></a>00098     {
<a name="l00099"></a>00099         Log2(PCSC_LOG_CRITICAL, <span class="stringliteral">&quot;Accept on common socket: %s&quot;</span>,
<a name="l00100"></a>00100             strerror(errno));
<a name="l00101"></a>00101         <span class="keywordflow">return</span> -1;
<a name="l00102"></a>00102     }
<a name="l00103"></a>00103 
<a name="l00104"></a>00104     *pdwClientID = new_sock;
<a name="l00105"></a>00105 
<a name="l00106"></a>00106     one = 1;
<a name="l00107"></a>00107     <span class="keywordflow">if</span> (ioctl(*pdwClientID, FIONBIO, &amp;one) &lt; 0)
<a name="l00108"></a>00108     {
<a name="l00109"></a>00109         Log2(PCSC_LOG_CRITICAL, <span class="stringliteral">&quot;Error: cannot set socket nonblocking: %s&quot;</span>,
<a name="l00110"></a>00110             strerror(errno));
<a name="l00111"></a>00111         (void)<a class="code" href="sys__generic_8h.html#af10fc153fdf365c3a3001635c065a1c6" title="Opens/creates a file.">SYS_CloseFile</a>(*pdwClientID);
<a name="l00112"></a>00112         *pdwClientID = -1;
<a name="l00113"></a>00113         <span class="keywordflow">return</span> -1;
<a name="l00114"></a>00114     }
<a name="l00115"></a>00115 
<a name="l00116"></a>00116     <span class="keywordflow">return</span> 0;
<a name="l00117"></a>00117 }
<a name="l00118"></a>00118 
<a name="l00133"></a><a class="code" href="winscard__msg__srv_8c.html#a7f73b8df9dc165deb9775d35cff8973d">00133</a> INTERNAL int32_t <a class="code" href="winscard__msg_8h.html#a0c558a68f42842f5e73d529dfc73a2a9" title="Prepares the communication channel used by the server to talk to the clients.">SHMInitializeCommonSegment</a>(<span class="keywordtype">void</span>)
<a name="l00134"></a>00134 {
<a name="l00135"></a>00135     <span class="keyword">static</span> <span class="keyword">struct </span>sockaddr_un serv_adr;
<a name="l00136"></a>00136 
<a name="l00137"></a>00137     <span class="comment">/*</span>
<a name="l00138"></a>00138 <span class="comment">     * Create the common shared connection socket</span>
<a name="l00139"></a>00139 <span class="comment">     */</span>
<a name="l00140"></a>00140     <span class="keywordflow">if</span> ((<a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c" title="Socket to a file, used for clients-server comminication.">commonSocket</a> = socket(AF_UNIX, SOCK_STREAM, 0)) &lt; 0)
<a name="l00141"></a>00141     {
<a name="l00142"></a>00142         Log2(PCSC_LOG_CRITICAL, <span class="stringliteral">&quot;Unable to create common socket: %s&quot;</span>,
<a name="l00143"></a>00143             strerror(errno));
<a name="l00144"></a>00144         <span class="keywordflow">return</span> -1;
<a name="l00145"></a>00145     }
<a name="l00146"></a>00146 
<a name="l00147"></a>00147     serv_adr.sun_family = AF_UNIX;
<a name="l00148"></a>00148     strncpy(serv_adr.sun_path, PCSCLITE_CSOCK_NAME,
<a name="l00149"></a>00149         <span class="keyword">sizeof</span>(serv_adr.sun_path));
<a name="l00150"></a>00150     (void)<a class="code" href="sys__generic_8h.html#af473e9d9a973ce499cdef8ffb87913b2" title="Removes a file.">SYS_RemoveFile</a>(PCSCLITE_CSOCK_NAME);
<a name="l00151"></a>00151 
<a name="l00152"></a>00152     <span class="keywordflow">if</span> (bind(<a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c" title="Socket to a file, used for clients-server comminication.">commonSocket</a>, (<span class="keyword">struct</span> sockaddr *) &amp;serv_adr,
<a name="l00153"></a>00153             <span class="keyword">sizeof</span>(serv_adr.sun_family) + strlen(serv_adr.sun_path) + 1) &lt; 0)
<a name="l00154"></a>00154     {
<a name="l00155"></a>00155         Log2(PCSC_LOG_CRITICAL, <span class="stringliteral">&quot;Unable to bind common socket: %s&quot;</span>,
<a name="l00156"></a>00156             strerror(errno));
<a name="l00157"></a>00157         <a class="code" href="winscard__msg_8c.html#a300df343a6a356eebb24216f787ad8ea" title="Closes the communications channel used by the server to talk to the clients.">SHMCleanupSharedSegment</a>(<a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c" title="Socket to a file, used for clients-server comminication.">commonSocket</a>, PCSCLITE_CSOCK_NAME);
<a name="l00158"></a>00158         <span class="keywordflow">return</span> -1;
<a name="l00159"></a>00159     }
<a name="l00160"></a>00160 
<a name="l00161"></a>00161     <span class="keywordflow">if</span> (listen(<a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c" title="Socket to a file, used for clients-server comminication.">commonSocket</a>, 1) &lt; 0)
<a name="l00162"></a>00162     {
<a name="l00163"></a>00163         Log2(PCSC_LOG_CRITICAL, <span class="stringliteral">&quot;Unable to listen common socket: %s&quot;</span>,
<a name="l00164"></a>00164             strerror(errno));
<a name="l00165"></a>00165         <a class="code" href="winscard__msg_8c.html#a300df343a6a356eebb24216f787ad8ea" title="Closes the communications channel used by the server to talk to the clients.">SHMCleanupSharedSegment</a>(<a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c" title="Socket to a file, used for clients-server comminication.">commonSocket</a>, PCSCLITE_CSOCK_NAME);
<a name="l00166"></a>00166         <span class="keywordflow">return</span> -1;
<a name="l00167"></a>00167     }
<a name="l00168"></a>00168 
<a name="l00169"></a>00169     <span class="comment">/*</span>
<a name="l00170"></a>00170 <span class="comment">     * Chmod the public entry channel</span>
<a name="l00171"></a>00171 <span class="comment">     */</span>
<a name="l00172"></a>00172     (void)SYS_Chmod(PCSCLITE_CSOCK_NAME, S_IRWXO | S_IRWXG | S_IRWXU);
<a name="l00173"></a>00173 
<a name="l00174"></a>00174     <span class="keywordflow">return</span> 0;
<a name="l00175"></a>00175 }
<a name="l00176"></a>00176 
<a name="l00190"></a>00190 <span class="preprocessor">#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)</span>
<a name="l00191"></a>00191 <span class="preprocessor"></span><span class="preprocessor">#define DO_TIMEOUT</span>
<a name="l00192"></a>00192 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00193"></a><a class="code" href="winscard__msg__srv_8c.html#a0bba564b08a9b2044ccd41580d6d7566">00193</a> <span class="preprocessor"></span>INTERNAL int32_t <a class="code" href="winscard__msg_8h.html#a0dcf683dc7824fb581a5aa6fe99f09ce" title="Looks for messages sent by clients.">SHMProcessEventsServer</a>(uint32_t *pdwClientID)
<a name="l00194"></a>00194 {
<a name="l00195"></a>00195     fd_set read_fd;
<a name="l00196"></a>00196     <span class="keywordtype">int</span> selret;
<a name="l00197"></a>00197 <span class="preprocessor">#ifdef DO_TIMEOUT</span>
<a name="l00198"></a>00198 <span class="preprocessor"></span>    <span class="keyword">struct </span>timeval tv;
<a name="l00199"></a>00199 
<a name="l00200"></a>00200     tv.tv_sec = 1;
<a name="l00201"></a>00201     tv.tv_usec = 0;
<a name="l00202"></a>00202 <span class="preprocessor">#endif</span>
<a name="l00203"></a>00203 <span class="preprocessor"></span>
<a name="l00204"></a>00204     FD_ZERO(&amp;read_fd);
<a name="l00205"></a>00205 
<a name="l00206"></a>00206     <span class="comment">/*</span>
<a name="l00207"></a>00207 <span class="comment">     * Set up the bit masks for select</span>
<a name="l00208"></a>00208 <span class="comment">     */</span>
<a name="l00209"></a>00209     FD_SET(<a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c" title="Socket to a file, used for clients-server comminication.">commonSocket</a>, &amp;read_fd);
<a name="l00210"></a>00210 
<a name="l00211"></a>00211     selret = select(<a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c" title="Socket to a file, used for clients-server comminication.">commonSocket</a> + 1, &amp;read_fd, (fd_set *) NULL,
<a name="l00212"></a>00212         (fd_set *) NULL,
<a name="l00213"></a>00213 #ifdef DO_TIMEOUT
<a name="l00214"></a>00214         &amp;tv
<a name="l00215"></a>00215 #<span class="keywordflow">else</span>
<a name="l00216"></a>00216         NULL
<a name="l00217"></a>00217 #endif
<a name="l00218"></a>00218         );
<a name="l00219"></a>00219 
<a name="l00220"></a>00220     <span class="keywordflow">if</span> (selret &lt; 0)
<a name="l00221"></a>00221     {
<a name="l00222"></a>00222         <span class="keywordflow">if</span> (EINTR == errno)
<a name="l00223"></a>00223             <span class="keywordflow">return</span> -2;
<a name="l00224"></a>00224 
<a name="l00225"></a>00225         Log2(PCSC_LOG_CRITICAL, <span class="stringliteral">&quot;Select returns with failure: %s&quot;</span>,
<a name="l00226"></a>00226             strerror(errno));
<a name="l00227"></a>00227         <span class="keywordflow">return</span> -1;
<a name="l00228"></a>00228     }
<a name="l00229"></a>00229 
<a name="l00230"></a>00230     <span class="keywordflow">if</span> (selret == 0)
<a name="l00231"></a>00231         <span class="comment">/* timeout. On *BSD only */</span>
<a name="l00232"></a>00232         <span class="keywordflow">return</span> 2;
<a name="l00233"></a>00233 
<a name="l00234"></a>00234     <span class="comment">/*</span>
<a name="l00235"></a>00235 <span class="comment">     * A common pipe packet has arrived - it could be a new application</span>
<a name="l00236"></a>00236 <span class="comment">     */</span>
<a name="l00237"></a>00237     <span class="keywordflow">if</span> (FD_ISSET(<a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c" title="Socket to a file, used for clients-server comminication.">commonSocket</a>, &amp;read_fd))
<a name="l00238"></a>00238     {
<a name="l00239"></a>00239         Log1(PCSC_LOG_DEBUG, <span class="stringliteral">&quot;Common channel packet arrival&quot;</span>);
<a name="l00240"></a>00240         <span class="keywordflow">if</span> (<a class="code" href="winscard__msg__srv_8c.html#a9daf00a9f46d3e86afb2ab1e17470547" title="Accepts a Client connection.">SHMProcessCommonChannelRequest</a>(pdwClientID) == -1)
<a name="l00241"></a>00241         {
<a name="l00242"></a>00242             Log2(PCSC_LOG_ERROR,
<a name="l00243"></a>00243                 <span class="stringliteral">&quot;error in SHMProcessCommonChannelRequest: %d&quot;</span>, *pdwClientID);
<a name="l00244"></a>00244             <span class="keywordflow">return</span> -1;
<a name="l00245"></a>00245         } <span class="keywordflow">else</span>
<a name="l00246"></a>00246         {
<a name="l00247"></a>00247             Log2(PCSC_LOG_DEBUG,
<a name="l00248"></a>00248                 <span class="stringliteral">&quot;SHMProcessCommonChannelRequest detects: %d&quot;</span>, *pdwClientID);
<a name="l00249"></a>00249             <span class="keywordflow">return</span> 0;
<a name="l00250"></a>00250         }
<a name="l00251"></a>00251     }
<a name="l00252"></a>00252 
<a name="l00253"></a>00253     <span class="keywordflow">return</span> -1;
<a name="l00254"></a>00254 }
<a name="l00255"></a>00255 
<a name="l00261"></a><a class="code" href="winscard__msg__srv_8c.html#a7b9db088df74f87199e70b838298bf6d">00261</a> INTERNAL int32_t <a class="code" href="winscard__msg_8h.html#ab6cab1acc9730e61d9df2069d8902c73" title="Called by ContextThread().">SHMProcessEventsContext</a>(uint32_t dwClientID,
<a name="l00262"></a>00262     <a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">psharedSegmentMsg</a> msgStruct)
<a name="l00263"></a>00263 {
<a name="l00264"></a>00264     fd_set read_fd;
<a name="l00265"></a>00265     <span class="keywordtype">int</span> selret, rv;
<a name="l00266"></a>00266 <span class="preprocessor">#ifdef DO_TIMEOUT</span>
<a name="l00267"></a>00267 <span class="preprocessor"></span>    <span class="keyword">struct </span>timeval tv;
<a name="l00268"></a>00268 
<a name="l00269"></a>00269     tv.tv_sec = 1;
<a name="l00270"></a>00270     tv.tv_usec = 0;
<a name="l00271"></a>00271 <span class="preprocessor">#endif</span>
<a name="l00272"></a>00272 <span class="preprocessor"></span>
<a name="l00273"></a>00273     FD_ZERO(&amp;read_fd);
<a name="l00274"></a>00274     FD_SET(dwClientID, &amp;read_fd);
<a name="l00275"></a>00275 
<a name="l00276"></a>00276     selret = select(dwClientID + 1, &amp;read_fd, (fd_set *) NULL,
<a name="l00277"></a>00277         (fd_set *) NULL,
<a name="l00278"></a>00278 #ifdef DO_TIMEOUT
<a name="l00279"></a>00279         &amp;tv
<a name="l00280"></a>00280 #<span class="keywordflow">else</span>
<a name="l00281"></a>00281         NULL
<a name="l00282"></a>00282 #endif
<a name="l00283"></a>00283         );
<a name="l00284"></a>00284 
<a name="l00285"></a>00285     <span class="keywordflow">if</span> (selret &lt; 0)
<a name="l00286"></a>00286     {
<a name="l00287"></a>00287         Log2(PCSC_LOG_ERROR, <span class="stringliteral">&quot;select returns with failure: %s&quot;</span>,
<a name="l00288"></a>00288             strerror(errno));
<a name="l00289"></a>00289         <span class="keywordflow">return</span> -1;
<a name="l00290"></a>00290     }
<a name="l00291"></a>00291 
<a name="l00292"></a>00292     <span class="keywordflow">if</span> (selret == 0)
<a name="l00293"></a>00293         <span class="comment">/* timeout */</span>
<a name="l00294"></a>00294         <span class="keywordflow">return</span> 2;
<a name="l00295"></a>00295 
<a name="l00296"></a>00296     <span class="keywordflow">if</span> (FD_ISSET(dwClientID, &amp;read_fd))
<a name="l00297"></a>00297     {
<a name="l00298"></a>00298         <span class="comment">/*</span>
<a name="l00299"></a>00299 <span class="comment">         * Return the current handle</span>
<a name="l00300"></a>00300 <span class="comment">         */</span>
<a name="l00301"></a>00301         rv = <a class="code" href="winscard__msg_8c.html#a79ad4835c2384316592152d320eef49a" title="Called by the Client to get the reponse from the server or vice-versa.">SHMMessageReceive</a>(msgStruct, <span class="keyword">sizeof</span>(*msgStruct), dwClientID,
<a name="l00302"></a>00302                        <a class="code" href="pcscd_8h.html#a50c0e6f51672902e9bf5d8537d132be9" title="Attempts to reach cl.">PCSCLITE_SERVER_ATTEMPTS</a>);
<a name="l00303"></a>00303 
<a name="l00304"></a>00304         <span class="keywordflow">if</span> (rv == -1)
<a name="l00305"></a>00305         {   <span class="comment">/* The client has died */</span>
<a name="l00306"></a>00306             Log2(PCSC_LOG_DEBUG, <span class="stringliteral">&quot;Client has disappeared: %d&quot;</span>, dwClientID);
<a name="l00307"></a>00307             msgStruct-&gt;mtype = CMD_CLIENT_DIED;
<a name="l00308"></a>00308             msgStruct-&gt;command = 0;
<a name="l00309"></a>00309             (void)<a class="code" href="sys__generic_8h.html#af10fc153fdf365c3a3001635c065a1c6" title="Opens/creates a file.">SYS_CloseFile</a>(dwClientID);
<a name="l00310"></a>00310 
<a name="l00311"></a>00311             <span class="keywordflow">return</span> 0;
<a name="l00312"></a>00312         }
<a name="l00313"></a>00313 
<a name="l00314"></a>00314         <span class="comment">/*</span>
<a name="l00315"></a>00315 <span class="comment">         * Set the identifier handle</span>
<a name="l00316"></a>00316 <span class="comment">         */</span>
<a name="l00317"></a>00317         Log3(PCSC_LOG_DEBUG, <span class="stringliteral">&quot;command %s received by client %d&quot;</span>, CommandsText[msgStruct-&gt;command], dwClientID);
<a name="l00318"></a>00318         <span class="keywordflow">return</span> 1;
<a name="l00319"></a>00319     }
<a name="l00320"></a>00320 
<a name="l00321"></a>00321     <span class="keywordflow">return</span> -1;
<a name="l00322"></a>00322 }
<a name="l00323"></a>00323 
</pre></div></div>
<hr class="footer"/><address style="text-align: right;"><small>Generated by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2-20100208 </small></address>
</body>
</html>