Skip to content

Commit 9aec6ab

Browse files
committed
Initial Commit
These are old files, part of an experiment. They need cleaning and commenting. There are too many references for me to remember after so long, but I will try to locate and list them, when I get time. This project currently does not compile, I am in the process of updating it to use node 0.12.4. Until then the source is good for reference, but not running.
1 parent 4dc473b commit 9aec6ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2998
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v8green/zdrive

v8green.sln

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.31101.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "v8green", "v8green\v8green.vcxproj", "{9679C45B-6B6D-4844-AE0C-C81BF2AE9B3F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Win32 = Debug|Win32
11+
Debug|x64 = Debug|x64
12+
Release|Win32 = Release|Win32
13+
Release|x64 = Release|x64
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{9679C45B-6B6D-4844-AE0C-C81BF2AE9B3F}.Debug|Win32.ActiveCfg = Debug|Win32
17+
{9679C45B-6B6D-4844-AE0C-C81BF2AE9B3F}.Debug|Win32.Build.0 = Debug|Win32
18+
{9679C45B-6B6D-4844-AE0C-C81BF2AE9B3F}.Debug|x64.ActiveCfg = Debug|x64
19+
{9679C45B-6B6D-4844-AE0C-C81BF2AE9B3F}.Debug|x64.Build.0 = Debug|x64
20+
{9679C45B-6B6D-4844-AE0C-C81BF2AE9B3F}.Release|Win32.ActiveCfg = Release|Win32
21+
{9679C45B-6B6D-4844-AE0C-C81BF2AE9B3F}.Release|Win32.Build.0 = Release|Win32
22+
{9679C45B-6B6D-4844-AE0C-C81BF2AE9B3F}.Release|x64.ActiveCfg = Release|x64
23+
{9679C45B-6B6D-4844-AE0C-C81BF2AE9B3F}.Release|x64.Build.0 = Release|x64
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
EndGlobal

v8green.v11.suo

93 KB
Binary file not shown.

v8green.v12.suo

128 KB
Binary file not shown.

v8green/CallBase.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "standard.h"
2+
3+
CallBase::CallBase() {
4+
cb = nullptr;
5+
overlapped.Internal = 0;
6+
overlapped.InternalHigh = 0;
7+
overlapped.Pointer = nullptr;
8+
overlapped.hEvent = nullptr;
9+
}
10+
11+
CallBase::operator LPOVERLAPPED() {
12+
return reinterpret_cast<LPOVERLAPPED>(this);
13+
}

v8green/CallBase.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
3+
typedef class CallBase {
4+
private:
5+
//#include "ClassHeap.h"
6+
public:
7+
typedef void (*PCBFUNC)(CallBase *obj, DWORD bytes, ULONG_PTR key);
8+
OVERLAPPED overlapped;
9+
PCBFUNC cb;
10+
LPVOID buffer;
11+
size_t bufferSize;
12+
CallBase();
13+
operator LPOVERLAPPED();
14+
static CallBase *cast(LPOVERLAPPED lpOverlaped) {
15+
return reinterpret_cast<pCallBase>(lpOverlaped);
16+
}
17+
static void dequeue(HANDLE CompletionPort, DWORD dwMilliseconds) {
18+
DWORD NumberOfBytes = 0;
19+
ULONG_PTR CompletionKey = 0;
20+
LPOVERLAPPED lpOverlapped = nullptr;
21+
BOOL ret = 0;
22+
mThrowFailureAllow({WAIT_TIMEOUT}, ret = GetQueuedCompletionStatus(CompletionPort, &NumberOfBytes, &CompletionKey, &lpOverlapped, dwMilliseconds));
23+
if(ret) {
24+
auto obj = cast(lpOverlapped);
25+
obj->cb(obj, NumberOfBytes, CompletionKey);
26+
}
27+
}
28+
} *pCallBase;
29+
30+
static_assert(offsetof(CallBase, overlapped) == 0, "CallBase::overlapped must be at offset 0");

