1414#include " util/async_scope.h"
1515#include " util/error.h"
1616#include " util/object.h"
17+ #include " util/string_or_buffer.h"
1718#include " util/take.h"
1819#include " util/uvdelayed.h"
1920#include " util/uvwork.h"
@@ -102,7 +103,7 @@ Socket::Socket(const Napi::CallbackInfo& info)
102103 return ;
103104 }
104105
105- uv_os_sock_t file_descriptor = 0 ;
106+ auto file_descriptor = uv_os_sock_t {} ;
106107
107108 const auto error = [this ]() {
108109 [[maybe_unused]] auto err = zmq_close (socket);
@@ -751,27 +752,20 @@ Napi::Value Socket::Receive(const Napi::CallbackInfo& info) {
751752
752753void Socket::Join ([[maybe_unused]] const Napi::CallbackInfo& info) {
753754#ifdef ZMQ_HAS_POLLABLE_THREAD_SAFE
754- Arg::Validator args{
755- Arg::Required<Arg::String, Arg::Buffer>(" Group must be a string or buffer" ),
756- };
757-
758- if (args.ThrowIfInvalid (info)) {
759- return ;
755+ for (size_t i_value = 0 ; i_value < info.Length (); ++i_value) {
756+ const auto & value = info[i_value];
757+ this ->JoinElement (value);
760758 }
759+ #endif
760+ }
761761
762+ void Socket::JoinElement ([[maybe_unused]] const Napi::Value& value) {
763+ #ifdef ZMQ_HAS_POLLABLE_THREAD_SAFE
762764 if (!ValidateOpen ()) {
763765 return ;
764766 }
765767
766- auto str = [&]() {
767- if (info[0 ].IsString ()) {
768- return std::string (info[0 ].As <Napi::String>());
769- }
770- auto buf = info[0 ].As <Napi::Object>();
771- auto length = buf.As <Napi::Buffer<char >>().Length ();
772- auto * value = buf.As <Napi::Buffer<char >>().Data ();
773- return std::string (value, length);
774- }();
768+ const auto str = convert_string_or_buffer (value);
775769
776770 if (zmq_join (socket, str.c_str ()) < 0 ) {
777771 ErrnoException (Env (), zmq_errno ()).ThrowAsJavaScriptException ();
@@ -782,27 +776,20 @@ void Socket::Join([[maybe_unused]] const Napi::CallbackInfo& info) {
782776
783777void Socket::Leave ([[maybe_unused]] const Napi::CallbackInfo& info) {
784778#ifdef ZMQ_HAS_POLLABLE_THREAD_SAFE
785- Arg::Validator args{
786- Arg::Required<Arg::String, Arg::Buffer>(" Group must be a string or buffer" ),
787- };
788-
789- if (args.ThrowIfInvalid (info)) {
790- return ;
779+ for (size_t i_value = 0 ; i_value < info.Length (); ++i_value) {
780+ const auto & value = info[i_value];
781+ this ->LeaveElement (value);
791782 }
783+ #endif
784+ }
792785
786+ void Socket::LeaveElement ([[maybe_unused]] const Napi::Value& value) {
787+ #ifdef ZMQ_HAS_POLLABLE_THREAD_SAFE
793788 if (!ValidateOpen ()) {
794789 return ;
795790 }
796791
797- auto str = [&]() {
798- if (info[0 ].IsString ()) {
799- return std::string (info[0 ].As <Napi::String>());
800- }
801- auto buf = info[0 ].As <Napi::Object>();
802- auto length = buf.As <Napi::Buffer<char >>().Length ();
803- auto * value = buf.As <Napi::Buffer<char >>().Data ();
804- return std::string (value, length);
805- }();
792+ const auto str = convert_string_or_buffer (value);
806793
807794 if (zmq_leave (socket, str.c_str ()) < 0 ) {
808795 ErrnoException (Env (), zmq_errno ()).ThrowAsJavaScriptException ();
0 commit comments