mpcio.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. #include "mpcio.hpp"
  2. template<typename T>
  3. PreCompStorage<T>::PreCompStorage(unsigned player, bool preprocessing,
  4. const char *filenameprefix, unsigned thread_num) {
  5. if (preprocessing) return;
  6. std::string filename(filenameprefix);
  7. char suffix[20];
  8. sprintf(suffix, ".p%d.t%u", player%10, thread_num);
  9. filename.append(suffix);
  10. storage.open(filename);
  11. if (storage.fail()) {
  12. std::cerr << "Failed to open " << filename << "\n";
  13. exit(1);
  14. }
  15. count = 0;
  16. }
  17. template<typename T>
  18. void PreCompStorage<T>::get(T& nextval) {
  19. storage.read((char *)&nextval, sizeof(T));
  20. if (storage.gcount() != sizeof(T)) {
  21. std::cerr << "Failed to read precomputed value from storage\n";
  22. exit(1);
  23. }
  24. ++count;
  25. }
  26. void MPCSingleIO::async_send_from_msgqueue()
  27. {
  28. #ifdef SEND_LAMPORT_CLOCKS
  29. std::vector<boost::asio::const_buffer> tosend;
  30. tosend.push_back(boost::asio::buffer(messagequeue.front().header));
  31. tosend.push_back(boost::asio::buffer(messagequeue.front().message));
  32. #endif
  33. boost::asio::async_write(sock,
  34. #ifdef SEND_LAMPORT_CLOCKS
  35. tosend,
  36. #else
  37. boost::asio::buffer(messagequeue.front()),
  38. #endif
  39. [&](boost::system::error_code ec, std::size_t amt){
  40. messagequeuelock.lock();
  41. messagequeue.pop();
  42. if (messagequeue.size() > 0) {
  43. async_send_from_msgqueue();
  44. }
  45. messagequeuelock.unlock();
  46. });
  47. }
  48. size_t MPCSingleIO::queue(const void *data, size_t len, lamport_t lamport)
  49. {
  50. // Is this a new message?
  51. size_t newmsg = 0;
  52. dataqueue.append((const char *)data, len);
  53. // If this is the first queue() since the last explicit send(),
  54. // which we'll know because message_lamport will be nullopt, set
  55. // message_lamport to the current Lamport clock. Note that the
  56. // boolean test tests whether message_lamport is nullopt, not
  57. // whether its value is zero.
  58. if (!message_lamport) {
  59. message_lamport = lamport;
  60. newmsg = 1;
  61. }
  62. // If we already have some full packets worth of data, may as
  63. // well send it.
  64. if (dataqueue.size() > 28800) {
  65. send(true);
  66. }
  67. return newmsg;
  68. }
  69. void MPCSingleIO::send(bool implicit_send)
  70. {
  71. size_t thissize = dataqueue.size();
  72. // Ignore spurious calls to send(), except for resetting
  73. // message_lamport if this was an explicit send().
  74. if (thissize == 0) {
  75. #ifdef SEND_LAMPORT_CLOCKS
  76. // If this was an explicit send(), reset the message_lamport so
  77. // that it gets updated at the next queue().
  78. if (!implicit_send) {
  79. message_lamport.reset();
  80. }
  81. #endif
  82. return;
  83. }
  84. #ifdef RECORD_IOTRACE
  85. iotrace.push_back(thissize);
  86. #endif
  87. messagequeuelock.lock();
  88. // Move the current message to send into the message queue (this
  89. // moves a pointer to the data, not copying the data itself)
  90. #ifdef SEND_LAMPORT_CLOCKS
  91. messagequeue.emplace(std::move(dataqueue),
  92. message_lamport.value());
  93. // If this was an explicit send(), reset the message_lamport so
  94. // that it gets updated at the next queue().
  95. if (!implicit_send) {
  96. message_lamport.reset();
  97. }
  98. #else
  99. messagequeue.emplace(std::move(dataqueue));
  100. #endif
  101. // If this is now the first thing in the message queue, launch
  102. // an async_write to write it
  103. if (messagequeue.size() == 1) {
  104. async_send_from_msgqueue();
  105. }
  106. messagequeuelock.unlock();
  107. }
  108. size_t MPCSingleIO::recv(void *data, size_t len, lamport_t &lamport)
  109. {
  110. #ifdef SEND_LAMPORT_CLOCKS
  111. char *cdata = (char *)data;
  112. size_t res = 0;
  113. while (len > 0) {
  114. while (recvdataremain == 0) {
  115. // Read a new header
  116. char hdr[sizeof(uint32_t) + sizeof(lamport_t)];
  117. uint32_t datalen;
  118. lamport_t recv_lamport;
  119. boost::asio::read(sock, boost::asio::buffer(hdr, sizeof(hdr)));
  120. memmove(&datalen, hdr, sizeof(datalen));
  121. memmove(&recv_lamport, hdr+sizeof(datalen), sizeof(lamport_t));
  122. lamport_t new_lamport = recv_lamport + 1;
  123. if (lamport < new_lamport) {
  124. lamport = new_lamport;
  125. }
  126. if (datalen > 0) {
  127. recvdata.resize(datalen, '\0');
  128. boost::asio::read(sock, boost::asio::buffer(recvdata));
  129. recvdataremain = datalen;
  130. }
  131. }
  132. size_t amttoread = len;
  133. if (amttoread > recvdataremain) {
  134. amttoread = recvdataremain;
  135. }
  136. memmove(cdata, recvdata.data()+recvdata.size()-recvdataremain,
  137. amttoread);
  138. cdata += amttoread;
  139. len -= amttoread;
  140. recvdataremain -= amttoread;
  141. res += amttoread;
  142. }
  143. #else
  144. size_t res = boost::asio::read(sock, boost::asio::buffer(data, len));
  145. #endif
  146. #ifdef RECORD_IOTRACE
  147. iotrace.push_back(-(ssize_t(res)));
  148. #endif
  149. return res;
  150. }
  151. #ifdef RECORD_IOTRACE
  152. void MPCSingleIO::dumptrace(std::ostream &os, const char *label)
  153. {
  154. if (label) {
  155. os << label << " ";
  156. }
  157. os << "IO trace:";
  158. for (auto& s: iotrace) {
  159. os << " " << s;
  160. }
  161. os << "\n";
  162. }
  163. #endif
  164. void MPCIO::reset_stats()
  165. {
  166. msgs_sent.clear();
  167. msg_bytes_sent.clear();
  168. for (size_t i=0; i<num_threads; ++i) {
  169. msgs_sent.push_back(0);
  170. msg_bytes_sent.push_back(0);
  171. }
  172. steady_start = boost::chrono::steady_clock::now();
  173. cpu_start = boost::chrono::process_cpu_clock::now();
  174. }
  175. void MPCIO::dump_stats(std::ostream &os)
  176. {
  177. size_t tot_msgs_sent = 0;
  178. size_t tot_msg_bytes_sent = 0;
  179. for (auto& n : msgs_sent) {
  180. tot_msgs_sent += n;
  181. }
  182. for (auto& n : msg_bytes_sent) {
  183. tot_msg_bytes_sent += n;
  184. }
  185. auto steady_elapsed =
  186. boost::chrono::steady_clock::now() - steady_start;
  187. auto cpu_elapsed =
  188. boost::chrono::process_cpu_clock::now() - cpu_start;
  189. os << tot_msgs_sent << " messages sent\n";
  190. os << tot_msg_bytes_sent << " message bytes sent\n";
  191. os << lamport << " Lamport clock (latencies)\n";
  192. os << boost::chrono::duration_cast
  193. <boost::chrono::milliseconds>(steady_elapsed) <<
  194. " wall clock time\n";
  195. os << cpu_elapsed << " {real;user;system}\n";
  196. }
  197. MPCPeerIO::MPCPeerIO(unsigned player, bool preprocessing,
  198. std::deque<tcp::socket> &peersocks,
  199. std::deque<tcp::socket> &serversocks) :
  200. MPCIO(player, preprocessing, peersocks.size())
  201. {
  202. unsigned num_threads = unsigned(peersocks.size());
  203. for (unsigned i=0; i<num_threads; ++i) {
  204. triples.emplace_back(player, preprocessing, "triples", i);
  205. }
  206. for (unsigned i=0; i<num_threads; ++i) {
  207. halftriples.emplace_back(player, preprocessing, "halves", i);
  208. }
  209. for (auto &&sock : peersocks) {
  210. peerios.emplace_back(std::move(sock));
  211. }
  212. for (auto &&sock : serversocks) {
  213. serverios.emplace_back(std::move(sock));
  214. }
  215. }
  216. void MPCPeerIO::dump_precomp_stats(std::ostream &os)
  217. {
  218. for (size_t i=0; i<triples.size(); ++i) {
  219. if (i > 0) {
  220. os << " ";
  221. }
  222. os << "T" << i << " t:" << triples[i].get_stats() <<
  223. " h:" << halftriples[i].get_stats();
  224. }
  225. os << "\n";
  226. }
  227. void MPCPeerIO::reset_precomp_stats()
  228. {
  229. for (size_t i=0; i<triples.size(); ++i) {
  230. triples[i].reset_stats();
  231. halftriples[i].reset_stats();
  232. }
  233. }
  234. void MPCPeerIO::dump_stats(std::ostream &os)
  235. {
  236. MPCIO::dump_stats(os);
  237. os << "Precomputed values used: ";
  238. dump_precomp_stats(os);
  239. }
  240. MPCServerIO::MPCServerIO(bool preprocessing,
  241. std::deque<tcp::socket> &p0socks,
  242. std::deque<tcp::socket> &p1socks) :
  243. MPCIO(2, preprocessing, p0socks.size())
  244. {
  245. for (auto &&sock : p0socks) {
  246. p0ios.emplace_back(std::move(sock));
  247. }
  248. for (auto &&sock : p1socks) {
  249. p1ios.emplace_back(std::move(sock));
  250. }
  251. }
  252. // Sync our per-thread lamport clock with the master one in the
  253. // mpcio. You only need to call this explicitly if your MPCTIO
  254. // outlives your thread (in which case call it after the join), or
  255. // if your threads do interthread communication amongst themselves
  256. // (in which case call it in the sending thread before the send, and
  257. // call it in the receiving thread after the receive).
  258. void MPCTIO::sync_lamport()
  259. {
  260. // Update the mpcio Lamport time to be max of the thread Lamport
  261. // time and what we thought it was before. We use this
  262. // compare_exchange construction in order to atomically
  263. // do the comparison, computation, and replacement
  264. lamport_t old_lamport = mpcio.lamport;
  265. lamport_t new_lamport = thread_lamport;
  266. do {
  267. if (new_lamport < old_lamport) {
  268. new_lamport = old_lamport;
  269. }
  270. // The next line atomically checks if lamport still has
  271. // the value old_lamport; if so, it changes its value to
  272. // new_lamport and returns true (ending the loop). If
  273. // not, it sets old_lamport to the current value of
  274. // lamport, and returns false (continuing the loop so
  275. // that new_lamport can be recomputed based on this new
  276. // value).
  277. } while (!mpcio.lamport.compare_exchange_weak(
  278. old_lamport, new_lamport));
  279. thread_lamport = new_lamport;
  280. }
  281. // Queue up data to the peer or to the server
  282. void MPCTIO::queue_peer(const void *data, size_t len)
  283. {
  284. if (mpcio.player < 2) {
  285. MPCPeerIO &mpcpio = static_cast<MPCPeerIO&>(mpcio);
  286. size_t newmsg = mpcpio.peerios[thread_num].queue(data, len, thread_lamport);
  287. mpcpio.msgs_sent[thread_num] += newmsg;
  288. mpcpio.msg_bytes_sent[thread_num] += len;
  289. }
  290. }
  291. void MPCTIO::queue_server(const void *data, size_t len)
  292. {
  293. if (mpcio.player < 2) {
  294. MPCPeerIO &mpcpio = static_cast<MPCPeerIO&>(mpcio);
  295. size_t newmsg = mpcpio.serverios[thread_num].queue(data, len, thread_lamport);
  296. mpcpio.msgs_sent[thread_num] += newmsg;
  297. mpcpio.msg_bytes_sent[thread_num] += len;
  298. }
  299. }
  300. // Receive data from the peer or to the server
  301. size_t MPCTIO::recv_peer(void *data, size_t len)
  302. {
  303. if (mpcio.player < 2) {
  304. MPCPeerIO &mpcpio = static_cast<MPCPeerIO&>(mpcio);
  305. return mpcpio.peerios[thread_num].recv(data, len, thread_lamport);
  306. }
  307. return 0;
  308. }
  309. size_t MPCTIO::recv_server(void *data, size_t len)
  310. {
  311. if (mpcio.player < 2) {
  312. MPCPeerIO &mpcpio = static_cast<MPCPeerIO&>(mpcio);
  313. return mpcpio.serverios[thread_num].recv(data, len, thread_lamport);
  314. }
  315. return 0;
  316. }
  317. // Queue up data to p0 or p1
  318. void MPCTIO::queue_p0(const void *data, size_t len)
  319. {
  320. if (mpcio.player == 2) {
  321. MPCServerIO &mpcsrvio = static_cast<MPCServerIO&>(mpcio);
  322. size_t newmsg = mpcsrvio.p0ios[thread_num].queue(data, len, thread_lamport);
  323. mpcsrvio.msgs_sent[thread_num] += newmsg;
  324. mpcsrvio.msg_bytes_sent[thread_num] += len;
  325. }
  326. }
  327. void MPCTIO::queue_p1(const void *data, size_t len)
  328. {
  329. if (mpcio.player == 2) {
  330. MPCServerIO &mpcsrvio = static_cast<MPCServerIO&>(mpcio);
  331. size_t newmsg = mpcsrvio.p1ios[thread_num].queue(data, len, thread_lamport);
  332. mpcsrvio.msgs_sent[thread_num] += newmsg;
  333. mpcsrvio.msg_bytes_sent[thread_num] += len;
  334. }
  335. }
  336. // Receive data from p0 or p1
  337. size_t MPCTIO::recv_p0(void *data, size_t len)
  338. {
  339. if (mpcio.player == 2) {
  340. MPCServerIO &mpcsrvio = static_cast<MPCServerIO&>(mpcio);
  341. return mpcsrvio.p0ios[thread_num].recv(data, len, thread_lamport);
  342. }
  343. return 0;
  344. }
  345. size_t MPCTIO::recv_p1(void *data, size_t len)
  346. {
  347. if (mpcio.player == 2) {
  348. MPCServerIO &mpcsrvio = static_cast<MPCServerIO&>(mpcio);
  349. return mpcsrvio.p1ios[thread_num].recv(data, len, thread_lamport);
  350. }
  351. return 0;
  352. }
  353. // Send all queued data for this thread
  354. void MPCTIO::send()
  355. {
  356. if (mpcio.player < 2) {
  357. MPCPeerIO &mpcpio = static_cast<MPCPeerIO&>(mpcio);
  358. mpcpio.peerios[thread_num].send();
  359. mpcpio.serverios[thread_num].send();
  360. } else {
  361. MPCServerIO &mpcsrvio = static_cast<MPCServerIO&>(mpcio);
  362. mpcsrvio.p0ios[thread_num].send();
  363. mpcsrvio.p1ios[thread_num].send();
  364. }
  365. }
  366. // Functions to get precomputed values. If we're in the online
  367. // phase, get them from PreCompStorage. If we're in the
  368. // preprocessing phase, read them from the server.
  369. MultTriple MPCTIO::triple()
  370. {
  371. MultTriple val;
  372. if (mpcio.player < 2) {
  373. MPCPeerIO &mpcpio = static_cast<MPCPeerIO&>(mpcio);
  374. if (mpcpio.preprocessing) {
  375. recv_server(&val, sizeof(val));
  376. } else {
  377. mpcpio.triples[thread_num].get(val);
  378. }
  379. } else if (mpcio.preprocessing) {
  380. // Create triples (X0,Y0,Z0),(X1,Y1,Z1) such that
  381. // (X0*Y1 + Y0*X1) = (Z0+Z1)
  382. value_t X0, Y0, Z0, X1, Y1, Z1;
  383. arc4random_buf(&X0, sizeof(X0));
  384. arc4random_buf(&Y0, sizeof(Y0));
  385. arc4random_buf(&Z0, sizeof(Z0));
  386. arc4random_buf(&X1, sizeof(X1));
  387. arc4random_buf(&Y1, sizeof(Y1));
  388. Z1 = X0 * Y1 + X1 * Y0 - Z0;
  389. MultTriple T0, T1;
  390. T0 = std::make_tuple(X0, Y0, Z0);
  391. T1 = std::make_tuple(X1, Y1, Z1);
  392. queue_p0(&T0, sizeof(T0));
  393. queue_p1(&T1, sizeof(T1));
  394. }
  395. return val;
  396. }
  397. HalfTriple MPCTIO::halftriple()
  398. {
  399. HalfTriple val;
  400. if (mpcio.player < 2) {
  401. MPCPeerIO &mpcpio = static_cast<MPCPeerIO&>(mpcio);
  402. if (mpcpio.preprocessing) {
  403. recv_server(&val, sizeof(val));
  404. } else {
  405. mpcpio.halftriples[thread_num].get(val);
  406. }
  407. } else if (mpcio.preprocessing) {
  408. // Create half-triples (X0,Z0),(Y1,Z1) such that
  409. // X0*Y1 = Z0 + Z1
  410. value_t X0, Z0, Y1, Z1;
  411. arc4random_buf(&X0, sizeof(X0));
  412. arc4random_buf(&Z0, sizeof(Z0));
  413. arc4random_buf(&Y1, sizeof(Y1));
  414. Z1 = X0 * Y1 - Z0;
  415. HalfTriple H0, H1;
  416. H0 = std::make_tuple(X0, Z0);
  417. H1 = std::make_tuple(Y1, Z1);
  418. queue_p0(&H0, sizeof(H0));
  419. queue_p1(&H1, sizeof(H1));
  420. }
  421. return val;
  422. }
  423. // The port number for the P1 -> P0 connection
  424. static const unsigned short port_p1_p0 = 2115;
  425. // The port number for the P2 -> P0 connection
  426. static const unsigned short port_p2_p0 = 2116;
  427. // The port number for the P2 -> P1 connection
  428. static const unsigned short port_p2_p1 = 2117;
  429. void mpcio_setup_computational(unsigned player,
  430. boost::asio::io_context &io_context,
  431. const char *p0addr, // can be NULL when player=0
  432. int num_threads,
  433. std::deque<tcp::socket> &peersocks,
  434. std::deque<tcp::socket> &serversocks)
  435. {
  436. if (player == 0) {
  437. // Listen for connections from P1 and from P2
  438. tcp::acceptor acceptor_p1(io_context,
  439. tcp::endpoint(tcp::v4(), port_p1_p0));
  440. tcp::acceptor acceptor_p2(io_context,
  441. tcp::endpoint(tcp::v4(), port_p2_p0));
  442. peersocks.clear();
  443. serversocks.clear();
  444. for (int i=0;i<num_threads;++i) {
  445. peersocks.emplace_back(io_context);
  446. serversocks.emplace_back(io_context);
  447. }
  448. for (int i=0;i<num_threads;++i) {
  449. tcp::socket peersock = acceptor_p1.accept();
  450. // Read 2 bytes from the socket, which will be the thread
  451. // number
  452. unsigned short thread_num;
  453. boost::asio::read(peersock,
  454. boost::asio::buffer(&thread_num, sizeof(thread_num)));
  455. if (thread_num >= num_threads) {
  456. std::cerr << "Received bad thread number from peer\n";
  457. } else {
  458. peersocks[thread_num] = std::move(peersock);
  459. }
  460. }
  461. for (int i=0;i<num_threads;++i) {
  462. tcp::socket serversock = acceptor_p2.accept();
  463. // Read 2 bytes from the socket, which will be the thread
  464. // number
  465. unsigned short thread_num;
  466. boost::asio::read(serversock,
  467. boost::asio::buffer(&thread_num, sizeof(thread_num)));
  468. if (thread_num >= num_threads) {
  469. std::cerr << "Received bad thread number from server\n";
  470. } else {
  471. serversocks[thread_num] = std::move(serversock);
  472. }
  473. }
  474. } else if (player == 1) {
  475. // Listen for connections from P2, make num_threads connections to P0
  476. tcp::acceptor acceptor_p2(io_context,
  477. tcp::endpoint(tcp::v4(), port_p2_p1));
  478. tcp::resolver resolver(io_context);
  479. boost::system::error_code err;
  480. peersocks.clear();
  481. serversocks.clear();
  482. for (int i=0;i<num_threads;++i) {
  483. serversocks.emplace_back(io_context);
  484. }
  485. for (unsigned short thread_num = 0; thread_num < num_threads; ++thread_num) {
  486. tcp::socket peersock(io_context);
  487. while(1) {
  488. boost::asio::connect(peersock,
  489. resolver.resolve(p0addr, std::to_string(port_p1_p0)), err);
  490. if (!err) break;
  491. std::cerr << "Connection to p0 refused, will retry.\n";
  492. sleep(1);
  493. }
  494. // Write 2 bytes to the socket indicating which thread
  495. // number this socket is for
  496. boost::asio::write(peersock,
  497. boost::asio::buffer(&thread_num, sizeof(thread_num)));
  498. peersocks.push_back(std::move(peersock));
  499. }
  500. for (int i=0;i<num_threads;++i) {
  501. tcp::socket serversock = acceptor_p2.accept();
  502. // Read 2 bytes from the socket, which will be the thread
  503. // number
  504. unsigned short thread_num;
  505. boost::asio::read(serversock,
  506. boost::asio::buffer(&thread_num, sizeof(thread_num)));
  507. if (thread_num >= num_threads) {
  508. std::cerr << "Received bad thread number from server\n";
  509. } else {
  510. serversocks[thread_num] = std::move(serversock);
  511. }
  512. }
  513. } else {
  514. std::cerr << "Invalid player number passed to mpcio_setup_computational\n";
  515. }
  516. }
  517. void mpcio_setup_server(boost::asio::io_context &io_context,
  518. const char *p0addr, const char *p1addr, int num_threads,
  519. std::deque<tcp::socket> &p0socks,
  520. std::deque<tcp::socket> &p1socks)
  521. {
  522. // Make connections to P0 and P1
  523. tcp::resolver resolver(io_context);
  524. boost::system::error_code err;
  525. p0socks.clear();
  526. p1socks.clear();
  527. for (unsigned short thread_num = 0; thread_num < num_threads; ++thread_num) {
  528. tcp::socket p0sock(io_context);
  529. while(1) {
  530. boost::asio::connect(p0sock,
  531. resolver.resolve(p0addr, std::to_string(port_p2_p0)), err);
  532. if (!err) break;
  533. std::cerr << "Connection to p0 refused, will retry.\n";
  534. sleep(1);
  535. }
  536. // Write 2 bytes to the socket indicating which thread
  537. // number this socket is for
  538. boost::asio::write(p0sock,
  539. boost::asio::buffer(&thread_num, sizeof(thread_num)));
  540. p0socks.push_back(std::move(p0sock));
  541. }
  542. for (unsigned short thread_num = 0; thread_num < num_threads; ++thread_num) {
  543. tcp::socket p1sock(io_context);
  544. while(1) {
  545. boost::asio::connect(p1sock,
  546. resolver.resolve(p1addr, std::to_string(port_p2_p1)), err);
  547. if (!err) break;
  548. std::cerr << "Connection to p1 refused, will retry.\n";
  549. sleep(1);
  550. }
  551. // Write 2 bytes to the socket indicating which thread
  552. // number this socket is for
  553. boost::asio::write(p1sock,
  554. boost::asio::buffer(&thread_num, sizeof(thread_num)));
  555. p1socks.push_back(std::move(p1sock));
  556. }
  557. }