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

int SHMInitializeCommonSegment ( void   ) 

Prepares the communication channel used by the server to talk to the clients.

This is called by the server to create a socket for local IPC with the clients. The socket is associated to the file PCSCLITE_CSOCK_NAME. Each client will open a connection to this socket.

Returns:
Error code.
Return values:
0 Success
-1 Can not create the socket.
-1 Can not bind the socket to the file PCSCLITE_CSOCK_NAME.
-1 Can not put the socket in listen mode.

Definition at line 110 of file winscard_msg_srv.c.

References commonSocket, and SHMCleanupSharedSegment().

Referenced by SVCServiceRunLoop().

{
      static struct sockaddr_un serv_adr;

      /*
       * Create the common shared connection socket 
       */
      if ((commonSocket = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
      {
            Log2(PCSC_LOG_CRITICAL, "Unable to create common socket: %s",
                  strerror(errno));
            return -1;
      }

      serv_adr.sun_family = AF_UNIX;
      strncpy(serv_adr.sun_path, PCSCLITE_CSOCK_NAME,
            sizeof(serv_adr.sun_path));
      SYS_Unlink(PCSCLITE_CSOCK_NAME);

      if (bind(commonSocket, (struct sockaddr *) &serv_adr,
                  sizeof(serv_adr.sun_family) + strlen(serv_adr.sun_path) + 1) < 0)
      {
            Log2(PCSC_LOG_CRITICAL, "Unable to bind common socket: %s",
                  strerror(errno));
            SHMCleanupSharedSegment(commonSocket, PCSCLITE_CSOCK_NAME);
            return -1;
      }

      if (listen(commonSocket, 1) < 0)
      {
            Log2(PCSC_LOG_CRITICAL, "Unable to listen common socket: %s",
                  strerror(errno));
            SHMCleanupSharedSegment(commonSocket, PCSCLITE_CSOCK_NAME);
            return -1;
      }

      /*
       * Chmod the public entry channel 
       */
      SYS_Chmod(PCSCLITE_CSOCK_NAME, S_IRWXO | S_IRWXG | S_IRWXU);

      return 0;
}


Generated by  Doxygen 1.6.0   Back to index