2

I'm sending intents from native layer to Java layer at a very high rate ( more than 100 intents / sec ). If the CPU load is high, a TransactionTooLargeException is thrown in logcat, but i cannot catch it back in the native sender.

My intents have small payload of about 300 bytes, and indeed, i've checked that at the moment of the first exception, i have about 1 MB worth of intents sent but not received the other end ( in the Java app).

Here is my native sender code.

sp<IServiceManager> mServiceManager = defaultServiceManager();
sp<IBinder>         mActivityManager  = mServiceManager->checkService(String16("activity"));

status_t ret = mActivityManager->transact(BROADCAST_INTENT_TRANSACTION, mData, &mReply, 0);

    if (ret == NO_ERROR)
    {
        int32_t exceptionCode = mReply.readExceptionCode();
        if (!exceptionCode)
        {
            status = true;
        }
        else
        {
            ALOGD("exception %d\n", exceptionCode);
        }
    }
    else
    {
        ALOGD("error: %d", ret);
    }
Onik
  • 19,396
  • 14
  • 68
  • 91
Cumatru
  • 695
  • 2
  • 12
  • 34
  • you are transferring lots of data, why do you use a Binder based data passing? why not UNIX pipes? – pskink Jul 21 '16 at 18:23
  • cannot change this aspect now – Cumatru Jul 21 '16 at 20:10
  • My intents have small payload of about 300 bytes, and indeed, i've checked that at the moment of the first exception, i have about 1 MB worth of intents sent but not received the other end ( in the Java app). – Cumatru Jul 22 '16 at 07:26
  • i'm sending double values, 1 per Transaction, i cannot send them in bulk. The other end, is just a simple BroadcastReceiver that just unpacks the Bundle inside the Parcel and makes use of the data – Cumatru Jul 22 '16 at 10:50
  • sure, the threshold of msg / second is given by the system CPU load. sometimes i can send and receive in Java 1 million of Intents at a rate of 400 msg / second without any issue. But if system CPU load gets to 100 % and the Binder buffer gets filled with more than 1MB worth of transactions, it fails. – Cumatru Jul 22 '16 at 11:19
  • The idea is that i want to catch that exception. Why ? Well, i understand that you've performed that test and worked, but try to introduce some CPU load from another application and bottleneck the CPU to 100% for a few minutes. Do you get that exception ? BTW: this is not NDK, is native framework. The NDK doesn't have Binder – Cumatru Jul 24 '16 at 11:14
  • is your native code similar to mine ? could you share it here ? – Cumatru Jul 24 '16 at 14:11
  • if your code is similar to [this](http://stackoverflow.com/questions/37300703/bundle-inside-intent-from-native-cpp-application-using-binder) then no, my is far different, now it is clear why you are getting those mysterious exceptions – pskink Jul 24 '16 at 14:20
  • why ? what is the correct approach ? – Cumatru Jul 24 '16 at 17:27
  • why? do you think that calling `data.writeInt32` / `data.writeString16` many many times with cryptic / magic numbers is a right approach? if so, what do you really want to achieve? i said it is XY problem but you dont want to say what is you goal actually – pskink Jul 24 '16 at 17:36
  • I have and Java end-point which i cannot change and expects data via Binder, as Intents. I cannot send them from Java, because i have the data into a native C++ application, so the only way is to send Intents from native to java clients. I think i provided sufficient details. – Cumatru Jul 24 '16 at 18:08
  • what does `Binder` have to do with `Intent`? they are completely two different things, so how does your java endpoint returns the `Binder` to talk to? is it a `Service` that returns the `Binder` via `onBind`? or you just need the `Intent` to start your endpoint component let it be `Service` / `Activity` / `BroadcastReceiver` ? – pskink Jul 24 '16 at 18:45
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/118156/discussion-between-cumatru-and-pskink). – Cumatru Jul 24 '16 at 20:02

0 Answers0