v8green/CallClose.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "standard.h"
2+
3+
void CallClose::call() {
4+
DWORD bytesWritten = 0;
5+
mThrowFailure(QueryPerformanceCounter(&tickStart));
6+
mThrowFailure(CloseHandle(reinterpret_cast<HANDLE>(fd)));
7+
mThrowFailure(QueryPerformanceCounter(&tickEnd));
8+
// _InterlockedAdd64(&totalCounter, tickEnd.QuadPart - tickStart.QuadPart);
9+
csIsolate->protectedScope([this, bytesWritten](){
10+
v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate);
11+
auto cb = v8::Local<v8::Function>::New(isolate, callback);
12+
v8::Handle<v8::Value> args[1] = {v8::Undefined(isolate)};
13+
callback.Dispose();
14+
delete this;
15+
cb->Call(v8::Context::GetCurrent()->Global(), ARRAYSIZE(args), args);
16+
_InterlockedDecrement(&outStandingCallbacks);
17+
});
18+
}
19+
20+
CallClose::CallClose(uint32_t fd, v8::Persistent<v8::Function> callback):
21+
fd(fd), callback(callback) {
22+
// typeNum = stypeNum;
23+
_InterlockedIncrement(&outStandingCallbacks);
24+
}
25+
26+
void CallClose::call(const v8::FunctionCallbackInfo<v8::Value>& info) {
27+
v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate);
28+
if(info.Length() < 2) { return; }
29+
if(!info[0]->IsUint32()) { return; }
30+
if(!info[1]->IsFunction()) { return; }
31+
/*push(new CallClose(
32+
info[0]->Uint32Value(),
33+
v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(info[1]))
34+
));*/
35+
auto item = new CallClose(info[0]->Uint32Value(), v8::Persistent<v8::Function>::New(isolate, v8::Local<v8::Function>::Cast(info[1])));
36+
iocpCall.postEmptyLambda([](ULONG_PTR item){ ((CallClose*)item)->call(); }, (ULONG_PTR)item);
37+
return;
38+
}
39+
40+
void func_fs_closeSync(const v8::FunctionCallbackInfo<v8::Value>& info) {
41+
if(info.Length() < 1) { return; }
42+
v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate);
43+
HANDLE fd = reinterpret_cast<HANDLE>(info[0]->Uint32Value());
44+
mThrowFailure(CloseHandle(fd));
45+
return;
46+
}

v8green/CallClose.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
3+
#include "CallBase.h"
4+
5+
typedef class CallClose: public CallBase {
6+
public:
7+
//#include "ClassHeap.h"
8+
//static volatile LONG64 totalCounter;
9+
LARGE_INTEGER tickStart;
10+
LARGE_INTEGER tickEnd;
11+
// const static auto stypeNum = CallID::CallCloseID;
12+
13+
uint32_t fd;
14+
v8::Persistent<v8::Function> callback;
15+
16+
void call();
17+
CallClose(uint32_t fd, v8::Persistent<v8::Function> callback);
18+
static void call(const v8::FunctionCallbackInfo<v8::Value>& info);
19+
20+
21+
} *pCallClose;
22+
23+
//#include "ClassHeapDef.h"
24+
//ClassHeapDef(CallClose)
25+
//volatile int64_t CallClose::totalCounter = 0;
26+
27+
void func_fs_closeSync(const v8::FunctionCallbackInfo<v8::Value>& info);

