<p>I have a fundamental doubt wrt boost signaling used in bitcoin. As far as I understand the following happens between <code>main.cpp</code> and <code>init.cpp</code>:</p>

<ul>
<li><code>StartNode()</code> spawns a thread <code>ThreadMessageHandler</code> </li>
<li><code>ThreadMessageHandler</code> issues a boost signal <code>SendMessages</code></li>
<li><code>SendMessages()</code> does the sending of messages (like <code>PING</code> or <code>INV</code>)</li>
</ul>

<p>Is my understanding correct? Why do we invoke a boost signal and complicate ? Why not a simple function call to <code>SendMessages()</code> in <code>main.cpp</code> would not do the equivalent?</p>

<p>Any expert please explain the flow of code here.</p>

<p><strong>Update</strong></p>

<p>Code Snippet1 (Original Bitcoin)</p>

<pre><code>if (lockSend)
     g_signals.SendMessages(pnode);
</code></pre>

<p>Code Snippet2 (My Attempt):</p>

<pre><code>if (lockSend)
     SendMessages(pnode);
</code></pre>

CC BY-SA 3.0
2016-01-08T08:00:08.043Z
When would you call it?
David Schwartz
CC BY-SA 3.0
2016-01-08T08:55:00.507Z
Please see my update (Snippets).  Is that not equivalent? Anyway there are some checks inside `ProcessMessages()` after which real messages are pushed. Like for Ping to happen -- one will need wait till `PING_INTERVAL` or manually issue it. All these are anyway checked in the function.
Guhan S
<bitcoind><bitcoin-core><client><protocol>
What is the correct code flow while sending a message
Guhan S
# What is the correct code flow while sending a message

(Asked by: username_0 on 2016-01-08)

I have a fundamental doubt wrt boost signaling used in bitcoin. As far as I understand the following happens between main.cpp and init.cpp:

StartNode() spawns a thread ThreadMessageHandler 
ThreadMessageHandler issues a boost signal SendMessages
SendMessages() does the sending of messages (like PING or INV)

Is my understanding correct? Why do we invoke a boost signal and complicate ? Why not a simple function call to SendMessages() in main.cpp would not do the equivalent?
Any expert please explain the flow of code here.
Update
Code Snippet1 (Original Bitcoin)
if (lockSend)
     g_signals.SendMessages(pnode);

Code Snippet2 (My Attempt):
if (lockSend)
     SendMessages(pnode);

**Tags:** bitcoind, bitcoin-core, client, protocol

> **Comments:**
> **username_1**: When would you call it?  
> **username_0**: Please see my update (Snippets).  Is that not equivalent? Anyway there are some checks inside `ProcessMessages()` after which real messages are pushed. Like for Ping to happen -- one will need wait till `PING_INTERVAL` or manually issue it. All these are anyway checked in the function.  

---

## 0 answers

