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

INTERNAL LONG MessageReceive ( void *  buffer_void,
uint64_t  buffer_size,
int32_t  filedes 
)

Called by the Client to get the reponse from the server or vice-versa.

Reads the message from the file filedes.

Parameters:
[out]buffer_voidMessage read.
[in]buffer_sizeSize to read
[in]filedesSocket handle.
Return values:
SCARD_S_SUCCESSSuccess.
SCARD_F_COMM_ERRORSocket is closed.
SCARD_F_COMM_ERRORA signal was received.

Definition at line 415 of file winscard_msg.c.

References SCARD_F_COMM_ERROR, and SCARD_S_SUCCESS.

Referenced by SCardBeginTransaction(), SCardCancel(), SCardConnect(), SCardControl(), SCardDisconnect(), SCardEndTransaction(), SCardEstablishContextTH(), SCardGetStatusChange(), SCardReconnect(), SCardReleaseContext(), SCardStatus(), and SCardTransmit().

{
      char *buffer = buffer_void;

      /* default is success */
      LONG retval = SCARD_S_SUCCESS;

      /* how many bytes we must read */
      size_t remaining = buffer_size;

      /* repeat until we get the whole message */
      while (remaining > 0)
      {
            fd_set read_fd;
            int selret;

            FD_ZERO(&read_fd);
            FD_SET(filedes, &read_fd);

            selret = select(filedes + 1, &read_fd, NULL, NULL, NULL);

            /* try to read only when socket is readable */
            if (selret > 0)
            {
                  int readed;

                  if (!FD_ISSET(filedes, &read_fd))
                  {
                        /* very strange situation. it should be an assert really */
                        retval = SCARD_F_COMM_ERROR;
                        break;
                  }
                  readed = read(filedes, buffer, remaining);

                  if (readed > 0)
                  {
                        /* we got something */
                        buffer += readed;
                        remaining -= readed;
                  } else if (readed == 0)
                  {
                        /* peer closed the socket */
                        retval = SCARD_F_COMM_ERROR;
                        break;
                  } else
                  {
                        /* we ignore the signals and empty socket situations, all
                         * other errors are fatal */
                        if (errno != EINTR && errno != EAGAIN)
                        {
                              retval = SCARD_F_COMM_ERROR;
                              break;
                        }
                  }
            }
            else
            {
                  /* we ignore signals, all other errors are fatal */
                  if (errno != EINTR)
                  {
                        Log2(PCSC_LOG_ERROR, "select returns with failure: %s",
                              strerror(errno));
                        retval = SCARD_F_COMM_ERROR;
                        break;
                  }
            }
      }

      return retval;
}

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index