]> Git Repo - VerusCoin.git/blame - src/qt/qtipcserver.cpp
Remove headers.h
[VerusCoin.git] / src / qt / qtipcserver.cpp
CommitLineData
88216419 1// Copyright (c) 2009-2012 The Bitcoin developers
7d145a0f
MC
2// Distributed under the MIT/X11 software license, see the accompanying
3// file license.txt or http://www.opensource.org/licenses/mit-license.php.
4
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>
9
ed6d0b5f 10#include "util.h"
fa2544e7 11#include "qtipcserver.h"
7d145a0f
MC
12
13using namespace boost::interprocess;
14using namespace boost::posix_time;
15using namespace boost;
16using namespace std;
17
18void ipcShutdown()
19{
fa2544e7 20 message_queue::remove(BITCOINURI_QUEUE_NAME);
7d145a0f
MC
21}
22
23void ipcThread(void* parg)
24{
25 message_queue* mq = (message_queue*)parg;
26 char strBuf[257];
27 size_t nSize;
28 unsigned int nPriority;
29 loop
30 {
31 ptime d = boost::posix_time::microsec_clock::universal_time() + millisec(100);
32 if(mq->timed_receive(&strBuf, sizeof(strBuf), nSize, nPriority, d))
33 {
fa2544e7 34 ThreadSafeHandleURI(std::string(strBuf, nSize));
7d145a0f
MC
35 Sleep(1000);
36 }
37 if (fShutdown)
38 {
39 ipcShutdown();
40 break;
41 }
42 }
43 ipcShutdown();
44}
45
46void ipcInit()
47{
07ed49a4
GA
48#ifdef MAC_OSX
49 // TODO: implement bitcoin: URI handling the Mac Way
50 return;
51#endif
7b90edb5
GA
52#ifdef WIN32
53 // TODO: THOROUGHLY test boost::interprocess fix,
54 // and make sure there are no Windows argument-handling exploitable
55 // problems.
56 return;
57#endif
07ed49a4 58
7d145a0f
MC
59 message_queue* mq;
60 char strBuf[257];
61 size_t nSize;
62 unsigned int nPriority;
63 try {
fa2544e7 64 mq = new message_queue(open_or_create, BITCOINURI_QUEUE_NAME, 2, 256);
7d145a0f
MC
65
66 // Make sure we don't lose any bitcoin: URIs
67 for (int i = 0; i < 2; i++)
68 {
69 ptime d = boost::posix_time::microsec_clock::universal_time() + millisec(1);
70 if(mq->timed_receive(&strBuf, sizeof(strBuf), nSize, nPriority, d))
71 {
fa2544e7 72 ThreadSafeHandleURI(std::string(strBuf, nSize));
7d145a0f
MC
73 }
74 else
75 break;
76 }
77
78 // Make sure only one bitcoin instance is listening
fa2544e7
LD
79 message_queue::remove(BITCOINURI_QUEUE_NAME);
80 mq = new message_queue(open_or_create, BITCOINURI_QUEUE_NAME, 2, 256);
7d145a0f
MC
81 }
82 catch (interprocess_exception &ex) {
83 return;
84 }
85 if (!CreateThread(ipcThread, mq))
86 {
87 delete mq;
88 }
89}
This page took 0.039222 seconds and 4 git commands to generate.