Logo Search packages:      
Sourcecode: pcsc-lite version File versions  Download package

LONG SCardReleaseContext ( SCARDCONTEXT  hContext)

Destroys a communication context to the PC/SC Resource Manager. This must be the last function called in a PC/SC application.

Parameters:
[in]hContextConnection context to be closed.
Returns:
Connection status.
Return values:
SCARD_S_SUCCESSSuccessful (SCARD_S_SUCCESS)
SCARD_E_NO_SERVICEThe server is not running (SCARD_E_NO_SERVICE)
SCARD_E_INVALID_HANDLEInvalid hContext handle (SCARD_E_INVALID_HANDLE)
SCARD_F_COMM_ERRORAn internal communications error has been detected (SCARD_F_COMM_ERROR)
 SCARDCONTEXT hContext;
 LONG rv;
 ...
 rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
 rv = SCardReleaseContext(hContext);

Definition at line 645 of file winscard_clnt.c.

References MessageReceive(), MessageSendWithHeader(), SCARD_E_INVALID_HANDLE, SCARD_RELEASE_CONTEXT, SCARD_S_SUCCESS, SCardGetContext(), SCardLockThread(), SCardRemoveContext(), and SCardUnlockThread().

{
      LONG rv;
      struct release_struct scReleaseStruct;
      SCONTEXTMAP * currentContextMap;

      API_TRACE_IN("%ld", hContext)
      PROFILE_START

      /*
       * Make sure this context has been opened
       * and get currentContextMap
       */
      currentContextMap = SCardGetContext(hContext);
      if (NULL == currentContextMap)
      {
            rv = SCARD_E_INVALID_HANDLE;
            goto error;
      }

      (void)pthread_mutex_lock(currentContextMap->mMutex);

      /* check the context is still opened */
      currentContextMap = SCardGetContext(hContext);
      if (NULL == currentContextMap)
            /* the context is now invalid
             * -> another thread may have called SCardReleaseContext
             * -> so the mMutex has been unlocked */
      {
            rv = SCARD_E_INVALID_HANDLE;
            goto error;
      }

      scReleaseStruct.hContext = hContext;
      scReleaseStruct.rv = SCARD_S_SUCCESS;

      rv = MessageSendWithHeader(SCARD_RELEASE_CONTEXT,
            currentContextMap->dwClientID,
            sizeof(scReleaseStruct), (void *) &scReleaseStruct);

      if (rv != SCARD_S_SUCCESS)
            goto end;

      /*
       * Read a message from the server
       */
      rv = MessageReceive(&scReleaseStruct, sizeof(scReleaseStruct),
            currentContextMap->dwClientID);

      if (rv != SCARD_S_SUCCESS)
            goto end;

      rv = scReleaseStruct.rv;
end:
      (void)pthread_mutex_unlock(currentContextMap->mMutex);

      /*
       * Remove the local context from the stack
       */
      (void)SCardLockThread();
      (void)SCardRemoveContext(hContext);
      (void)SCardUnlockThread();

error:
      PROFILE_END(rv)
      API_TRACE_OUT("")

      return rv;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index