1 // Copyright (c) 2011 The Bitcoin developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
5 #include <boost/algorithm/string.hpp>
6 #include <boost/interprocess/ipc/message_queue.hpp>
7 #include <boost/tokenizer.hpp>
8 #include <boost/date_time/posix_time/posix_time.hpp>
12 using namespace boost::interprocess;
13 using namespace boost::posix_time;
14 using namespace boost;
19 message_queue::remove("BitcoinURL");
22 void ipcThread(void* parg)
24 message_queue* mq = (message_queue*)parg;
27 unsigned int nPriority;
30 ptime d = boost::posix_time::microsec_clock::universal_time() + millisec(100);
31 if(mq->timed_receive(&strBuf, sizeof(strBuf), nSize, nPriority, d))
34 // Convert bitcoin:// URLs to bitcoin: URIs
35 if (strBuf[8] == '/' && strBuf[9] == '/')
37 for (int i = 8; i < 256; i++)
39 strBuf[i] = strBuf[i+2];
42 ThreadSafeHandleURL(strBuf);
59 unsigned int nPriority;
61 mq = new message_queue(open_or_create, "BitcoinURL", 2, 256);
63 // Make sure we don't lose any bitcoin: URIs
64 for (int i = 0; i < 2; i++)
66 ptime d = boost::posix_time::microsec_clock::universal_time() + millisec(1);
67 if(mq->timed_receive(&strBuf, sizeof(strBuf), nSize, nPriority, d))
70 // Convert bitcoin:// URLs to bitcoin: URIs
71 if (strBuf[8] == '/' && strBuf[9] == '/')
73 for (int i = 8; i < 256; i++)
75 strBuf[i] = strBuf[i+2];
78 ThreadSafeHandleURL(strBuf);
84 // Make sure only one bitcoin instance is listening
85 message_queue::remove("BitcoinURL");
86 mq = new message_queue(open_or_create, "BitcoinURL", 2, 256);
88 catch (interprocess_exception &ex) {
91 if (!CreateThread(ipcThread, mq))