-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.cpp
executable file
·55 lines (41 loc) · 1.18 KB
/
run.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <nan.h>
#include <node.h>
#include <string>
#include <regex.h>
#include <sys/socket.h>
//#include <linux/tcp.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <unistd.h>
//using namespace v8;
using namespace std;
void run(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() < 1) {
Nan::ThrowTypeError("Wrong number of arguments (too few)");
return;
}
if (args.Length() > 1) {
Nan::ThrowTypeError("Wrong number of arguments (too many)");
return;
}
if (args[0]->IsString()) {
Nan::ThrowTypeError("First argument to 'modify-socket' must be a file descriptor.");
return;
}
int socket_fd = (int)(args[0]->Int32Value());
// v8::Int socket_fd(args[0]->ToInt());
// int socket_fd = args[0];
int i = true;
if(setsockopt(socket_fd, IPPROTO_TCP, TCP_QUICKACK, (void *)&i, sizeof(i)) < 0){
printf("setsockopt failed\n");
args.GetReturnValue().Set(false);
}
else{
printf("setsockopt succeeded\n");
args.GetReturnValue().Set(true);
}
}
void init(v8::Local<v8::Object> exports) {
NODE_SET_METHOD(exports, "run", run);
}
NODE_MODULE(run, init)