@@ -103,11 +103,13 @@ class RawChannel : public Nan::ObjectWrap
103103 }
104104
105105private:
106- explicit RawChannel (const char *name, bool timestamps = false , int protocol = CAN_RAW ) : m_Thread (0 ), m_Name (name), m_SocketFd (-1 )
106+ explicit RawChannel (const char *name, bool timestamps, int protocol, bool non_block_send)
107+ : m_Thread (0 ), m_Name (name), m_SocketFd (-1 )
107108 {
108109 m_SocketFd = socket (PF_CAN , SOCK_RAW , protocol);
109110 m_ThreadStopRequested = false ;
110111 m_TimestampsSupported = timestamps;
112+ m_NonBlockingSend = non_block_send;
111113
112114 if (m_SocketFd > 0 )
113115 {
@@ -170,8 +172,9 @@ class RawChannel : public Nan::ObjectWrap
170172 */
171173 static NAN_METHOD (New)
172174 {
173- bool timestamps = false ;
174- int protocol = CAN_RAW ;
175+ bool timestamps = false ;
176+ int protocol = CAN_RAW ;
177+ bool non_block_send = false ;
175178
176179 CHECK_CONDITION (info.IsConstructCall (), " Must be called with new" );
177180 CHECK_CONDITION (info.Length () >= 1 , " Too few arguments" );
@@ -191,7 +194,13 @@ class RawChannel : public Nan::ObjectWrap
191194 protocol = info[2 ]->IntegerValue (Nan::GetCurrentContext ()).FromJust ();
192195 }
193196
194- RawChannel* hw = new RawChannel (*ascii, timestamps, protocol);
197+ if (info.Length () >= 4 )
198+ {
199+ if (info[3 ]->IsBoolean ())
200+ non_block_send = info[3 ]->IsTrue ();
201+ }
202+
203+ RawChannel* hw = new RawChannel (*ascii, timestamps, protocol, non_block_send);
195204 hw->Wrap (info.This ());
196205
197206 CHECK_CONDITION (hw->IsValid (), " Error while creating channel" );
@@ -326,6 +335,11 @@ class RawChannel : public Nan::ObjectWrap
326335 }
327336 }
328337
338+ int flags = 0 ;
339+
340+ if (hw->m_NonBlockingSend )
341+ flags = MSG_DONTWAIT ;
342+
329343 int i = send (hw->m_SocketFd , &frame, sizeof (struct can_frame ), 0 );
330344
331345 info.GetReturnValue ().Set (i);
@@ -438,6 +452,7 @@ class RawChannel : public Nan::ObjectWrap
438452
439453 bool m_ThreadStopRequested;
440454 bool m_TimestampsSupported;
455+ bool m_NonBlockingSend;
441456
442457 static void * c_thread_entry (void *_this) { assert (_this); reinterpret_cast <RawChannel *>(_this)->ThreadEntry (); return NULL ; }
443458
0 commit comments