< prev index next >

jdk/src/jdk.jdi/share/native/libdt_shmem/shmemBase.c

Print this page




 520      * freeConnection(connection);
 521      */
 522 }
 523 
 524 
 525 /*
 526  * For client: connect to the shared memory.  Open incoming and
 527  * outgoing streams.
 528  */
 529 static jint
 530 openConnection(SharedMemoryTransport *transport, jlong otherPID,
 531                SharedMemoryConnection **connectionPtr)
 532 {
 533     jint error;
 534 
 535     SharedMemoryConnection *connection = allocConnection();
 536     if (connection == NULL) {
 537         return SYS_NOMEM;
 538     }
 539 
 540     sprintf(connection->name, "%s.%ld", transport->name, sysProcessGetID());
 541     error = sysSharedMemOpen(connection->name, &connection->sharedMemory,
 542                              &connection->shared);
 543     if (error != SYS_OK) {
 544         closeConnection(connection);
 545         return error;
 546     }
 547 
 548     /* This process is the client */
 549     connection->incoming.shared = &connection->shared->toClient;
 550     connection->outgoing.shared = &connection->shared->toServer;
 551 
 552     error = openStream(&connection->incoming);
 553     if (error != SYS_OK) {
 554         closeConnection(connection);
 555         return error;
 556     }
 557 
 558     error = openStream(&connection->outgoing);
 559     if (error != SYS_OK) {
 560         closeConnection(connection);


 584     *connectionPtr = connection;
 585     return SYS_OK;
 586 }
 587 
 588 /*
 589  * For server: create the shared memory.  Create incoming and
 590  * outgoing streams.
 591  */
 592 static jint
 593 createConnection(SharedMemoryTransport *transport, jlong otherPID,
 594                  SharedMemoryConnection **connectionPtr)
 595 {
 596     jint error;
 597     char streamPrefix[MAX_IPC_NAME];
 598 
 599     SharedMemoryConnection *connection = allocConnection();
 600     if (connection == NULL) {
 601         return SYS_NOMEM;
 602     }
 603 
 604     sprintf(connection->name, "%s.%ld", transport->name, otherPID);
 605     error = sysSharedMemCreate(connection->name, sizeof(SharedMemory),
 606                                &connection->sharedMemory, &connection->shared);
 607     if (error != SYS_OK) {
 608         closeConnection(connection);
 609         return error;
 610     }
 611 
 612     memset(connection->shared, 0, sizeof(SharedMemory));
 613 
 614     /* This process is the server */
 615     connection->incoming.shared = &connection->shared->toServer;
 616     connection->outgoing.shared = &connection->shared->toClient;
 617 
 618     strcpy(streamPrefix, connection->name);
 619     strcat(streamPrefix, ".ctos");
 620     error = createStream(streamPrefix, &connection->incoming);
 621     if (error != SYS_OK) {
 622         closeConnection(connection);
 623         return error;
 624     }




 520      * freeConnection(connection);
 521      */
 522 }
 523 
 524 
 525 /*
 526  * For client: connect to the shared memory.  Open incoming and
 527  * outgoing streams.
 528  */
 529 static jint
 530 openConnection(SharedMemoryTransport *transport, jlong otherPID,
 531                SharedMemoryConnection **connectionPtr)
 532 {
 533     jint error;
 534 
 535     SharedMemoryConnection *connection = allocConnection();
 536     if (connection == NULL) {
 537         return SYS_NOMEM;
 538     }
 539 
 540     sprintf(connection->name, "%s.%ld", transport->name, (jint)sysProcessGetID());
 541     error = sysSharedMemOpen(connection->name, &connection->sharedMemory,
 542                              &connection->shared);
 543     if (error != SYS_OK) {
 544         closeConnection(connection);
 545         return error;
 546     }
 547 
 548     /* This process is the client */
 549     connection->incoming.shared = &connection->shared->toClient;
 550     connection->outgoing.shared = &connection->shared->toServer;
 551 
 552     error = openStream(&connection->incoming);
 553     if (error != SYS_OK) {
 554         closeConnection(connection);
 555         return error;
 556     }
 557 
 558     error = openStream(&connection->outgoing);
 559     if (error != SYS_OK) {
 560         closeConnection(connection);


 584     *connectionPtr = connection;
 585     return SYS_OK;
 586 }
 587 
 588 /*
 589  * For server: create the shared memory.  Create incoming and
 590  * outgoing streams.
 591  */
 592 static jint
 593 createConnection(SharedMemoryTransport *transport, jlong otherPID,
 594                  SharedMemoryConnection **connectionPtr)
 595 {
 596     jint error;
 597     char streamPrefix[MAX_IPC_NAME];
 598 
 599     SharedMemoryConnection *connection = allocConnection();
 600     if (connection == NULL) {
 601         return SYS_NOMEM;
 602     }
 603 
 604     sprintf(connection->name, "%s.%ld", transport->name, (jint)otherPID);
 605     error = sysSharedMemCreate(connection->name, sizeof(SharedMemory),
 606                                &connection->sharedMemory, &connection->shared);
 607     if (error != SYS_OK) {
 608         closeConnection(connection);
 609         return error;
 610     }
 611 
 612     memset(connection->shared, 0, sizeof(SharedMemory));
 613 
 614     /* This process is the server */
 615     connection->incoming.shared = &connection->shared->toServer;
 616     connection->outgoing.shared = &connection->shared->toClient;
 617 
 618     strcpy(streamPrefix, connection->name);
 619     strcat(streamPrefix, ".ctos");
 620     error = createStream(streamPrefix, &connection->incoming);
 621     if (error != SYS_OK) {
 622         closeConnection(connection);
 623         return error;
 624     }


< prev index next >