Changeset 50

Show
Ignore:
Timestamp:
07/01/08 17:23:07 (3 months ago)
Author:
jtang
Message:

Updated Java unit tests. (incremental checkin)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libsipc/bindings/java/com/tresys/sipc/Sipc.java

    r49 r50  
    3232        protected libsipc_t handle; /* internal handle */ 
    3333        protected boolean isConnected = false; /* internal state flag */ 
     34        private java.nio.ByteBuffer dataPtr = null; /* shared buffer for sending data */ 
    3435 
    3536        /** shared IPC key */ 
     
    8889                        handle.close(); 
    8990                        handle = null; 
     91                        dataPtr = null; 
    9092                        isConnected = false; 
    9193                } 
     
    124126        public java.nio.ByteBuffer GetDataPtr() throws Exception { 
    125127                if (isConnected) { 
    126                         return handle.get_data_ptr(); 
     128                        /* cache the dataPtr, to avoid re-creating it for 
     129                         * each call -- this pointer is supposed to 
     130                         * persistent across all calls, and there is 
     131                         * supposed to be exactly one that is ever 
     132                         * created */ 
     133                        if (dataPtr == null) { 
     134                                dataPtr = handle.get_data_ptr(); 
     135                        } 
     136                        return dataPtr; 
    127137                } 
    128138                else { 
     
    159169        public void SendData() throws Exception { 
    160170                if (isConnected) { 
    161                         java.nio.ByteBuffer b = GetDataPtr(); 
    162                         handle.send_data(b.limit()); 
     171                        handle.send_data(dataPtr.limit()); 
    163172                } 
    164173                else { 
  • trunk/libsipc/bindings/java/com/tresys/sipc/SipcMqueue.java

    r49 r50  
    4242                super(key, role, sipcwrapperConstants.SIPC_SYSV_MQUEUES, ipcLength); 
    4343        } 
     44 
     45        /** 
     46         * Destroys the IPC resources associated with the message 
     47         * queue handle.  Existing handles can continue operating 
     48         * until they call Close(). 
     49         */ 
     50        public static void Unlink(String key) { 
     51                sipcwrapper.sipc_unlink(key, sipcwrapperConstants.SIPC_SYSV_MQUEUES); 
     52        } 
    4453} 
  • trunk/libsipc/bindings/java/com/tresys/sipc/SipcShm.java

    r49 r50  
    4747         * successfully received and handled. 
    4848         */ 
    49         public void SipcRecvDone() throws Exception { 
     49        public void RecvDone() throws Exception { 
    5050                if (isConnected) { 
    5151                        handle.shm_recv_done(); 
     
    5555                } 
    5656        } 
     57 
     58        /** 
     59         * Destroys the IPC resources associated with the message 
     60         * queue handle.  Existing handles can continue operating 
     61         * until they call Close(). 
     62         */ 
     63        public static void Unlink(String key) { 
     64                sipcwrapper.sipc_unlink(key, sipcwrapperConstants.SIPC_SYSV_SHM); 
     65        } 
    5766} 
  • trunk/libsipc/bindings/java/examples/MQ_Creator.java

    r1 r50  
    11/* 
    22 * MQ_Creator.java 
    3  * Create a message queue.  This is a privileged application.  
     3 * Create a message queue.  This is a privileged application. 
    44 * 
    5  * Copyright (C) 2006, 2007 Tresys Technology, LLC 
     5 * Copyright (C) 2006 - 2008 Tresys Technology, LLC 
    66 * Developed Under US JFCOM Sponsorship 
    77 * 
     
    2525/** 
    2626 * Creator process for the SIPC shared memory backend. 
    27  *  
     27 * 
    2828 * @author David Windsor <dwindsor@tresys.com> 
    2929 */ 
    3030public class MQ_Creator { 
    31         private static final String sipc_key = "sipc_mq_key";  /* shared IPC key */ 
     31        private static final String sipc_key = "sipc_mq_key";  /* shared IPC key */ 
    3232 
    3333        public static void main(String[] args) { 
    3434                try { 
    35                         SipcMqueue.Create(sipc_key); 
    36                 } catch (BadKeyException e) { 
     35                    Sipc sipc = new SipcMqueue(sipc_key, sipcwrapperConstants.SIPC_CREATOR, 8196); 
     36                    sipc.Close(); 
     37                } catch (Exception e) { 
    3738                        e.printStackTrace(); 
    3839                        System.exit(1); 
  • trunk/libsipc/bindings/java/examples/MQ_Destroyer.java

    r1 r50  
    33 * Free a message queue.  This is a privileged application. 
    44 * 
    5  * Copyright (C) 2006, 2007 Tresys Technology, LLC 
     5 * Copyright (C) 2006 - 2008 Tresys Technology, LLC 
    66 * Developed Under US JFCOM Sponsorship 
    77 * 
     
    3232 
    3333        public static void main(String[] args) { 
    34                 SipcMqueue.Destroy(sipc_key); 
     34                SipcMqueue.Unlink(sipc_key); 
    3535        } 
    3636} 
  • trunk/libsipc/bindings/java/examples/MQ_Reader.java

    r1 r50  
    33 * Read character data from a message queue backed communications channel. 
    44 * 
    5  * Copyright (C) 2006, 2007 Tresys Technology, LLC 
     5 * Copyright (C) 2006 - 2008 Tresys Technology, LLC 
    66 * Developed Under US JFCOM Sponsorship 
    77 * 
     
    2424 
    2525import java.nio.*; 
    26 import java.nio.charset.*; 
    2726 
    2827/** 
    2928 * Read data from a SYSV message queue backed IPC resource. 
    3029 * The IPC resource must be created by a privileged creation processs. 
    31  *  
    32  * @author David Windsor <dwindsor@tresys.com>  
     30 * 
     31 * @author David Windsor <dwindsor@tresys.com> 
    3332 * @author Norman Patrick <npatrick@tresys.com> 
     33 * @author L. Ross Raszewski <lraszewski@tresys.com> 
    3434 */ 
    3535public class MQ_Reader { 
    36         private static final String sipc_key = "sipc_mq_key";   /* shared IPC key */ 
    37         private static final String data_end = "0xDEADBEEF";    /* end of transmission marker */ 
     36        private static final String sipc_key = "sipc_mq_key";   /* shared IPC key */ 
     37 
     38        private static final String data_end = "0xDEADBEEF";    /* end of transmission marker */ 
    3839 
    3940        /** 
    4041         * @param args 
    4142         */ 
    42         public static void main(String[] args) throws CharacterCodingException
     43        public static void main(String[] args)
    4344                SipcMqueue queue = null; 
    44                 int data_len = 4096; 
    4545                int ipc_len = 8196; 
    4646 
    4747                /* Create and initialize the IPC handle */ 
    48                 queue = new SipcMqueue(sipc_key, data_len, ipc_len); 
    49                 queue.Init(false); 
    50  
    51                 /* Connect the handle to its backend */ 
    5248                try { 
    53                         queue.Connect(); 
    54                 } catch (ConnectionException e) { 
     49                        queue = new SipcMqueue(sipc_key, sipcwrapperConstants.SIPC_RECEIVER, ipc_len); 
     50                } 
     51                catch (Exception e) { 
    5552                        e.printStackTrace(); 
    5653                        System.err.println("Unable to connect message queue!"); 
     
    5855                } 
    5956 
    60                 /* Read data from the queue */ 
    61                 ByteBuffer bbuf = queue.ReadData(); 
    62                 String data = ByteBufferToString(bbuf); 
    63                 while(data.length() > 0) { 
    64                         /* Check for an end of transmission marker */ 
    65                         if(data.equals(data_end)) 
    66                                 break; 
     57                try { 
     58                        java.io.FileOutputStream fileOut = new java.io.FileOutputStream( 
     59                                "out.dat"); 
     60                        /* Read data from the queue */ 
     61                        while (true) { 
     62                                byte[] bbuf = queue.ReadData(); 
     63                                /* Check for an end of transmission marker */ 
     64                                if (bbuf.length == 11) { 
     65                                        String data = new String(bbuf); 
     66                                        if(data.startsWith(data_end) 
     67                                                && ((int) data.charAt(10)) == 0) 
     68                                                break; 
     69                                } 
     70                                fileOut.write(bbuf); 
     71                        } 
    6772 
    68                         System.out.println(data); 
    69                         bbuf.clear(); 
    70                         bbuf = queue.ReadData(); 
    71                         data = ByteBufferToString(bbuf); 
     73                        fileOut.close(); 
    7274                } 
    73  
    74                 queue.Disconnect(); 
    75         } 
    76  
    77         /** 
    78          * Convert a ByteBuffer to a String 
    79          * @param buf  a ByteBuffer 
    80          * @return     a String, null on error 
    81          */ 
    82         private static final String ByteBufferToString(ByteBuffer b) 
    83                 throws CharacterCodingException { 
    84                 Charset cset = Charset.forName("ISO-8859-1"); 
    85                 CharsetDecoder decoder = cset.newDecoder(); 
    86                 CharBuffer cbuf = null; 
    87  
    88                 cbuf = decoder.decode(b); 
    89                 return cbuf.toString(); 
     75                catch (Exception e) { 
     76                        e.printStackTrace(); 
     77                        System.exit(1); 
     78                } 
    9079        } 
    9180} 
  • trunk/libsipc/bindings/java/examples/MQ_Sender.java

    r1 r50  
    33 * Send character data to a message queue backed communications channel. 
    44 * 
    5  * Copyright (C) 2006, 2007 Tresys Technology, LLC 
     5 * Copyright (C) 2006 - 2008 Tresys Technology, LLC 
    66 * Developed Under US JFCOM Sponsorship 
    77 * 
     
    2424import com.tresys.sipc.*; 
    2525 
     26import java.nio.*; 
     27import java.nio.charset.*; 
     28 
    2629/** 
    2730 * Write data to a SYSV message queue backed IPC resource. 
    2831 * The IPC resource must be created by a privileged creation processs. 
    29  *  
     32 * 
    3033 * @author David Windsor <dwindsor@tresys.com> 
    3134 * @author Norman Patrick <npatrick@tresys.com> 
     
    4043         */ 
    4144        public static void main(String[] args) { 
    42                long data_len = 4096
    43                 long ipc_len = 8192; 
     45                SipcMqueue queue
     46                int ipc_len = 8192; 
    4447                String filename = args[0]; 
    4548                FileInputStream stream = null; 
    4649 
    47                 /* Create and initialize the IPC handle */ 
    48                 SipcMqueue queue = new SipcMqueue(sipc_key, data_len, ipc_len); 
    49                 queue.Init(true); 
    50  
    51                 try { 
    52                         /* Connect the handle to its backend */ 
    53                         queue.Connect(); 
    54                          
     50                try { 
     51                        /* Create and initialize the IPC handle */ 
     52                        queue = new SipcMqueue(sipc_key, sipcwrapperConstants.SIPC_SENDER, ipc_len); 
    5553                        /* Read data from the file and send it to the channel */ 
    5654                        stream = new FileInputStream(filename); 
    5755                        SendData(queue, stream); 
    5856                        stream.close(); 
    59                 } catch (ConnectionException e) { 
    60                         e.printStackTrace(); 
    61                         System.err.println("Unable to connect message queue"); 
    6257                } catch (IOException ex) { 
    6358                        ex.printStackTrace(); 
    6459                        System.err.println("Unable to read from file " + filename); 
    65                 } finally { 
    66                         queue.Disconnect(); 
     60                        System.exit(1); 
     61                } catch (Exception e) { 
     62                        e.printStackTrace(); 
     63                        System.err.println("Unable to connect message queue"); 
     64                        System.exit(1); 
    6765                } 
    6866        } 
    6967 
    70         private static void SendData(SipcMqueue queue, FileInputStream stream) { 
    71                 try { 
    72                         java.nio.ByteBuffer buffer = queue.GetDataPtr(); 
    73                         java.nio.channels.FileChannel fc = stream.getChannel(); 
    74                         int read = fc.read(buffer); 
    75                         buffer.flip(); 
     68        private static void SendData(SipcMqueue queue, FileInputStream stream) throws Exception { 
     69                java.nio.ByteBuffer buffer = queue.GetDataPtr(); 
     70                java.nio.channels.FileChannel fc = stream.getChannel(); 
     71                int read = fc.read(buffer); 
     72                while (read >= 0) { 
     73                        /* Explicit-length version of SendData: 
     74                           Send the number of bytes we read */ 
     75                        queue.SendData(read); 
     76                        buffer.clear(); 
     77                        read = fc.read(buffer); 
     78                } 
    7679 
    77                         if(read < queue.DATA_LEN) 
    78                                 buffer.put((byte) 0); 
    79  
    80                         while(read >= 0) { 
    81                                 if(queue.SendData() < 0) 
    82                                         throw new IOException("Cannot send data."); 
    83  
    84                                 buffer.clear(); 
    85                                 read = fc.read(buffer); 
    86                                 if(read < queue.DATA_LEN) 
    87                                         buffer.put((byte) 0); 
    88                         } 
    89  
    90                         buffer.clear(); 
    91                         //Send the end of transmission marker 
    92                         buffer.put(MQ_Sender.data_end.getBytes()); 
    93                         buffer.put((byte) 0); 
    94                         if(queue.SendData() < 0) 
    95                                 throw new IOException("Cannot send end of transmission marker"); 
    96                 } catch (IOException ex) { 
    97                         ex.printStackTrace(); 
    98                 } 
     80                buffer.clear(); 
     81                //Send the end of transmission marker 
     82                buffer.put(MQ_Sender.data_end.getBytes()); 
     83                buffer.put((byte) 0); 
     84                /* Inferred-length version of SendData: 
     85                   flip the buffer to set its limit, and 
     86                   Sipc will use that as the data length 
     87                */ 
     88                buffer.flip(); 
     89                queue.SendData(); 
    9990        } 
    10091} 
  • trunk/libsipc/bindings/java/examples/Makefile

    r49 r50  
    44AM_JFLAGS = -cp ../libsipc-1.0.jar 
    55 
    6 SRC = MQ_Binary_Reader.java \ 
    7         MQ_Creator.java \ 
     6SRC = MQ_Creator.java \ 
    87        MQ_Destroyer.java \ 
    98        MQ_Reader.java \ 
     
    1716SIPC_KEYS=sipc_mq_key sipc_shm_key 
    1817 
    19 all: $(SIPC_KEYS) $(CLASSES) 
     18all: 
     19 
     20tests: $(CLASSES) 
     21 
     22check: $(SIPC_KEYS) tests 
     23        sh run_tests.sh 
    2024 
    2125$(SIPC_KEYS): 
     
    2529        $(JAVAC) $(AM_JFLAGS) $(JFLAGS) $< 
    2630 
    27 .PHONY: clean 
     31.PHONY: all tests check clean 
    2832        rm -f *.class core $(SIPC_KEYS) 
  • trunk/libsipc/bindings/java/examples/SHM_Creator.java

    r1 r50  
    33 * Create a shared memory segment.  This is a prvileged application. 
    44 * 
    5  * Copyright (C) 2006, 2007 Tresys Technology, LLC 
     5 * Copyright (C) 2006 - 2008 Tresys Technology, LLC 
    66 * Developed Under US JFCOM Sponsorship 
    77 * 
     
    2525/** 
    2626 * Creator process for the SIPC shared memory backend. 
    27  *  
     27 * 
    2828 * @author David Windsor <dwindsor@tresys.com> 
    2929 */ 
     
    3333        public static void main(String[] args) { 
    3434                try { 
    35                         SipcShm.Create(sipc_key); 
    36                 } catch (BadKeyException ex) { 
    37                         ex.printStackTrace(); 
     35                    Sipc sipc = new SipcShm(sipc_key, sipcwrapperConstants.SIPC_CREATOR, 8196); 
     36                    sipc.Close(); 
     37                } catch (Exception e) { 
     38                        e.printStackTrace(); 
    3839                        System.exit(1); 
    3940                } 
  • trunk/libsipc/bindings/java/examples/SHM_Destroyer.java

    r1 r50  
    11/* 
    22 * SHM_Destroyer.java 
    3  * Free a shared memory segment.  This is a provileged application.   
    4  *  
    5  * Copyright (C) 2006, 2007 Tresys Technology, LLC 
     3 * Free a shared memory segment.  This is a provileged application. 
     4 * 
     5 * Copyright (C) 2006 - 2008 Tresys Technology, LLC 
    66 * Developed Under US JFCOM Sponsorship 
    77 * 
     
    2525/** 
    2626 * Destroyer process for the SIPC shared memory backend. 
    27  *  
     27 * 
    2828 * @author David Windsor <dwindsor@tresys.com> 
    2929 */ 
     
    3232 
    3333        public static void main(String[] args) { 
    34                 SipcShm.Destroy(sipc_key); 
     34                SipcShm.Unlink(sipc_key); 
    3535        } 
    3636} 
  • trunk/libsipc/bindings/java/examples/SHM_Reader.java

    r1 r50  
    33 * Read character data from a shared memory backed communications channel. 
    44 * 
    5  * Copyright (C) 2006, 2007 Tresys Technology, LLC 
     5 * Copyright (C) 2006 - 2008 Tresys Technology, LLC 
    66 * Developed Under US JFCOM Sponsorship 
    77 * 
     
    2424 
    2525import java.nio.ByteBuffer; 
    26 import java.nio.CharBuffer; 
    27 import java.nio.charset.*; 
    2826 
    2927/** 
    3028 * Read data from a SYSV shared memory backed IPC resource. 
    3129 * The IPC resource must be created by a privileged creation processs. 
    32  *  
     30 * 
    3331 * @author David Windsor <dwindsor@tresys.com> 
    3432 * @author Norman Patrick <npatrick@tresys.com> 
    3533 */ 
    3634public class SHM_Reader { 
    37         private static final String sipc_key = "sipc_shm_key"; /* shared IPC key */ 
     35        private static final String sipc_key = "sipc_shm_key"; /* shared IPC key */ 
    3836 
    39         private static final String data_end = "0xDEADBEEF"; /* end of transmission marker */ 
    40  
    41         /* canonical encoding name, as understood by nio Charset */ 
    42         private static final String encoding = "ISO-8859-1"; 
     37        private static final String data_end = "0xDEADBEEF";    /* end of transmission marker */ 
    4338 
    4439        /** 
     
    4641         */ 
    4742        public static void main(String[] args) { 
    48                 String data = null; 
    49                 int data_len = 4096; 
     43                SipcShm shm = null; 
    5044                int ipc_len = 8196; 
    51                 ByteBuffer buffer = null; 
    5245 
    5346                /* Create and initialize the IPC handle */ 
    54                 SipcShm shm = new SipcShm(sipc_key, data_len, ipc_len); 
    55                 shm.Init(false); 
    56  
    57                 /* Connect the handle to its backend */ 
    5847                try { 
    59                         shm.Connect(); 
    60                 } catch (ConnectionException e) { 
     48                        shm = new SipcShm(sipc_key, sipcwrapperConstants.SIPC_RECEIVER, ipc_len); 
     49                } catch (Exception e) { 
    6150                        e.printStackTrace(); 
    6251                        System.err.println("Unable to connect shared memory!"); 
     
    6756                 * marker is encountered 
    6857                 */ 
    69                 while((buffer = shm.ReadData()) != null) { 
    70                         data = ByteBufferToString(buffer, data_len); 
    71                         if(data == null) 
    72                                 return; 
    73  
    74                         /* Check for the end of transmission marker */ 
    75                         if(IsEndXmit(data)) { 
    76                                 shm.SipcRecvDone(); 
    77                                 break; 
     58                try { 
     59                        java.io.FileOutputStream fileOut = new java.io.FileOutputStream( 
     60                                "out.dat"); 
     61                        /* Read data from the shared memory */ 
     62                        while(true) { 
     63                                byte[] bbuf = shm.ReadData(); 
     64                                /* Check for the end of transmission marker */ 
     65                                if (IsEndXmit(bbuf)) { 
     66                                        shm.RecvDone(); 
     67                                        break; 
     68                                } 
     69                                fileOut.write(bbuf); 
     70                                shm.RecvDone(); 
    7871                        } 
    79  
    80                         System.out.print(data); 
    81                         shm.SipcRecvDone(); 
    8272                } 
    83                 shm.Disconnect(); 
     73                catch (Exception e) { 
     74                        e.printStackTrace(); 
     75                        System.exit(1); 
     76                } 
     77                shm.Close(); 
    8478        } 
    8579 
    86         private static final boolean IsEndXmit(String data) { 
    87                 if(data.length() >= data_end.length()) { 
     80        private static final boolean IsEndXmit(byte[] bbuf) { 
     81                String data = new String(bbuf); 
     82                if (data.length() >= data_end.length()) { 
    8883                        String sub = data.substring(0, data_end.length()); 
    89                         if(sub.equals(data_end)) 
     84                        if (sub.equals(data_end)) 
    9085                                return true; 
    9186                } 
     
    9388                return false; 
    9489        } 
    95  
    96         private static final String ByteBufferToString(ByteBuffer b, int msglen) { 
    97                 Charset cset = Charset.forName(encoding); 
    98                 CharsetDecoder decoder = cset.newDecoder(); 
    99                 CharBuffer cbuf = null; 
    100  
    101                 try { 
    102                         cbuf = decoder.decode(b); 
    103                 } catch (CharacterCodingException ex) { 
    104                         ex.printStackTrace(); 
    105                         return null; 
    106                 } 
    107  
    108                 return cbuf.toString(); 
    109         } 
    11090} 
  • trunk/libsipc/bindings/java/examples/SHM_Sender.java

    r1 r50  
    22 * SHM_Sender.java 
    33 * Send character data to a shared memory backed communications channel. 
    4  *  
    5  * Copyright (C) 2006, 2007 Tresys Technology, LLC 
     4 * 
     5 * Copyright (C) 2006 - 2008 Tresys Technology, LLC 
    66 * Developed Under US JFCOM Sponsorship 
    77 * 
     
    3838        private static final String data_end = "0xDEADBEEF"; /* end of transmission marker */ 
    3939 
    40         /* canonical encoding name, as understood by nio Charset */ 
    41         private static final String encoding = "ISO-8859-1"; 
    42  
    4340        /** 
    4441         * @param args 
    4542         */ 
    4643        public static void main(String[] args) { 
    47                 int data_len = 4096
     44                SipcShm shm = null
    4845                int ipc_len = 8192; 
    4946                String filename = args[0]; 
    50                 SipcShm shm = null; 
    51  
    52                 /* Create and initialize the IPC handle */ 
    53                 shm = new SipcShm(sipc_key, data_len, ipc_len); 
    54                 shm.Init(true); 
     47                FileInputStream stream = null; 
    5548 
    5649                try { 
    57                         /* Connect the handle to its backend */ 
    58                         shm.Connect(); 
     50                        /* Create and initialize the IPC handle */ 
     51                        shm = new SipcShm(sipc_key, sipcwrapperConstants.SIPC_SENDER, ipc_len); 
    5952 
    6053                        /* Read data from the file and send it across the channel */ 
    61                         File file = new File(sipc_key); 
    62                         file.createNewFile(); 
    63                         FileInputStream stream = new FileInputStream(filename); 
     54                        stream = new FileInputStream(filename); 
    6455                        SendData(shm, stream); 
    6556                        stream.close(); 
     57                        shm.Close(); 
    6658                } catch (IOException ioe) { 
    6759                        ioe.printStackTrace(); 
    6860                        System.err.println("Unable to read from file " + filename); 
    69                 } catch (ConnectionException e) { 
     61                        System.exit(1); 
     62                } catch (Exception e) { 
    7063                        e.printStackTrace(); 
    7164                        System.err.println("Unable to connect shared memory!"); 
    72                 } 
    73                 finally { 
    74                         shm.Disconnect(); 
     65                        System.exit(1); 
    7566                } 
    7667        } 
    7768 
    78         private static void SendData(SipcShm shm, FileInputStream stream) { 
    79                 try { 
    80                         java.nio.ByteBuffer buffer = shm.GetDataPtr(); 
    81                         java.nio.channels.FileChannel fc = stream.getChannel(); 
     69        private static void SendData(SipcShm shm, FileInputStream stream) throws Exception { 
     70                java.nio.ByteBuffer buffer = shm.GetDataPtr(); 
     71                java.nio.channels.FileChannel fc = stream.getChannel(); 
     72                int read = fc.read(buffer); 
     73                while (read >= 0) { 
     74                        /* Explicit-length version of SendData: 
     75                           Send the number of bytes we read */ 
     76                        shm.SendData(read); 
     77                        buffer.clear(); 
     78                        read = fc.read(buffer); 
     79                } 
    8280 
    83                         int read = fc.read(buffer); 
    84  
    85                         while(read >= 0) { 
    86                                 if(buffer.remaining() > 0) 
    87                                         buffer.put((byte) 0); 
    88  
    89                                 if(shm.SendData() < 0) 
    90                                         throw new IOException("Cannot send data."); 
    91  
    92                                 // Clear out the data in the buffer 
    93                                 ClearBuffer(buffer); 
    94  
    95                                 buffer.clear(); // Set limit = capacity, position = 0 
    96                                 read = fc.read(buffer); 
    97                         } 
    98  
    99                         // Clear out the data in the buffer 
    100                         ClearBuffer(buffer); 
    101  
    102                         // Send the end of transmission marker 
    103                         // Set the limit so that the buffer contains only end of xmit message 
    104                         buffer.rewind(); 
    105                         buffer.limit(data_end.getBytes().length + 1); 
    106                         buffer.put(data_end.getBytes(encoding)); 
    107                         if(shm.SendData() < 0) 
    108                                 throw new IOException("Cannot send end of transmission marker"); 
    109                 } catch (IOException ex) { 
    110                         ex.printStackTrace(System.out); 
    111                 } 
    112         } 
    113  
    114         private static void ClearBuffer(ByteBuffer b) { 
    115                 byte[] bytes = new byte[b.capacity()]; 
    116                 b.clear(); // Set limit = capacity, position = 0  
    117                 b.put(bytes); 
     81                buffer.clear(); 
     82                //Send the end of transmission marker 
     83                buffer.put(SHM_Sender.data_end.getBytes()); 
     84                buffer.put((byte) 0); 
     85                /* Inferred-length version of SendData: 
     86                   flip the buffer to set its limit, and 
     87                   Sipc will use that as the data length 
     88                */ 
     89                buffer.flip(); 
     90                shm.SendData(); 
    11891        } 
    11992} 
  • trunk/libsipc/include/sipc/sipc.h

    r45 r50  
    2626struct sipc; 
    2727typedef struct sipc sipc_t; 
    28  
    29 struct sipc_msg; 
    30 typedef struct sipc_msg sipc_msg_t; 
    3128 
    3229/* SIPC roles */ 
  • trunk/libsipc/src/libsipc.map

    r45 r50  
    1212}; 
    1313 
    14 VERS_1.1
     14VERS_1.2
    1515  global: 
    1616        sipc_ioctl;