c++ - Native Messaging host not able to send 1 MB data -


i using native-host in c++, when send base64 native app chrome extension(native messaging) size base64 < 1m, program still running. when send base64 native app chrome extension (native messaging) size base64 >1m, program error "error when communicating native messaging host" code below

int _tmain(int argc, _tchar* argv[]) {     std::cout.setf( std::ios_base::unitbuf );     unsigned int c, t=0;     inp="";     t=0;     // sum first 4 chars stdin (the length of message passed).     (int = 0; <= 3; i++) {         //t += getchar();         t += std::pow(256.0f, i) * getchar();     }     // loop getchar pull in message until reach total     //  length provided.     (int i=0; < t; i++) {         c = getchar();         inp += c;     }      unsigned int len =  inp.length();     // need send 4 btyes of length information     std::cout << char(((len>>0) & 0xff))               << char(((len>>8) & 0xff))               << char(((len>>16) & 0xff))               << char(((len>>24) & 0xff));     // can output our message     std::cout << inp;     return 0; } 

native messaging hosts cannot send message more 1024*1024 bytes.

https://cs.chromium.org/file%3anative_message_process_host.cc%20kmaximummessagesize:

// maximum message size in bytes messages received native messaging // hosts. message size limited prevent chrome crashing when // native application misbehaves (e.g. starts writing garbage pipe). const size_t kmaximummessagesize = 1024 * 1024; 

to work around problem, have split message sent native messaging host extension/app in chunks of less 1mb.
in native messaging host, create loop repeatedly outputs 32-bit message length (max 1mb) followed chunk of message.
in app/extension, use chrome.runtime.connectnative instead of chrome.runtime.sendnativemessage open port lasts longer 1 message (if use sendnativemessage, port closed after receiving 1 reply, causes native messaging host terminate).


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -