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 |
|
|
|
22 |
|
|
#ifndef SRC_UDP_WRAP_H_ |
23 |
|
|
#define SRC_UDP_WRAP_H_ |
24 |
|
|
|
25 |
|
|
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
26 |
|
|
|
27 |
|
|
#include "async_wrap.h" |
28 |
|
|
#include "env.h" |
29 |
|
|
#include "handle_wrap.h" |
30 |
|
|
#include "uv.h" |
31 |
|
|
#include "v8.h" |
32 |
|
|
|
33 |
|
|
namespace node { |
34 |
|
|
|
35 |
✗✓ |
460 |
class UDPWrap: public HandleWrap { |
36 |
|
|
public: |
37 |
|
|
enum SocketType { |
38 |
|
|
SOCKET |
39 |
|
|
}; |
40 |
|
|
static void Initialize(v8::Local<v8::Object> target, |
41 |
|
|
v8::Local<v8::Value> unused, |
42 |
|
|
v8::Local<v8::Context> context, |
43 |
|
|
void* priv); |
44 |
|
|
static void GetFD(const v8::FunctionCallbackInfo<v8::Value>& args); |
45 |
|
|
static void New(const v8::FunctionCallbackInfo<v8::Value>& args); |
46 |
|
|
static void Open(const v8::FunctionCallbackInfo<v8::Value>& args); |
47 |
|
|
static void Bind(const v8::FunctionCallbackInfo<v8::Value>& args); |
48 |
|
|
static void Connect(const v8::FunctionCallbackInfo<v8::Value>& args); |
49 |
|
|
static void Send(const v8::FunctionCallbackInfo<v8::Value>& args); |
50 |
|
|
static void Bind6(const v8::FunctionCallbackInfo<v8::Value>& args); |
51 |
|
|
static void Connect6(const v8::FunctionCallbackInfo<v8::Value>& args); |
52 |
|
|
static void Send6(const v8::FunctionCallbackInfo<v8::Value>& args); |
53 |
|
|
static void Disconnect(const v8::FunctionCallbackInfo<v8::Value>& args); |
54 |
|
|
static void RecvStart(const v8::FunctionCallbackInfo<v8::Value>& args); |
55 |
|
|
static void RecvStop(const v8::FunctionCallbackInfo<v8::Value>& args); |
56 |
|
|
static void AddMembership(const v8::FunctionCallbackInfo<v8::Value>& args); |
57 |
|
|
static void DropMembership(const v8::FunctionCallbackInfo<v8::Value>& args); |
58 |
|
|
static void SetMulticastInterface( |
59 |
|
|
const v8::FunctionCallbackInfo<v8::Value>& args); |
60 |
|
|
static void SetMulticastTTL(const v8::FunctionCallbackInfo<v8::Value>& args); |
61 |
|
|
static void SetMulticastLoopback( |
62 |
|
|
const v8::FunctionCallbackInfo<v8::Value>& args); |
63 |
|
|
static void SetBroadcast(const v8::FunctionCallbackInfo<v8::Value>& args); |
64 |
|
|
static void SetTTL(const v8::FunctionCallbackInfo<v8::Value>& args); |
65 |
|
|
static void BufferSize(const v8::FunctionCallbackInfo<v8::Value>& args); |
66 |
|
|
|
67 |
|
|
static v8::MaybeLocal<v8::Object> Instantiate(Environment* env, |
68 |
|
|
AsyncWrap* parent, |
69 |
|
|
SocketType type); |
70 |
|
1 |
SET_NO_MEMORY_INFO() |
71 |
|
1 |
SET_MEMORY_INFO_NAME(UDPWrap) |
72 |
|
1 |
SET_SELF_SIZE(UDPWrap) |
73 |
|
|
|
74 |
|
|
private: |
75 |
|
|
typedef uv_udp_t HandleType; |
76 |
|
|
|
77 |
|
|
template <typename T, |
78 |
|
|
int (*F)(const typename T::HandleType*, sockaddr*, int*)> |
79 |
|
|
friend void GetSockOrPeerName(const v8::FunctionCallbackInfo<v8::Value>&); |
80 |
|
|
|
81 |
|
|
UDPWrap(Environment* env, v8::Local<v8::Object> object); |
82 |
|
|
|
83 |
|
|
static void DoBind(const v8::FunctionCallbackInfo<v8::Value>& args, |
84 |
|
|
int family); |
85 |
|
|
static void DoConnect(const v8::FunctionCallbackInfo<v8::Value>& args, |
86 |
|
|
int family); |
87 |
|
|
static void DoSend(const v8::FunctionCallbackInfo<v8::Value>& args, |
88 |
|
|
int family); |
89 |
|
|
static void SetMembership(const v8::FunctionCallbackInfo<v8::Value>& args, |
90 |
|
|
uv_membership membership); |
91 |
|
|
|
92 |
|
|
static void OnAlloc(uv_handle_t* handle, |
93 |
|
|
size_t suggested_size, |
94 |
|
|
uv_buf_t* buf); |
95 |
|
|
static void OnSend(uv_udp_send_t* req, int status); |
96 |
|
|
static void OnRecv(uv_udp_t* handle, |
97 |
|
|
ssize_t nread, |
98 |
|
|
const uv_buf_t* buf, |
99 |
|
|
const struct sockaddr* addr, |
100 |
|
|
unsigned int flags); |
101 |
|
|
|
102 |
|
|
uv_udp_t handle_; |
103 |
|
|
}; |
104 |
|
|
|
105 |
|
|
} // namespace node |
106 |
|
|
|
107 |
|
|
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
108 |
|
|
|
109 |
|
|
#endif // SRC_UDP_WRAP_H_ |