Changeset 8
- Timestamp:
- 04/16/07 11:48:20 (2 years ago)
- Files:
-
- branches/binary-mq/libsipc/bindings/java/com/tresys/sipc/Sipc.java (modified) (7 diffs)
- branches/binary-mq/libsipc/bindings/java/com/tresys/sipc/libsipc.java (modified) (2 diffs)
- branches/binary-mq/libsipc/bindings/java/examples/MQ_Binary_Reader.java (added)
- branches/binary-mq/libsipc/bindings/java/examples/MQ_Reader.java (modified) (1 diff)
- branches/binary-mq/libsipc/bindings/java/examples/MQ_Sender.java (modified) (3 diffs)
- branches/binary-mq/libsipc/bindings/java/sipc_java_wrapper/sipc_wrap.c (modified) (13 diffs)
- branches/binary-mq/libsipc/src/sipc_mqueue.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/binary-mq/libsipc/bindings/java/com/tresys/sipc/Sipc.java
r4 r8 25 25 * @author David Windsor <dwindsor@tresys.com> 26 26 * @author Norman Patrick <npatrick@tresys.com> 27 * @author L. Ross Raszewski <lraszewski@tresys.com> 27 28 */ 28 29 public abstract class Sipc { … … 41 42 protected long handle; /* internal handle */ 42 43 44 protected long size_handle; /* internal message size handle */ 43 45 private java.nio.ByteBuffer dataPtr = null; /* internal pointer to data */ 44 46 … … 77 79 public void Init(boolean write) { 78 80 handle = libsipc.sipc_init(Key, GetIPCType(), DATA_LEN, write ? 1 : 0); 81 size_handle=libsipc.sipc_create_length(); 79 82 } 80 83 … … 86 89 if(handle != 0) { 87 90 libsipc.sipc_destroy_handle(handle); 91 libsipc.sipc_destroy_length(size_handle); 92 size_handle=0; 88 93 handle = 0; 89 94 dataPtr = null; … … 146 151 */ 147 152 public java.nio.ByteBuffer ReadData() { 148 return libsipc.sipc_recv_data(handle, GetIPCType()); 149 } 150 153 return libsipc.sipc_recv_data(handle, GetIPCType(), size_handle); 154 } 155 156 /** 157 * Returns the size of the last successful ReadData() operation. 158 * This should be identical to the capacity of the buffer returned by 159 * ReadData(). Return value is undefined if ReadData has not been called. 160 * 161 * @return The size of the buffer returned by the most recent call to ReadData() 162 */ 163 public int GetReadSize() { 164 return libsipc.sipc_get_length(size_handle); 165 } 151 166 /** 152 167 * Get a reference to the IPC handle's internal data buffer. … … 159 174 public java.nio.ByteBuffer GetDataPtr() { 160 175 if(isConnected && dataPtr == null) { 161 dataPtr = libsipc.sipc_get_data_ptr(handle, DATA_LEN); 162 } 176 dataPtr = libsipc.sipc_get_data_ptr(handle); 177 } 178 163 179 164 180 return dataPtr; … … 169 185 * connected state for this to succeed. 170 186 * 187 * @param len Length of the message to be sent 171 188 * @return 0 on success, <0 on error. 172 189 * @see #Connect() Connect 173 190 */ 191 public int SendData(int len) { 192 return libsipc.sipc_send_data(handle, len); 193 } 194 195 /** 196 * Send data to the communications channel. The amount of data to 197 * send is determined by the current limit of the data buffer. 198 * 199 * @return 0 on success, <0 on error 200 * @see #SendData(int) SendData(int) 201 */ 174 202 public int SendData() { 175 return libsipc.sipc_send_data(handle);203 return SendData(dataPtr.limit()); 176 204 } 177 205 } branches/binary-mq/libsipc/bindings/java/com/tresys/sipc/libsipc.java
r4 r8 1 /* This file has been hand-modified -- do not regenerate */ 2 1 3 /* ---------------------------------------------------------------------------- 2 4 * This file was automatically generated by SWIG (http://www.swig.org). … … 9 11 package com.tresys.sipc; 10 12 11 final class libsipc { 13 class libsipc { 14 12 15 static { 13 16 System.loadLibrary("sipcwrapper"); 14 17 } 15 16 public final static int SIPC_SYSV_SHM = 0; 17 18 public final static int SIPC_SYSV_MQUEUES = 1; 19 20 public final static int SIPC_NUM_TYPES = 2; 21 22 public final static native long sipc_init(String key, int ipc_type, 23 long size, int sender); 24 25 public final static native void sipc_destroy_handle(long handle); 26 27 public final static native void sipc_destroy_resource(String key, 28 int ipc_type); 29 30 public final static native int sipc_create(String key, int ipc_type); 31 32 public final static native int sipc_connect(long handle); 33 34 public final static native void sipc_disconnect(long handle); 35 36 public final static native int sipc_send_data(long handle); 37 38 public final static native java.nio.ByteBuffer sipc_recv_data(long handle, 39 int ipc_type); 40 41 public final static native int sipc_shm_recv_done(long handle); 42 43 public final static native java.nio.ByteBuffer sipc_get_data_ptr( 44 long jarg1, 45 long size); 18 public final static int SIPC_SYSV_SHM=0; 19 public final static int SIPC_SYSV_MQUEUES=1; 20 public final static int SIPC_NUM_TYPES=2; 21 public final static native long sipc_init(String jarg1, int jarg2, long jarg3, int jarg4); 22 public final static native void sipc_destroy_handle(long jarg1); 23 public final static native void sipc_destroy_resource(String jarg1, int jarg2); 24 public final static native int sipc_create(String jarg1, int jarg2); 25 public final static native int sipc_connect(long jarg1); 26 public final static native void sipc_disconnect(long jarg1); 27 public final static native int sipc_send_data(long jarg1, int jarg2); 28 /* This method is for internal use by sipc_recv_data */ 29 private final static native byte[] sipc_recv_datad(long handle, 30 int ipc_type, 31 long size_handle); 32 /* Wrap the result of the native call in a ByteBuffer */ 33 public final static java.nio.ByteBuffer sipc_recv_data(long handle, 34 int ipc_type, 35 long size_handle) 36 { 37 byte [] buf=sipc_recv_datad(handle,ipc_type,size_handle); 38 return (buf==null? null: 39 java.nio.ByteBuffer.wrap(buf,0,sipc_get_length(size_handle))); 40 } 41 public final static native java.nio.ByteBuffer sipc_get_data_ptr(long jarg1); 42 public final static native void sipc_error(long jarg1, String jarg2); 43 public final static native int sipc_shm_recv_done(long jarg1); 44 public final static native long sipc_create_length(); 45 public final static native int sipc_get_length(long jarg1); 46 public final static native void sipc_destroy_length(long jarg1); 46 47 } branches/binary-mq/libsipc/bindings/java/examples/MQ_Reader.java
r4 r8 61 61 ByteBuffer bbuf = queue.ReadData(); 62 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; 67 68 System.out.println(data); 69 bbuf.clear(); 70 bbuf = queue.ReadData(); 71 data = ByteBufferToString(bbuf); 63 System.out.println("Recieved " + queue.GetReadSize()); 64 while(bbuf!=null && data.length() > 0) { 65 /* Read off the End-Of-Transmission Marker */ 66 queue.ReadData(); 67 68 /* Check for an end of transmission marker */ 69 if(data.startsWith(data_end)) 70 break; 71 72 System.out.println(data); 73 bbuf.clear(); 74 bbuf = queue.ReadData(); 75 data = ByteBufferToString(bbuf); 72 76 } 73 74 77 queue.Disconnect(); 75 78 } branches/binary-mq/libsipc/bindings/java/examples/MQ_Sender.java
r4 r8 23 23 import java.io.*; 24 24 import com.tresys.sipc.*; 25 26 import java.nio.*; 27 import java.nio.charset.*; 25 28 26 29 /** … … 73 76 java.nio.channels.FileChannel fc = stream.getChannel(); 74 77 int read = fc.read(buffer); 75 buffer.flip();76 77 if(read < queue.DATA_LEN)78 buffer.put((byte) 0);79 80 78 while(read >= 0) { 81 if(queue.SendData() < 0) 79 /*Explicit-length version of 80 SendData: Send the number of bytes we read */ 81 if(queue.SendData(read) < 0) 82 82 throw new IOException("Cannot send data."); 83 83 84 84 buffer.clear(); 85 read = fc.read(buffer); 86 if(read < queue.DATA_LEN) 87 buffer.put((byte) 0); 85 read = fc.read(buffer); 88 86 } 89 87 … … 92 90 buffer.put(MQ_Sender.data_end.getBytes()); 93 91 buffer.put((byte) 0); 92 /* Inferred-length version of SendData: 93 flip the buffer to set its limit, and 94 Sipc will use that as the data length 95 */ 96 buffer.flip(); 94 97 if(queue.SendData() < 0) 95 98 throw new IOException("Cannot send end of transmission marker"); branches/binary-mq/libsipc/bindings/java/sipc_java_wrapper/sipc_wrap.c
r4 r8 1 /* This file has been modified by hand. Do not regenerate it. */ 2 3 1 4 /* ---------------------------------------------------------------------------- 2 5 * This file was automatically generated by SWIG (http://www.swig.org). … … 14 17 * ----------------------------------------------------------------------------- */ 15 18 16 /* template workaround for compilers that cannot correctly implement the C++ standard */ 19 /* template workaround for compilers that cannot correctly implement the 20 C++ standard */ 17 21 #ifndef SWIGTEMPLATEDISAMBIGUATOR 18 22 # if defined(__SUNPRO_CC) … … 72 76 #if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) 73 77 # ifndef GCC_HASCLASSVISIBILITY 74 # define GCC_HASCLASSVIS IBILITY78 # define GCC_HASCLASSVIS\IBILITY 75 79 # endif 76 80 #endif … … 173 177 174 178 175 /* Includes the header in the wrapper code */ 176 #include <sipc/sipc.h> 177 179 /* Includes the header in the wrapper code */ 180 #include <sipc/sipc.h> 181 182 /* Need the internal definition of the sipc structure to generate the output 183 bytebuffer */ 184 struct sipc { 185 key_t key; 186 int ipc_type; 187 int sender; 188 union { 189 int fd; /* file desciptor for socket connections */ 190 struct shm { /* shm data */ 191 int shmid; /* ID of segment */ 192 int msqid; /* notify channel */ 193 /* sipc_t *mqueue; handle to notify channel */ 194 } s; 195 int msqid; /* message queue */ 196 }; 197 198 char *data; 199 size_t len; 200 size_t msg_len; /* Length in bytes of the next message */ 201 size_t copied; /* Number of bytes xmitted so far */ 202 struct sipc_func_table *funcs; 203 }; 178 204 179 205 #ifdef __cplusplus … … 181 207 #endif 182 208 183 // sipc_init 184 JNIEXPORT jlong JNICALL Java_com_tresys_sipc_libsipc_sipc_1init(JNIEnv *jenv, jclass jcls, jstring key, jint ipc_type, jlong size, jint sender) { 209 JNIEXPORT jlong JNICALL Java_com_tresys_sipc_libsipc_sipc_1init(JNIEnv *jenv, jclass jcls, jstring jarg1, jint jarg2, jlong jarg3, jint jarg4) { 185 210 jlong jresult = 0 ; 186 211 char *arg1 = (char *) 0 ; … … 193 218 (void)jcls; 194 219 arg1 = 0; 195 if ( key) {196 arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, key, 0);220 if (jarg1) { 221 arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); 197 222 if (!arg1) return 0; 198 223 } 199 arg2 = (int) ipc_type;200 arg3 = (size_t) size;201 arg4 = (int) sender;224 arg2 = (int)jarg2; 225 arg3 = (size_t)jarg3; 226 arg4 = (int)jarg4; 202 227 result = (sipc_t *)sipc_init(arg1,arg2,arg3,arg4); 203 228 *(sipc_t **)&jresult = result; 204 if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, key, arg1);205 return jresult; 206 } 207 208 // sipc_destroy_handle 209 JNIEXPORT void JNICALL Java_com_tresys_sipc_libsipc_sipc_1destroy_1handle(JNIEnv *jenv, jclass jcls, jlong handle) {210 sipc_t *arg1 = (sipc_t *) 0 ; 211 212 (void)jenv; 213 (void)jcls; 214 arg1 = *(sipc_t **)& handle;229 if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, arg1); 230 return jresult; 231 } 232 233 234 JNIEXPORT void JNICALL Java_com_tresys_sipc_libsipc_sipc_1destroy_1handle(JNIEnv *jenv, jclass jcls, jlong jarg1) { 235 sipc_t *arg1 = (sipc_t *) 0 ; 236 237 (void)jenv; 238 (void)jcls; 239 arg1 = *(sipc_t **)&jarg1; 215 240 sipc_destroy_handle(arg1); 216 241 } 217 242 218 // sipc_destroy_resource 219 JNIEXPORT void JNICALL Java_com_tresys_sipc_libsipc_sipc_1destroy_1resource(JNIEnv *jenv, jclass jcls, jstring key, jint ipc_type) {243 244 JNIEXPORT void JNICALL Java_com_tresys_sipc_libsipc_sipc_1destroy_1resource(JNIEnv *jenv, jclass jcls, jstring jarg1, jint jarg2) { 220 245 char *arg1 = (char *) 0 ; 221 246 int arg2 ; … … 224 249 (void)jcls; 225 250 arg1 = 0; 226 if ( key) {227 arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, key, 0);251 if (jarg1) { 252 arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); 228 253 if (!arg1) return ; 229 254 } 230 arg2 = (int) ipc_type;255 arg2 = (int)jarg2; 231 256 sipc_destroy_resource(arg1,arg2); 232 if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, key, arg1);233 } 234 235 // sipc_create 236 JNIEXPORT jint JNICALL Java_com_tresys_sipc_libsipc_sipc_1create(JNIEnv *jenv, jclass jcls, jstring key, jint ipc_type) {257 if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, arg1); 258 } 259 260 261 JNIEXPORT jint JNICALL Java_com_tresys_sipc_libsipc_sipc_1create(JNIEnv *jenv, jclass jcls, jstring jarg1, jint jarg2) { 237 262 jint jresult = 0 ; 238 263 char *arg1 = (char *) 0 ; … … 243 268 (void)jcls; 244 269 arg1 = 0; 245 if ( key) {246 arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, key, 0);270 if (jarg1) { 271 arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); 247 272 if (!arg1) return 0; 248 273 } 249 arg2 = (int) ipc_type;274 arg2 = (int)jarg2; 250 275 result = (int)sipc_create(arg1,arg2); 251 276 jresult = (jint)result; 252 if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, key, arg1);253 return jresult; 254 } 255 256 // sipc_connect 257 JNIEXPORT jint JNICALL Java_com_tresys_sipc_libsipc_sipc_1connect(JNIEnv *jenv, jclass jcls, jlong handle) {277 if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, arg1); 278 return jresult; 279 } 280 281 282 JNIEXPORT jint JNICALL Java_com_tresys_sipc_libsipc_sipc_1connect(JNIEnv *jenv, jclass jcls, jlong jarg1) { 258 283 jint jresult = 0 ; 259 284 sipc_t *arg1 = (sipc_t *) 0 ; … … 262 287 (void)jenv; 263 288 (void)jcls; 264 arg1 = *(sipc_t **)& handle;289 arg1 = *(sipc_t **)&jarg1; 265 290 result = (int)sipc_connect(arg1); 266 291 jresult = (jint)result; … … 268 293 } 269 294 270 // sipc_disconnect 271 JNIEXPORT void JNICALL Java_com_tresys_sipc_libsipc_sipc_1disconnect(JNIEnv *jenv, jclass jcls, jlong handle) {272 sipc_t *arg1 = (sipc_t *) 0 ; 273 274 (void)jenv; 275 (void)jcls; 276 arg1 = *(sipc_t **)& handle;295 296 JNIEXPORT void JNICALL Java_com_tresys_sipc_libsipc_sipc_1disconnect(JNIEnv *jenv, jclass jcls, jlong jarg1) { 297 sipc_t *arg1 = (sipc_t *) 0 ; 298 299 (void)jenv; 300 (void)jcls; 301 arg1 = *(sipc_t **)&jarg1; 277 302 sipc_disconnect(arg1); 278 303 } 279 304 280 // sipc_send_data 281 JNIEXPORT jint JNICALL Java_com_tresys_sipc_libsipc_sipc_1send_1data(JNIEnv *jenv, jclass jcls, jlong handle) {305 306 JNIEXPORT jint JNICALL Java_com_tresys_sipc_libsipc_sipc_1send_1data(JNIEnv *jenv, jclass jcls, jlong jarg1, jint jarg2) { 282 307 jint jresult = 0 ; 283 308 sipc_t *arg1 = (sipc_t *) 0 ; 284 int result; 285 286 (void)jenv; 287 (void)jcls; 288 arg1 = *(sipc_t **)&handle; 289 result = (int)sipc_send_data(arg1); 309 int arg2 ; 310 int result; 311 312 (void)jenv; 313 (void)jcls; 314 arg1 = *(sipc_t **)&jarg1; 315 arg2 = (int)jarg2; 316 result = (int)sipc_send_data(arg1,arg2); 290 317 jresult = (jint)result; 291 318 return jresult; … … 293 320 294 321 295 // sipc_recv_data 296 JNIEXPORT jobject JNICALL Java_com_tresys_sipc_libsipc_sipc_1recv_1data(JNIEnv *jenv, jclass jcls, jlong handle, jint ipc_type) { 297 j object jresult = 0;322 JNIEXPORT jbyteArray JNICALL Java_com_tresys_sipc_libsipc_sipc_1recv_1datad(JNIEnv *jenv, jclass jcls, jlong handle, jint ipc_type, jlong size_handle) { 323 324 jbyteArray jresult = (jbyteArray) 0; 298 325 sipc_t *arg1 = (sipc_t *) 0 ; 299 326 char *arg2 = NULL; 300 327 int arg3 = 0; 301 328 int result; 302 303 (void)jenv; 304 (void)jcls; 305 arg1 = *(sipc_t **)&handle; 329 330 (void)jenv; 331 (void)jcls; 332 arg1 = *(sipc_t **)&handle; 306 333 result = (int)sipc_recv_data(arg1, &arg2, &arg3); 307 334 335 *(*(int **)&size_handle)=arg3; 336 308 337 if (result == 0) 309 338 { 310 jresult = (*jenv)->NewDirectByteBuffer(jenv, arg2, arg3); 339 /* 340 jresult = (*jenv)->NewDirectByteBuffer(jenv, arg2, arg3); 341 LRR: The original form above 342 leaks memory like a sieve. Instead, we ask java for a new 343 array and copy the output there. This incurs a performance 344 penalty, but it's better than leaking memory. 345 */ 346 jbyteArray jba=(*jenv)->NewByteArray(jenv,arg3); 347 (*jenv)->SetByteArrayRegion(jenv,jba,0,arg3,arg2); 348 jresult=jba; 349 350 311 351 } 312 313 if (ipc_type == (jint)SIPC_SYSV_MQUEUES) 314 free(arg2); 315 316 return jresult; 317 } 318 319 //sipc_get_data_ptr 320 JNIEXPORT jobject JNICALL Java_com_tresys_sipc_libsipc_sipc_1get_1data_1ptr(JNIEnv *jenv, jclass jcls, jlong handle, jlong size) { 321 jobject jresult = 0 ; 322 sipc_t *arg1 = (sipc_t *) 0 ; 323 char *result = NULL; 324 325 (void)jenv; 326 (void)jcls; 327 arg1 = *(sipc_t **)&handle; 328 result = sipc_get_data_ptr(arg1); 329 if(result) 330 { 331 jresult = (*jenv)->NewDirectByteBuffer(jenv, result, size); 352 if (ipc_type==(jint) SIPC_SYSV_MQUEUES) 353 { 354 free(arg2); 355 } 356 357 return jresult; 358 359 } 360 361 362 363 JNIEXPORT jobject JNICALL Java_com_tresys_sipc_libsipc_sipc_1get_1data_1ptr(JNIEnv *jenv, jclass jcls, jlong jarg1) { 364 jstring jresult = 0 ; 365 sipc_t *arg1 = (sipc_t *) 0 ; 366 char *result = 0 ; 367 368 (void)jenv; 369 (void)jcls; 370 arg1 = *(sipc_t **)&jarg1; 371 result = (char *)sipc_get_data_ptr(arg1); 372 if (result) jresult = (*jenv)->NewDirectByteBuffer(jenv, result, arg1->len); 373 return jresult; 374 } 375 376 JNIEXPORT void JNICALL Java_com_tresys_sipc_libsipc_sipc_1error(JNIEnv *jenv, jclass jcls, jlong jarg1, jstring jarg2) { 377 sipc_t *arg1 = (sipc_t *) 0 ; 378 char *arg2 = (char *) 0 ; 379 void *arg3 = 0 ; 380 381 (void)jenv; 382 (void)jcls; 383 arg1 = *(sipc_t **)&jarg1; 384 arg2 = 0; 385 if (jarg2) { 386 arg2 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg2, 0); 387 if (!arg2) return ; 332 388 } 333 return jresult; 334 } 335 336 // sipc_shm_recv_done 337 JNIEXPORT jint JNICALL Java_com_tresys_sipc_libsipc_sipc_1shm_1recv_1done(JNIEnv *jenv, jclass jcls, jlong handle) { 389 sipc_error(arg1,(char const *)arg2,arg3); 390 if (arg2) (*jenv)->ReleaseStringUTFChars(jenv, jarg2, arg2); 391 } 392 393 394 JNIEXPORT jint JNICALL Java_com_tresys_sipc_libsipc_sipc_1shm_1recv_1done(JNIEnv *jenv, jclass jcls, jlong jarg1) { 338 395 jint jresult = 0 ; 339 396 sipc_t *arg1 = (sipc_t *) 0 ; … … 342 399 (void)jenv; 343 400 (void)jcls; 344 arg1 = *(sipc_t **)& handle;401 arg1 = *(sipc_t **)&jarg1; 345 402 result = (int)sipc_shm_recv_done(arg1); 346 403 jresult = (jint)result; … … 349 406 350 407 408 /* Methods to allocate and unbox the int pointer used for returning 409 message size */ 410 static int *sipc_create_length() 411 { 412 return (int *)malloc(sizeof(int)); 413 } 414 415 static int sipc_get_length(int *arg) 416 { 417 if (arg) return *arg; else return -1; 418 } 419 420 static void sipc_destroy_length(int *arg) 421 { 422 if (arg) free(arg); 423 } 424 425 426 JNIEXPORT jlong JNICALL Java_com_tresys_sipc_libsipc_sipc_1create_1length(JNIEnv *jenv, jclass jcls) { 427 jlong jresult = 0 ; 428 int *result = 0 ; 429 430 (void)jenv; 431 (void)jcls; 432 result = (int *)sipc_create_length(); 433 *(int **)&jresult = result; 434 return jresult; 435 } 436 437 JNIEXPORT jint JNICALL Java_com_tresys_sipc_libsipc_sipc_1get_1length(JNIEnv *jenv, jclass jcls, jlong jarg1) { 438 jint jresult = 0 ; 439 int *arg1 = (int *) 0 ; 440 int result; 441 442 (void)jenv; 443 (void)jcls; 444 arg1 = *(int **)&jarg1; 445 result = (int)sipc_get_length(arg1); 446 jresult = (jint)result; 447 return jresult; 448 } 449 450 JNIEXPORT void JNICALL Java_com_tresys_sipc_libsipc_sipc_1destroy_1length(JNIEnv *jenv, jclass jcls, jlong jarg1) { 451 int *arg1 = (int *) 0 ; 452 453 (void)jenv; 454 (void)jcls; 455 arg1 = *(int **)&jarg1; 456 sipc_destroy_length(arg1); 457 } 458 459 351 460 #ifdef __cplusplus 352 461 } branches/binary-mq/libsipc/src/sipc_mqueue.c
r4 r8 302 302 } 303 303 304 /* Finds the length in digits of a number (approximates log10+1 for ints) */ 305 static int qlog(int x) 306 { 307 int i=0; 308 while(x) 309 { 310 i++; 311 x/=10; 312 } 313 return i; 314 } 315 304 316 static int mqueue_send_msg_len(sipc_t *sipc, int len) 305 317 { 306 struct msgbuf mbuf; 307 mbuf.mtype = SIPC_MSG_LEN; 308 318 struct msgbuf *mbuf; 319 309 320 if (len < 0) 310 321 return -1; 311 sprintf(mbuf.mtext, "%d", len); 312 313 if (msgsnd(sipc->msqid, (struct msgbuf *)&mbuf, sizeof(mbuf) + strlen(mbuf.mtext) + 1, 0) < 0) { 314 sipc_error(sipc, "msgsnd: %s\n", strerror(errno)); 315 return -1; 316 } 317 322 mbuf=calloc(1,sizeof(struct msgbuf)+qlog(len)+1); 323 if (!mbuf) { sipc_error(sipc,"Out of memory!\n"); return -1; } 324 325 mbuf->mtype = SIPC_MSG_LEN; 326 327 sprintf(mbuf->mtext, "%d", len); 328 329 if (msgsnd(sipc->msqid, mbuf, sizeof(struct msgbuf) + 330 strlen(mbuf->mtext) + 1, 0) < 0) { 331 free(mbuf); 332 sipc_error(sipc, "msgsnd: %s\n", strerror(errno)); 333 return -1; 334 } 335 free(mbuf); 318 336 return 0; 319 337 }