v8green/CallOpen.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include "standard.h"
2+
3+
CallOpen::CallOpen(v8::Local<v8::String> filename, v8::Local<v8::Function> pcb): WSfilename(reinterpret_cast<wchar_t*>(v8::String::Value(filename).operator*())), pcb(v8::Persistent<v8::Function>::New(pcb)) {
4+
//typeNum = stypeNum;
5+
_InterlockedIncrement(&outStandingCallbacks);
6+
//PostQueuedCompletionStatus();
7+
// iocpCall.postEmptyLambda(static_cbfuncB, this);
8+
}
9+
10+
void CallOpen::call() {
11+
DWORD bytesWritten = 0;
12+
QueryPerformanceCounter(&tickStart);
13+
HANDLE handle;
14+
#define USE_OVERLAPPED
15+
#ifdef USE_OVERLAPPED
16+
mThrowFailure(handle = CreateFile(WSfilename.c_str(), GENERIC_WRITE, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_OVERLAPPED, nullptr));
17+
#else
18+
mThrowFailure(handle = CreateFile(WSfilename.c_str(), GENERIC_WRITE, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_SEQUENTIAL_SCAN, nullptr));
19+
#endif
20+
auto tcb = [this]() {
21+
puts("tcb");
22+
DebugBreak();
23+
};
24+
//iocpCall.addHandle(reinterpret_cast<HANDLE>(handle), reinterpret_cast<ULONG_PTR>(&tcb));
25+
#undef USE_OVERLAPPED
26+
mThrowFailure(QueryPerformanceCounter(&tickEnd));
27+
// _InterlockedAdd64(&totalCounter, tickEnd.QuadPart - tickStart.QuadPart);
28+
csIsolate->protectedScope([this, handle](){
29+
v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate);
30+
v8::Handle<v8::Value> args[2] = {v8::Undefined(isolate), v8::Uint32::NewFromUnsigned(isolate, reinterpret_cast<uint32_t>(handle))};
31+
auto cb = v8::Local<v8::Function>::New(isolate, pcb);
32+
pcb.Dispose();
33+
delete this;
34+
cb->Call(v8::Context::GetCurrent()->Global(), ARRAYSIZE(args), args);
35+
_InterlockedDecrement(&outStandingCallbacks);
36+
});
37+
}
38+
39+
void CallOpen::empty() {
40+
}
41+
42+
void CallOpen::call(const v8::FunctionCallbackInfo<v8::Value>& info) {
43+
if(info.Length() < 3) { return; }
44+
if(!info[0]->IsString()) { return; }
45+
if(!info[1]->IsString()) { return; }
46+
if(!info[2]->IsFunction()) { return; }
47+
v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate);
48+
//push(new CallOpen(v8::Local<v8::String>::Cast(info[0]), v8::Local<v8::Function>::Cast(info[2])));
49+
auto item = new CallOpen(v8::Local<v8::String>::Cast(info[0]), v8::Local<v8::Function>::Cast(info[2]));
50+
iocpCall.postEmptyLambda([](ULONG_PTR item){
51+
((CallOpen*)item)->call();
52+
}, (ULONG_PTR)item);
53+
//fixme
54+
return;
55+
}
56+
57+
void CallOpen::cbfunc(DWORD bytes, ULONG_PTR key) {
58+
printf("CallOpen(%p)::cbfunc(%u, %I64u);\n", this, bytes, key);
59+
call();
60+
}
61+
62+
void CallOpen::static_cbfunc(CallOpen *obj, DWORD bytes, ULONG_PTR key) {
63+
printf("CallOpen::static_cbfunc(%p, %u, %I64u);\n", obj, bytes, key);
64+
obj->cbfunc(bytes, key);
65+
}
66+
67+
void func_fs_openSync(const v8::FunctionCallbackInfo<v8::Value>& info) {
68+
if(info.Length() < 2) { return; }
69+
if(!info[0]->IsString()) { return; }
70+
if(!info[1]->IsString()) { return; }
71+
v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate);
72+
73+
HANDLE handle;
74+
mThrowFailure(handle = CreateFile(reinterpret_cast<wchar_t*>(v8::String::Value(v8::Local<v8::String>::Cast(info[0])).operator*()), GENERIC_WRITE, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_OVERLAPPED, nullptr));
75+
return scope.Close(v8::Uint32::NewFromUnsigned(reinterpret_cast<uint32_t>(handle)));
76+
}

v8green/CallOpen.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
typedef class CallOpen: public CallBase {
4+
public:
5+
//#include "ClassHeap.h"
6+
LARGE_INTEGER tickStart;
7+
LARGE_INTEGER tickEnd;
8+
// const static auto stypeNum = CallID::CallOpenID;
9+
//static volatile LONG64 totalCounter;
10+
std::wstring WSfilename;
11+
v8::Persistent<v8::Function> pcb;
12+
CallOpen(v8::Local<v8::String> filename, v8::Local<v8::Function> pcb);
13+
14+
void call();
15+
16+
static void empty();
17+
18+
static void call(const v8::FunctionCallbackInfo<v8::Value>& info);
19+
void cbfunc(DWORD bytes, ULONG_PTR key);
20+
static void static_cbfunc(CallOpen *obj, DWORD bytes, ULONG_PTR key);
21+
static void static_cbfuncB(CallOpen *obj) {
22+
obj->call();
23+
}
24+
} *pCallOpen;
25+
//#include "ClassHeapDef.h"
26+
//ClassHeapDef(CallOpen)
27+
//volatile int64_t CallOpen::totalCounter = 0;
28+
29+
void func_fs_openSync(const v8::FunctionCallbackInfo<v8::Value>& info);

0 commit comments

Comments
 (0)