Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 403 lines (293 sloc) 11.262 kb
60818b9 ry Add missing copyright headers
ry authored
1 // Copyright Joyent, Inc. and other Node contributors.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to permit
8 // persons to whom the Software is furnished to do so, subject to the
9 // following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
ff4a9d3 Ben Noordhuis core: use proper #include directives
bnoordhuis authored
22 #include "node.h"
23 #include "node_buffer.h"
1ab95a5 Ben Noordhuis udp_wrap: use new slab allocator
bnoordhuis authored
24 #include "slab_allocator.h"
ff4a9d3 Ben Noordhuis core: use proper #include directives
bnoordhuis authored
25 #include "req_wrap.h"
26 #include "handle_wrap.h"
af98fc9 Fedor Indutny child_process: new stdio API for .spawn() method
indutny authored
27 #include "udp_wrap.h"
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
28
11e3cfc Ben Noordhuis dgram: integrate libuv support for UDP over IPv6
bnoordhuis authored
29 #include <stdlib.h>
30
1ab95a5 Ben Noordhuis udp_wrap: use new slab allocator
bnoordhuis authored
31 #define SLAB_SIZE (1024 * 1024)
32
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
33
34 using namespace v8;
35
36 namespace node {
37
1ab95a5 Ben Noordhuis udp_wrap: use new slab allocator
bnoordhuis authored
38 typedef ReqWrap<uv_udp_send_t> SendWrap;
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
39
8802196 Ben Noordhuis tcp, udp: share sockaddr-to-object function
bnoordhuis authored
40 // see tcp_wrap.cc
7c02b5a Ben Noordhuis udp_wrap: simplify AddressToJS() function
bnoordhuis authored
41 Local<Object> AddressToJS(const sockaddr* addr);
1ab95a5 Ben Noordhuis udp_wrap: use new slab allocator
bnoordhuis authored
42
43 static Persistent<String> buffer_sym;
a26bee8 isaacs MakeCallback: Consistent symbol usage
isaacs authored
44 static Persistent<String> oncomplete_sym;
45 static Persistent<String> onmessage_sym;
27061cc Ben Noordhuis udp_wrap, stream_wrap: lazy init slab allocator
bnoordhuis authored
46 static SlabAllocator* slab_allocator;
47
48
49 static void DeleteSlabAllocator(void*) {
50 delete slab_allocator;
51 slab_allocator = NULL;
52 }
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
53
bd9fa2e Michael Bernstein dgram: use slab memory allocator
mrb authored
54
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
55 UDPWrap::UDPWrap(Handle<Object> object): HandleWrap(object,
56 (uv_handle_t*)&handle_) {
74a8215 Ben Noordhuis Revert support for isolates.
bnoordhuis authored
57 int r = uv_udp_init(uv_default_loop(), &handle_);
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
58 assert(r == 0); // can't fail anyway
59 handle_.data = reinterpret_cast<void*>(this);
60 }
61
62
63 UDPWrap::~UDPWrap() {
64 }
65
66
67 void UDPWrap::Initialize(Handle<Object> target) {
68 HandleWrap::Initialize(target);
69
27061cc Ben Noordhuis udp_wrap, stream_wrap: lazy init slab allocator
bnoordhuis authored
70 slab_allocator = new SlabAllocator(SLAB_SIZE);
71 AtExit(DeleteSlabAllocator, NULL);
72
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
73 HandleScope scope;
74
75 buffer_sym = NODE_PSYMBOL("buffer");
a26bee8 isaacs MakeCallback: Consistent symbol usage
isaacs authored
76 oncomplete_sym = NODE_PSYMBOL("oncomplete");
77 onmessage_sym = NODE_PSYMBOL("onmessage");
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
78
79 Local<FunctionTemplate> t = FunctionTemplate::New(New);
80 t->InstanceTemplate()->SetInternalFieldCount(1);
81 t->SetClassName(String::NewSymbol("UDP"));
82
83 NODE_SET_PROTOTYPE_METHOD(t, "bind", Bind);
84 NODE_SET_PROTOTYPE_METHOD(t, "send", Send);
85 NODE_SET_PROTOTYPE_METHOD(t, "bind6", Bind6);
86 NODE_SET_PROTOTYPE_METHOD(t, "send6", Send6);
87 NODE_SET_PROTOTYPE_METHOD(t, "close", Close);
88 NODE_SET_PROTOTYPE_METHOD(t, "recvStart", RecvStart);
89 NODE_SET_PROTOTYPE_METHOD(t, "recvStop", RecvStop);
90 NODE_SET_PROTOTYPE_METHOD(t, "getsockname", GetSockName);
a38fd60 Roman Shtylman dgram: reintroduce addMembership() and dropMembership()
defunctzombie authored
91 NODE_SET_PROTOTYPE_METHOD(t, "addMembership", AddMembership);
92 NODE_SET_PROTOTYPE_METHOD(t, "dropMembership", DropMembership);
f2b1f57 Dan VerWeire dgram: reintroduce setMulticastTTL()
wankdanker authored
93 NODE_SET_PROTOTYPE_METHOD(t, "setMulticastTTL", SetMulticastTTL);
46e86aa Ben Noordhuis dgram: bring back setMulticastLoopback()
bnoordhuis authored
94 NODE_SET_PROTOTYPE_METHOD(t, "setMulticastLoopback", SetMulticastLoopback);
f749338 Dan VerWeire dgram: reintroduce setBroadcast()
wankdanker authored
95 NODE_SET_PROTOTYPE_METHOD(t, "setBroadcast", SetBroadcast);
2775c0e Ben Noordhuis dgram: bring back setTTL()
bnoordhuis authored
96 NODE_SET_PROTOTYPE_METHOD(t, "setTTL", SetTTL);
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
97
19d43f8 Timothy J Fontaine export HandleWrap Unref Ref in tcp/udp/timer/pipe
tjfontaine authored
98 NODE_SET_PROTOTYPE_METHOD(t, "ref", HandleWrap::Ref);
99 NODE_SET_PROTOTYPE_METHOD(t, "unref", HandleWrap::Unref);
100
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
101 target->Set(String::NewSymbol("UDP"),
102 Persistent<FunctionTemplate>::New(t)->GetFunction());
103 }
104
105
106 Handle<Value> UDPWrap::New(const Arguments& args) {
107 HandleScope scope;
108
109 assert(args.IsConstructCall());
110 new UDPWrap(args.This());
111
112 return scope.Close(args.This());
113 }
114
11e3cfc Ben Noordhuis dgram: integrate libuv support for UDP over IPv6
bnoordhuis authored
115 Handle<Value> UDPWrap::DoBind(const Arguments& args, int family) {
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
116 HandleScope scope;
11e3cfc Ben Noordhuis dgram: integrate libuv support for UDP over IPv6
bnoordhuis authored
117 int r;
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
118
45de259 Oleg Efimov Make UNWRAP macro generic.
Sannis authored
119 UNWRAP(UDPWrap)
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
120
121 // bind(ip, port, flags)
122 assert(args.Length() == 3);
123
249c3c1 Avoiding unnecessary ToString() calls
ssuda authored
124 String::Utf8Value address(args[0]);
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
125 const int port = args[1]->Uint32Value();
126 const int flags = args[2]->Uint32Value();
127
11e3cfc Ben Noordhuis dgram: integrate libuv support for UDP over IPv6
bnoordhuis authored
128 switch (family) {
129 case AF_INET:
130 r = uv_udp_bind(&wrap->handle_, uv_ip4_addr(*address, port), flags);
131 break;
132 case AF_INET6:
133 r = uv_udp_bind6(&wrap->handle_, uv_ip6_addr(*address, port), flags);
134 break;
135 default:
136 assert(0 && "unexpected address family");
137 abort();
138 }
139
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
140 if (r)
74a8215 Ben Noordhuis Revert support for isolates.
bnoordhuis authored
141 SetErrno(uv_last_error(uv_default_loop()));
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
142
143 return scope.Close(Integer::New(r));
144 }
145
146
11e3cfc Ben Noordhuis dgram: integrate libuv support for UDP over IPv6
bnoordhuis authored
147 Handle<Value> UDPWrap::Bind(const Arguments& args) {
148 return DoBind(args, AF_INET);
149 }
150
151
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
152 Handle<Value> UDPWrap::Bind6(const Arguments& args) {
11e3cfc Ben Noordhuis dgram: integrate libuv support for UDP over IPv6
bnoordhuis authored
153 return DoBind(args, AF_INET6);
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
154 }
155
f749338 Dan VerWeire dgram: reintroduce setBroadcast()
wankdanker authored
156
2775c0e Ben Noordhuis dgram: bring back setTTL()
bnoordhuis authored
157 #define X(name, fn) \
158 Handle<Value> UDPWrap::name(const Arguments& args) { \
159 HandleScope scope; \
45de259 Oleg Efimov Make UNWRAP macro generic.
Sannis authored
160 UNWRAP(UDPWrap) \
2775c0e Ben Noordhuis dgram: bring back setTTL()
bnoordhuis authored
161 assert(args.Length() == 1); \
162 int flag = args[0]->Int32Value(); \
163 int r = fn(&wrap->handle_, flag); \
164 if (r) SetErrno(uv_last_error(uv_default_loop())); \
165 return scope.Close(Integer::New(r)); \
166 }
f749338 Dan VerWeire dgram: reintroduce setBroadcast()
wankdanker authored
167
2775c0e Ben Noordhuis dgram: bring back setTTL()
bnoordhuis authored
168 X(SetTTL, uv_udp_set_ttl)
169 X(SetBroadcast, uv_udp_set_broadcast)
170 X(SetMulticastTTL, uv_udp_set_multicast_ttl)
171 X(SetMulticastLoopback, uv_udp_set_multicast_loop)
f749338 Dan VerWeire dgram: reintroduce setBroadcast()
wankdanker authored
172
2775c0e Ben Noordhuis dgram: bring back setTTL()
bnoordhuis authored
173 #undef X
f749338 Dan VerWeire dgram: reintroduce setBroadcast()
wankdanker authored
174
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
175
a38fd60 Roman Shtylman dgram: reintroduce addMembership() and dropMembership()
defunctzombie authored
176 Handle<Value> UDPWrap::SetMembership(const Arguments& args,
177 uv_membership membership) {
178 HandleScope scope;
45de259 Oleg Efimov Make UNWRAP macro generic.
Sannis authored
179 UNWRAP(UDPWrap)
a38fd60 Roman Shtylman dgram: reintroduce addMembership() and dropMembership()
defunctzombie authored
180
181 assert(args.Length() == 2);
182
249c3c1 Avoiding unnecessary ToString() calls
ssuda authored
183 String::Utf8Value address(args[0]);
184 String::Utf8Value iface(args[1]);
a38fd60 Roman Shtylman dgram: reintroduce addMembership() and dropMembership()
defunctzombie authored
185
b1b16d1 isaacs udp: 'interface' is reserved word on windows.
isaacs authored
186 const char* iface_cstr = *iface;
a38fd60 Roman Shtylman dgram: reintroduce addMembership() and dropMembership()
defunctzombie authored
187 if (args[1]->IsUndefined() || args[1]->IsNull()) {
b1b16d1 isaacs udp: 'interface' is reserved word on windows.
isaacs authored
188 iface_cstr = NULL;
a38fd60 Roman Shtylman dgram: reintroduce addMembership() and dropMembership()
defunctzombie authored
189 }
190
b1b16d1 isaacs udp: 'interface' is reserved word on windows.
isaacs authored
191 int r = uv_udp_set_membership(&wrap->handle_, *address, iface_cstr,
a38fd60 Roman Shtylman dgram: reintroduce addMembership() and dropMembership()
defunctzombie authored
192 membership);
193
194 if (r)
195 SetErrno(uv_last_error(uv_default_loop()));
196
197 return scope.Close(Integer::New(r));
198 }
199
200
201 Handle<Value> UDPWrap::AddMembership(const Arguments& args) {
202 return SetMembership(args, UV_JOIN_GROUP);
203 }
204
205
206 Handle<Value> UDPWrap::DropMembership(const Arguments& args) {
207 return SetMembership(args, UV_LEAVE_GROUP);
208 }
209
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
210
11e3cfc Ben Noordhuis dgram: integrate libuv support for UDP over IPv6
bnoordhuis authored
211 Handle<Value> UDPWrap::DoSend(const Arguments& args, int family) {
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
212 HandleScope scope;
11e3cfc Ben Noordhuis dgram: integrate libuv support for UDP over IPv6
bnoordhuis authored
213 int r;
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
214
215 // send(buffer, offset, length, port, address)
216 assert(args.Length() == 5);
217
45de259 Oleg Efimov Make UNWRAP macro generic.
Sannis authored
218 UNWRAP(UDPWrap)
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
219
220 assert(Buffer::HasInstance(args[0]));
221 Local<Object> buffer_obj = args[0]->ToObject();
222
223 size_t offset = args[1]->Uint32Value();
224 size_t length = args[2]->Uint32Value();
defa637 Ben Noordhuis dgram: fix out-of-bound memory read
bnoordhuis authored
225 assert(offset < Buffer::Length(buffer_obj));
226 assert(length <= Buffer::Length(buffer_obj) - offset);
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
227
228 SendWrap* req_wrap = new SendWrap();
229 req_wrap->object_->SetHiddenValue(buffer_sym, buffer_obj);
230
231 uv_buf_t buf = uv_buf_init(Buffer::Data(buffer_obj) + offset,
232 length);
233
234 const unsigned short port = args[3]->Uint32Value();
249c3c1 Avoiding unnecessary ToString() calls
ssuda authored
235 String::Utf8Value address(args[4]);
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
236
11e3cfc Ben Noordhuis dgram: integrate libuv support for UDP over IPv6
bnoordhuis authored
237 switch (family) {
238 case AF_INET:
239 r = uv_udp_send(&req_wrap->req_, &wrap->handle_, &buf, 1,
240 uv_ip4_addr(*address, port), OnSend);
241 break;
242 case AF_INET6:
243 r = uv_udp_send6(&req_wrap->req_, &wrap->handle_, &buf, 1,
244 uv_ip6_addr(*address, port), OnSend);
245 break;
246 default:
247 assert(0 && "unexpected address family");
248 abort();
249 }
250
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
251 req_wrap->Dispatched();
252
253 if (r) {
74a8215 Ben Noordhuis Revert support for isolates.
bnoordhuis authored
254 SetErrno(uv_last_error(uv_default_loop()));
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
255 delete req_wrap;
256 return Null();
257 }
258 else {
259 return scope.Close(req_wrap->object_);
260 }
261 }
262
263
11e3cfc Ben Noordhuis dgram: integrate libuv support for UDP over IPv6
bnoordhuis authored
264 Handle<Value> UDPWrap::Send(const Arguments& args) {
265 return DoSend(args, AF_INET);
266 }
267
268
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
269 Handle<Value> UDPWrap::Send6(const Arguments& args) {
11e3cfc Ben Noordhuis dgram: integrate libuv support for UDP over IPv6
bnoordhuis authored
270 return DoSend(args, AF_INET6);
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
271 }
272
273
274 Handle<Value> UDPWrap::RecvStart(const Arguments& args) {
275 HandleScope scope;
276
45de259 Oleg Efimov Make UNWRAP macro generic.
Sannis authored
277 UNWRAP(UDPWrap)
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
278
279 // UV_EALREADY means that the socket is already bound but that's okay
280 int r = uv_udp_recv_start(&wrap->handle_, OnAlloc, OnRecv);
74a8215 Ben Noordhuis Revert support for isolates.
bnoordhuis authored
281 if (r && uv_last_error(uv_default_loop()).code != UV_EALREADY) {
282 SetErrno(uv_last_error(uv_default_loop()));
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
283 return False();
284 }
285
286 return True();
287 }
288
289
290 Handle<Value> UDPWrap::RecvStop(const Arguments& args) {
291 HandleScope scope;
292
45de259 Oleg Efimov Make UNWRAP macro generic.
Sannis authored
293 UNWRAP(UDPWrap)
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
294
295 int r = uv_udp_recv_stop(&wrap->handle_);
296
297 return scope.Close(Integer::New(r));
298 }
299
300
301 Handle<Value> UDPWrap::GetSockName(const Arguments& args) {
302 HandleScope scope;
303 struct sockaddr_storage address;
304
45de259 Oleg Efimov Make UNWRAP macro generic.
Sannis authored
305 UNWRAP(UDPWrap)
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
306
307 int addrlen = sizeof(address);
c82ab45 Bert Belder uv_getsockname got renamed
piscisaureus authored
308 int r = uv_udp_getsockname(&wrap->handle_,
309 reinterpret_cast<sockaddr*>(&address),
310 &addrlen);
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
311
7c02b5a Ben Noordhuis udp_wrap: simplify AddressToJS() function
bnoordhuis authored
312 if (r) {
74a8215 Ben Noordhuis Revert support for isolates.
bnoordhuis authored
313 SetErrno(uv_last_error(uv_default_loop()));
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
314 return Null();
315 }
7c02b5a Ben Noordhuis udp_wrap: simplify AddressToJS() function
bnoordhuis authored
316
317 const sockaddr* addr = reinterpret_cast<const sockaddr*>(&address);
318 return scope.Close(AddressToJS(addr));
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
319 }
320
321
322 // TODO share with StreamWrap::AfterWrite() in stream_wrap.cc
323 void UDPWrap::OnSend(uv_udp_send_t* req, int status) {
324 HandleScope scope;
325
326 assert(req != NULL);
327
328 SendWrap* req_wrap = reinterpret_cast<SendWrap*>(req->data);
329 UDPWrap* wrap = reinterpret_cast<UDPWrap*>(req->handle->data);
330
331 assert(req_wrap->object_.IsEmpty() == false);
332 assert(wrap->object_.IsEmpty() == false);
333
334 if (status) {
74a8215 Ben Noordhuis Revert support for isolates.
bnoordhuis authored
335 SetErrno(uv_last_error(uv_default_loop()));
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
336 }
337
338 Local<Value> argv[4] = {
339 Integer::New(status),
340 Local<Value>::New(wrap->object_),
341 Local<Value>::New(req_wrap->object_),
342 req_wrap->object_->GetHiddenValue(buffer_sym),
343 };
344
a26bee8 isaacs MakeCallback: Consistent symbol usage
isaacs authored
345 MakeCallback(req_wrap->object_, oncomplete_sym, ARRAY_SIZE(argv), argv);
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
346 delete req_wrap;
347 }
348
349
350 uv_buf_t UDPWrap::OnAlloc(uv_handle_t* handle, size_t suggested_size) {
1ab95a5 Ben Noordhuis udp_wrap: use new slab allocator
bnoordhuis authored
351 UDPWrap* wrap = static_cast<UDPWrap*>(handle->data);
27061cc Ben Noordhuis udp_wrap, stream_wrap: lazy init slab allocator
bnoordhuis authored
352 char* buf = slab_allocator->Allocate(wrap->object_, suggested_size);
1ab95a5 Ben Noordhuis udp_wrap: use new slab allocator
bnoordhuis authored
353 return uv_buf_init(buf, suggested_size);
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
354 }
355
356
357 void UDPWrap::OnRecv(uv_udp_t* handle,
358 ssize_t nread,
359 uv_buf_t buf,
360 struct sockaddr* addr,
361 unsigned flags) {
32b2964 Ben Noordhuis udp: remove slab allocator
bnoordhuis authored
362 HandleScope scope;
363
1ab95a5 Ben Noordhuis udp_wrap: use new slab allocator
bnoordhuis authored
364 UDPWrap* wrap = reinterpret_cast<UDPWrap*>(handle->data);
27061cc Ben Noordhuis udp_wrap, stream_wrap: lazy init slab allocator
bnoordhuis authored
365 Local<Object> slab = slab_allocator->Shrink(wrap->object_,
366 buf.base,
367 nread < 0 ? 0 : nread);
1ab95a5 Ben Noordhuis udp_wrap: use new slab allocator
bnoordhuis authored
368 if (nread == 0) return;
369
370 if (nread < 0) {
371 Local<Value> argv[] = { Local<Object>::New(wrap->object_) };
372 SetErrno(uv_last_error(uv_default_loop()));
a26bee8 isaacs MakeCallback: Consistent symbol usage
isaacs authored
373 MakeCallback(wrap->object_, onmessage_sym, ARRAY_SIZE(argv), argv);
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
374 return;
375 }
376
1ab95a5 Ben Noordhuis udp_wrap: use new slab allocator
bnoordhuis authored
377 Local<Value> argv[] = {
f86359c Ben Noordhuis udp: root JS objects in HandleScope with Local<>
bnoordhuis authored
378 Local<Object>::New(wrap->object_),
1ab95a5 Ben Noordhuis udp_wrap: use new slab allocator
bnoordhuis authored
379 slab,
380 Integer::NewFromUnsigned(buf.base - Buffer::Data(slab)),
381 Integer::NewFromUnsigned(nread),
7c02b5a Ben Noordhuis udp_wrap: simplify AddressToJS() function
bnoordhuis authored
382 AddressToJS(addr)
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
383 };
a26bee8 isaacs MakeCallback: Consistent symbol usage
isaacs authored
384 MakeCallback(wrap->object_, onmessage_sym, ARRAY_SIZE(argv), argv);
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
385 }
386
387
af98fc9 Fedor Indutny child_process: new stdio API for .spawn() method
indutny authored
388 UDPWrap* UDPWrap::Unwrap(Local<Object> obj) {
389 assert(!obj.IsEmpty());
390 assert(obj->InternalFieldCount() > 0);
391 return static_cast<UDPWrap*>(obj->GetPointerFromInternalField(0));
392 }
393
394
395 uv_udp_t* UDPWrap::UVHandle() {
396 return &handle_;
397 }
398
399
cbd4033 Ben Noordhuis dgram: integrate libuv UDP support
bnoordhuis authored
400 } // namespace node
401
cdcb111 Ben Noordhuis Remove stray NODE_MODULE() semi-colons.
bnoordhuis authored
402 NODE_MODULE(node_udp_wrap, node::UDPWrap::Initialize)
Something went wrong with that request. Please try again.