From 3a3dfe4894034d943e72e37f8f19f0045e656240 Mon Sep 17 00:00:00 2001 From: "Diez B. Roggisch" Date: Sat, 15 Jan 2022 14:47:39 +0100 Subject: [PATCH 1/3] Introduce block-argument to send By default, sending blocks. When block=False, raise pynng.TryAgain if no data could be delivered. --- pynng/nng.py | 19 ++++++++++++++++--- test/test_api.py | 6 ++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/pynng/nng.py b/pynng/nng.py index 1b71a4e..426fd24 100644 --- a/pynng/nng.py +++ b/pynng/nng.py @@ -456,10 +456,23 @@ def recv(self, block=True): lib.nng_free(data[0], size_t[0]) return recvd - def send(self, data): - """Sends ``data`` (either ``bytes`` or ``bytearray``) on socket.""" + def send(self, data, block=True): + """Sends ``data`` on socket. + + Args: + + data: either ``bytes`` or ``bytearray`` + + block: If block is True (the default), the function will + not return until the operation is completed or times out. + If block is False, the function will raise ``pynng.TryAgain`` + immediately if no data was sent. + """ _ensure_can_send(data) - err = lib.nng_send(self.socket, data, len(data), 0) + flags = 0 + if not block: + flags |= lib.NNG_FLAG_NONBLOCK + err = lib.nng_send(self.socket, data, len(data), flags) check_err(err) async def arecv(self): diff --git a/test/test_api.py b/test/test_api.py index 7059e34..a559c26 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -57,6 +57,12 @@ def test_nonblocking_recv_works(): s.recv(block=False) +def test_nonblocking_send_works(): + with pynng.Pair0(listen=addr) as s: + with pytest.raises(pynng.TryAgain): + s.send(b'sad message, never will be seen', block=False) + + @pytest.mark.trio async def test_context(): with pynng.Req0(listen=addr, recv_timeout=1000) as req_sock, \ From 1032bd11276e619acd47ee24c4e8f8137fd38955 Mon Sep 17 00:00:00 2001 From: "Diez B. Roggisch" Date: Sat, 16 Apr 2022 13:55:19 +0200 Subject: [PATCH 2/3] Update documentation on how to run tests properly --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bcbfa97..a0a60c7 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Building from the GitHub repo works as well, natch: pip3 install -e . (If you want to run tests, you also need to `pip3 install trio curio pytest pytest-asyncio pytest-trio pytest-curio`, -then just run `pytest`.) +then just run `pytest test`.) pynng might work on the BSDs as well. Who knows! From 91ddbbe712a50a5867853a6a95bfbd2b5021139f Mon Sep 17 00:00:00 2001 From: Kan Liu Date: Sun, 21 Aug 2022 11:57:40 +0800 Subject: [PATCH 3/3] Fix the bug that building process will be broken if add -latomic in Mac with clang. https://github.com/nodejs/node/pull/30099 --- .DS_Store | Bin 10244 -> 0 bytes .gitignore | 1 + build_pynng.py | 13 +++++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 92970a5de64a77a470d5f936b8f6929e66dae930..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10244 zcmeHMTWl0n82Jv1%y~5Yg2t9%lFNZ1%Q4)^q?>mPFX$&F48cHY)-*MB=f-$@EZ*5Q-5#6T+}Y6{+t{^v zdRmbiSH`#Y9U4D+Z0h**iI?~qXj2F`52zRQa{e-vDwbGUId`v67g9OLcAZhua!WNB zgop?Jt%^u_ft7fam9|&t7Cfk`E%D&%G7r=`ZE#54mu3qJbbI$q_?GK_r>tY9H|(27d|n#y+??MXIHnoPd*(wX z`B??ChrGREi@M`(43)EU7cX0}s;%R$E%)~9*!^H}-u!x|stXql6)exn*ycXn%bJd1 zIimxUmf??$5UCvBI&7IaMQOl4`yGAUEV3nyP0cNuCVVcpDfKd(&sdM;E&nKMmE|Iv zUq5fT7E=!xG@IS7!Fw}g_Kp%*TD6$ApIf?fCgn!hV70bZ?e}QXGSh`)ySiTOf0S6S zFi&XWYL_-(>lxElm?6g5pl;HJ3Ia@p?G(zp)vela)*T)VhzO#r2tf=HPIoe^t^9|_4Hn`0}jyl!U;GDPr)fT z4X?r*a1P#u_u*ss1U`k&pa|c=kMJw}4u2!XFiKd5P1uYYF2$7?$4>0RdvF^ju?Ktc z0Zd^(4&o3V!oxU<7CwR=PT_Gpfsf;p_zXUaFW`lJ^-cpl%z_wWLKfFI)L_yvB2 zMf@Ir!k_UM{7b5l=18?ti=;`nOKYV&#LT7AE;16XBotB?6)M9c+$N=i*9wo8-tFp+ z|0g`YnacyBVZp*hikcuDX6L~9dU(1hE;{tHbs#| zQQfpzq0nK~#pcGQB@`1X10K>!*iW*X`nkyD>*wVecoWVOFE0=;FTuC)1N;Vm5F6{T z0UHB8F2&`z8rR@jY{PZ90XO0%+(OLk#qD?>_Tf(AD3_k