Use fcntl to fix non-closing sockets
This commit is contained in:
parent
1a7bba516d
commit
9fa4a03434
19 changed files with 1331 additions and 566 deletions
121
.clang-format
Normal file
121
.clang-format
Normal file
|
@ -0,0 +1,121 @@
|
|||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: MultiLine
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterClass: false
|
||||
AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IndentCaseLabels: false
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 2
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Cpp11
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 8
|
||||
UseTab: Never
|
||||
...
|
||||
|
15
.gitignore
vendored
15
.gitignore
vendored
|
@ -50,3 +50,18 @@ _deps
|
|||
*-prefix/
|
||||
|
||||
# End of https://www.gitignore.io/api/cmake
|
||||
|
||||
# Created by https://www.gitignore.io/api/vagrant
|
||||
# Edit at https://www.gitignore.io/?templates=vagrant
|
||||
|
||||
### Vagrant ###
|
||||
# General
|
||||
.vagrant/
|
||||
|
||||
# Log files (if you are creating logs in debug mode, uncomment this)
|
||||
# *.log
|
||||
|
||||
### Vagrant Patch ###
|
||||
*.box
|
||||
|
||||
# End of https://www.gitignore.io/api/vagrant
|
||||
|
|
|
@ -3,5 +3,4 @@ project(angel_wings)
|
|||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_dart_utils/cmake")
|
||||
find_package(Dart REQUIRED)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
add_subdirectory(lib/src)
|
||||
install(TARGETS angel_wings LIBRARY DESTINATION "${CMAKE_CURRENT_LIST_DIR}")
|
||||
add_subdirectory(lib/src)
|
6
Vagrantfile
vendored
Normal file
6
Vagrantfile
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "ubuntu/bionic64"
|
||||
config.vm.provision "shell", path: "provision.sh"
|
||||
end
|
|
@ -5,3 +5,4 @@ add_dart_native_extension(angel_wings
|
|||
bind.cc http.cc wings_socket.cc
|
||||
util.cc)
|
||||
install(TARGETS angel_wings LIBRARY DESTINATION "${CMAKE_CURRENT_LIST_DIR}")
|
||||
install(TARGETS angel_wings LIBRARY DESTINATION "${CMAKE_CURRENT_LIST_DIR}/../..")
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
#include "angel_wings.h"
|
||||
#include <cstdlib>
|
||||
#include <dart_api.h>
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
#include <dart_api.h>
|
||||
#include "angel_wings.h"
|
||||
|
||||
// The name of the initialization function is the extension name followed
|
||||
// by _Init.
|
||||
DART_EXPORT Dart_Handle angel_wings_Init(Dart_Handle parent_library)
|
||||
{
|
||||
DART_EXPORT Dart_Handle angel_wings_Init(Dart_Handle parent_library) {
|
||||
if (Dart_IsError(parent_library))
|
||||
return parent_library;
|
||||
|
||||
|
@ -19,15 +18,14 @@ DART_EXPORT Dart_Handle angel_wings_Init(Dart_Handle parent_library)
|
|||
return Dart_Null();
|
||||
}
|
||||
|
||||
Dart_Handle HandleError(Dart_Handle handle)
|
||||
{
|
||||
Dart_Handle HandleError(Dart_Handle handle) {
|
||||
if (Dart_IsError(handle))
|
||||
Dart_PropagateError(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
Dart_NativeFunction ResolveName(Dart_Handle name, int argc, bool *auto_setup_scope)
|
||||
{
|
||||
Dart_NativeFunction ResolveName(Dart_Handle name, int argc,
|
||||
bool *auto_setup_scope) {
|
||||
// If we fail, we return NULL, and Dart throws an exception.
|
||||
if (!Dart_IsString(name))
|
||||
return NULL;
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
#ifndef ANGEL_WINGS_WINGS_H
|
||||
#define ANGEL_WINGS_WINGS_H
|
||||
|
||||
#include "angel_wings.h"
|
||||
#include <dart_api.h>
|
||||
#include <dart_native_api.h>
|
||||
#include "angel_wings.h"
|
||||
|
||||
Dart_NativeFunction ResolveName(Dart_Handle name, int argc, bool *auto_setup_scope);
|
||||
Dart_NativeFunction ResolveName(Dart_Handle name, int argc,
|
||||
bool *auto_setup_scope);
|
||||
Dart_Handle HandleError(Dart_Handle handle);
|
||||
|
||||
void wingsThrowError(const char *msg, const char *lib = "dart:core", const char *name = "StateError", int n = -1);
|
||||
void wingsThrowError(const char *msg, const char *lib = "dart:core",
|
||||
const char *name = "StateError", int n = -1);
|
||||
void Dart_WingsSocket_bindIPv4(Dart_NativeArguments arguments);
|
||||
void Dart_WingsSocket_bindIPv6(Dart_NativeArguments arguments);
|
||||
void Dart_WingsSocket_getAddress(Dart_NativeArguments arguments);
|
||||
|
|
246
lib/src/bind.cc
246
lib/src/bind.cc
|
@ -1,169 +1,161 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "angel_wings.h"
|
||||
#include "wings_socket.h"
|
||||
#include <fcntl.h>
|
||||
#include <vector>
|
||||
using namespace wings;
|
||||
|
||||
void getWingsSocketInfo(Dart_NativeArguments arguments, WingsSocketInfo *info);
|
||||
|
||||
WingsSocket *wingsFindSocket(Dart_NativeArguments arguments, const WingsSocketInfo &info, int af);
|
||||
WingsSocket *wingsFindSocket(Dart_NativeArguments arguments,
|
||||
const WingsSocketInfo &info, int af);
|
||||
|
||||
WingsSocket *wingsBindNewSocket(Dart_NativeArguments arguments, const WingsSocketInfo &info, int af);
|
||||
WingsSocket *wingsBindNewSocket(Dart_NativeArguments arguments,
|
||||
const WingsSocketInfo &info, int af);
|
||||
|
||||
void wingsReturnBound(Dart_NativeArguments arguments, WingsSocket *socket);
|
||||
|
||||
void Dart_WingsSocket_bind(sa_family_t af, Dart_NativeArguments arguments)
|
||||
{
|
||||
WingsSocketInfo info;
|
||||
getWingsSocketInfo(arguments, &info);
|
||||
WingsSocket *socket = wingsFindSocket(arguments, info, af);
|
||||
wingsReturnBound(arguments, socket);
|
||||
void Dart_WingsSocket_bind(sa_family_t af, Dart_NativeArguments arguments) {
|
||||
WingsSocketInfo info;
|
||||
getWingsSocketInfo(arguments, &info);
|
||||
WingsSocket *socket = wingsFindSocket(arguments, info, af);
|
||||
wingsReturnBound(arguments, socket);
|
||||
}
|
||||
|
||||
void Dart_WingsSocket_bindIPv4(Dart_NativeArguments arguments)
|
||||
{
|
||||
Dart_WingsSocket_bind(AF_INET, arguments);
|
||||
void Dart_WingsSocket_bindIPv4(Dart_NativeArguments arguments) {
|
||||
Dart_WingsSocket_bind(AF_INET, arguments);
|
||||
}
|
||||
|
||||
void Dart_WingsSocket_bindIPv6(Dart_NativeArguments arguments)
|
||||
{
|
||||
Dart_WingsSocket_bind(AF_INET6, arguments);
|
||||
void Dart_WingsSocket_bindIPv6(Dart_NativeArguments arguments) {
|
||||
Dart_WingsSocket_bind(AF_INET6, arguments);
|
||||
}
|
||||
|
||||
void wingsReturnBound(Dart_NativeArguments arguments, WingsSocket *socket)
|
||||
{
|
||||
Dart_Port sendPort;
|
||||
HandleError(Dart_SendPortGetId(Dart_GetNativeArgument(arguments, 5), &sendPort));
|
||||
socket->incrRef(sendPort);
|
||||
auto ptr = (uint64_t)socket;
|
||||
Dart_Handle ptrHandle = Dart_NewIntegerFromUint64(ptr);
|
||||
Dart_SetReturnValue(arguments, ptrHandle);
|
||||
void wingsReturnBound(Dart_NativeArguments arguments, WingsSocket *socket) {
|
||||
Dart_Port sendPort;
|
||||
HandleError(
|
||||
Dart_SendPortGetId(Dart_GetNativeArgument(arguments, 5), &sendPort));
|
||||
socket->incrRef(sendPort);
|
||||
auto ptr = (uint64_t)socket;
|
||||
Dart_Handle ptrHandle = Dart_NewIntegerFromUint64(ptr);
|
||||
Dart_SetReturnValue(arguments, ptrHandle);
|
||||
}
|
||||
|
||||
WingsSocket *wingsFindSocket(Dart_NativeArguments arguments, const WingsSocketInfo &info, int af)
|
||||
{
|
||||
// Find an existing server, if any.
|
||||
if (info.shared)
|
||||
{
|
||||
// std::cout << info.address << std::endl;
|
||||
// std::cout << globalSocketList.size() << std::endl;
|
||||
for (auto *socket : globalSocketList)
|
||||
{
|
||||
if (info.equals(socket->getInfo()))
|
||||
{
|
||||
return socket;
|
||||
}
|
||||
}
|
||||
WingsSocket *wingsFindSocket(Dart_NativeArguments arguments,
|
||||
const WingsSocketInfo &info, int af) {
|
||||
// Find an existing server, if any.
|
||||
if (info.shared) {
|
||||
// std::cout << info.address << std::endl;
|
||||
// std::cout << globalSocketList.size() << std::endl;
|
||||
for (auto *socket : globalSocketList) {
|
||||
if (info.equals(socket->getInfo())) {
|
||||
return socket;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return wingsBindNewSocket(arguments, info, af);
|
||||
return wingsBindNewSocket(arguments, info, af);
|
||||
}
|
||||
|
||||
WingsSocket *wingsBindNewSocket(Dart_NativeArguments arguments, const WingsSocketInfo &info, int af)
|
||||
{
|
||||
sockaddr *addr;
|
||||
sockaddr_in v4;
|
||||
sockaddr_in6 v6;
|
||||
int ret;
|
||||
WingsSocket *wingsBindNewSocket(Dart_NativeArguments arguments,
|
||||
const WingsSocketInfo &info, int af) {
|
||||
sockaddr *addr;
|
||||
sockaddr_in v4;
|
||||
sockaddr_in6 v6;
|
||||
int ret;
|
||||
|
||||
int sock = socket(af, SOCK_STREAM, IPPROTO_TCP);
|
||||
int sock = socket(af, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
if (sock < 0)
|
||||
{
|
||||
wingsThrowError("Failed to create socket.");
|
||||
return nullptr;
|
||||
}
|
||||
if (sock < 0) {
|
||||
wingsThrowError("Failed to create socket.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int i = 1;
|
||||
ret = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
|
||||
int i = 1;
|
||||
ret = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
wingsThrowError("Cannot reuse address for socket.");
|
||||
return nullptr;
|
||||
}
|
||||
if (ret < 0) {
|
||||
wingsThrowError("Cannot reuse address for socket.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// TODO: Only on Mac???
|
||||
// ret = setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &i, sizeof(i));
|
||||
// TODO: Only on Mac???
|
||||
// ret = setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &i, sizeof(i));
|
||||
|
||||
// if (ret < 0)
|
||||
// {
|
||||
// wingsThrowStateError("Cannot reuse port for socket.");
|
||||
// return;
|
||||
// }
|
||||
// if (ret < 0)
|
||||
// {
|
||||
// wingsThrowStateError("Cannot reuse port for socket.");
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (af == AF_INET6)
|
||||
{
|
||||
v6.sin6_family = AF_INET6;
|
||||
v6.sin6_port = htons((uint16_t)info.port);
|
||||
ret = inet_pton(AF_INET6, info.address, &v6.sin6_addr.s6_addr);
|
||||
if (ret >= 0)
|
||||
ret = bind(sock, (const sockaddr *)&v6, sizeof(v6));
|
||||
}
|
||||
else
|
||||
{
|
||||
v4.sin_family = AF_INET;
|
||||
v4.sin_port = htons((uint16_t)info.port);
|
||||
v4.sin_addr.s_addr = inet_addr(info.address);
|
||||
bind(sock, (const sockaddr *)&v4, sizeof(v4));
|
||||
}
|
||||
if (af == AF_INET6) {
|
||||
v6.sin6_family = AF_INET6;
|
||||
v6.sin6_port = htons((uint16_t)info.port);
|
||||
ret = inet_pton(AF_INET6, info.address, &v6.sin6_addr.s6_addr);
|
||||
if (ret >= 0)
|
||||
ret = bind(sock, (const sockaddr *)&v6, sizeof(v6));
|
||||
} else {
|
||||
v4.sin_family = AF_INET;
|
||||
v4.sin_port = htons((uint16_t)info.port);
|
||||
v4.sin_addr.s_addr = inet_addr(info.address);
|
||||
bind(sock, (const sockaddr *)&v4, sizeof(v4));
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
wingsThrowError("Failed to bind socket.");
|
||||
return nullptr;
|
||||
}
|
||||
if (ret < 0) {
|
||||
wingsThrowError("Failed to bind socket.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (listen(sock, SOMAXCONN) < 0)
|
||||
{
|
||||
wingsThrowError("Failed to set SOMAXCONN on bound socket.");
|
||||
return nullptr;
|
||||
}
|
||||
if (listen(sock, SOMAXCONN) < 0) {
|
||||
wingsThrowError("Failed to set SOMAXCONN on bound socket.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (listen(sock, (int)info.backlog) < 0)
|
||||
{
|
||||
wingsThrowError("Failed to set backlog on bound socket.");
|
||||
return nullptr;
|
||||
}
|
||||
if (listen(sock, (int)info.backlog) < 0) {
|
||||
wingsThrowError("Failed to set backlog on bound socket.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto *out = new WingsSocket(af, sock, info);
|
||||
globalSocketList.push_back(out);
|
||||
return out;
|
||||
if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1) {
|
||||
wingsThrowError("Failed to make socket non-blocking.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto *out = new WingsSocket(af, sock, info);
|
||||
globalSocketList.push_back(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
void getWingsSocketInfo(Dart_NativeArguments arguments, WingsSocketInfo *info)
|
||||
{
|
||||
Dart_Handle addressHandle = Dart_GetNativeArgument(arguments, 0);
|
||||
Dart_Handle portHandle = Dart_GetNativeArgument(arguments, 1);
|
||||
Dart_Handle sharedHandle = Dart_GetNativeArgument(arguments, 2);
|
||||
Dart_Handle backlogHandle = Dart_GetNativeArgument(arguments, 3);
|
||||
Dart_Handle v6OnlyHandle = Dart_GetNativeArgument(arguments, 4);
|
||||
info->sendPortHandle = Dart_GetNativeArgument(arguments, 5);
|
||||
void getWingsSocketInfo(Dart_NativeArguments arguments, WingsSocketInfo *info) {
|
||||
Dart_Handle addressHandle = Dart_GetNativeArgument(arguments, 0);
|
||||
Dart_Handle portHandle = Dart_GetNativeArgument(arguments, 1);
|
||||
Dart_Handle sharedHandle = Dart_GetNativeArgument(arguments, 2);
|
||||
Dart_Handle backlogHandle = Dart_GetNativeArgument(arguments, 3);
|
||||
Dart_Handle v6OnlyHandle = Dart_GetNativeArgument(arguments, 4);
|
||||
info->sendPortHandle = Dart_GetNativeArgument(arguments, 5);
|
||||
|
||||
HandleError(Dart_StringToCString(addressHandle, &info->address));
|
||||
HandleError(Dart_IntegerToUint64(portHandle, &info->port));
|
||||
HandleError(Dart_BooleanValue(sharedHandle, &info->shared));
|
||||
HandleError(Dart_IntegerToUint64(backlogHandle, &info->backlog));
|
||||
HandleError(Dart_BooleanValue(v6OnlyHandle, &info->v6Only));
|
||||
HandleError(Dart_StringToCString(addressHandle, &info->address));
|
||||
HandleError(Dart_IntegerToUint64(portHandle, &info->port));
|
||||
HandleError(Dart_BooleanValue(sharedHandle, &info->shared));
|
||||
HandleError(Dart_IntegerToUint64(backlogHandle, &info->backlog));
|
||||
HandleError(Dart_BooleanValue(v6OnlyHandle, &info->v6Only));
|
||||
}
|
||||
|
||||
void wingsThrowError(const char *msg, const char *lib, const char *name, int n)
|
||||
{
|
||||
Dart_Handle msgHandle = Dart_NewStringFromCString(msg);
|
||||
Dart_Handle emptyHandle = Dart_NewStringFromCString("");
|
||||
Dart_Handle stateErrorHandle = Dart_NewStringFromCString(name);
|
||||
Dart_Handle dartCoreHandle = Dart_NewStringFromCString(lib);
|
||||
Dart_Handle dartCore = Dart_LookupLibrary(dartCoreHandle);
|
||||
Dart_Handle stateError = Dart_GetType(dartCore, stateErrorHandle, 0, nullptr);
|
||||
void wingsThrowError(const char *msg, const char *lib, const char *name,
|
||||
int n) {
|
||||
Dart_Handle msgHandle = Dart_NewStringFromCString(msg);
|
||||
Dart_Handle emptyHandle = Dart_NewStringFromCString("");
|
||||
Dart_Handle stateErrorHandle = Dart_NewStringFromCString(name);
|
||||
Dart_Handle dartCoreHandle = Dart_NewStringFromCString(lib);
|
||||
Dart_Handle dartCore = Dart_LookupLibrary(dartCoreHandle);
|
||||
Dart_Handle stateError = Dart_GetType(dartCore, stateErrorHandle, 0, nullptr);
|
||||
|
||||
std::vector<Dart_Handle> args;
|
||||
args.push_back(msgHandle);
|
||||
std::vector<Dart_Handle> args;
|
||||
args.push_back(msgHandle);
|
||||
|
||||
if (n > -1)
|
||||
{
|
||||
args.push_back(Dart_NewInteger(n));
|
||||
}
|
||||
if (n > -1) {
|
||||
args.push_back(Dart_NewInteger(n));
|
||||
}
|
||||
|
||||
Dart_Handle errHandle = Dart_New(stateError, emptyHandle, args.size(), args.data());
|
||||
Dart_ThrowException(errHandle);
|
||||
Dart_Handle errHandle =
|
||||
Dart_New(stateError, emptyHandle, args.size(), args.data());
|
||||
Dart_ThrowException(errHandle);
|
||||
}
|
309
lib/src/http.cc
309
lib/src/http.cc
|
@ -1,192 +1,175 @@
|
|||
#include <iostream>
|
||||
#include <http-parser/http_parser.h>
|
||||
#include <cstring>
|
||||
|
||||
#include "angel_wings.h"
|
||||
#include "wings_socket.h"
|
||||
#include <http-parser/http_parser.h>
|
||||
#include <iostream>
|
||||
using namespace wings;
|
||||
|
||||
void Dart_WingsSocket_parseHttp(Dart_NativeArguments arguments)
|
||||
{
|
||||
Dart_Port service_port =
|
||||
Dart_NewNativePort("WingsHttpCallback", &wingsHttpCallback, true);
|
||||
Dart_Handle send_port = Dart_NewSendPort(service_port);
|
||||
Dart_SetReturnValue(arguments, send_port);
|
||||
void Dart_WingsSocket_parseHttp(Dart_NativeArguments arguments) {
|
||||
Dart_Port service_port =
|
||||
Dart_NewNativePort("WingsHttpCallback", &wingsHttpCallback, true);
|
||||
Dart_Handle send_port = Dart_NewSendPort(service_port);
|
||||
Dart_SetReturnValue(arguments, send_port);
|
||||
}
|
||||
|
||||
struct wingsHttp
|
||||
{
|
||||
Dart_Port port;
|
||||
std::string lastHeader;
|
||||
struct wingsHttp {
|
||||
Dart_Port port;
|
||||
std::string lastHeader;
|
||||
};
|
||||
|
||||
void wingsHttpCallback(Dart_Port dest_port_id, Dart_CObject *message)
|
||||
{
|
||||
int64_t fd = -1;
|
||||
Dart_Port outPort = message->value.as_array.values[0]->value.as_send_port.id;
|
||||
Dart_CObject *fdArg = message->value.as_array.values[1];
|
||||
void wingsHttpCallback(Dart_Port dest_port_id, Dart_CObject *message) {
|
||||
int64_t fd = -1;
|
||||
Dart_Port outPort = message->value.as_array.values[0]->value.as_send_port.id;
|
||||
Dart_CObject *fdArg = message->value.as_array.values[1];
|
||||
|
||||
wingsHttp httpData = {outPort};
|
||||
wingsHttp httpData = {outPort};
|
||||
|
||||
#define theStruct (*((wingsHttp *)parser->data))
|
||||
#define thePort theStruct.port
|
||||
#define sendInt(n) \
|
||||
{ \
|
||||
Dart_CObject obj; \
|
||||
obj.type = Dart_CObject_kInt64; \
|
||||
obj.value.as_int64 = (n); \
|
||||
Dart_PostCObject(thePort, &obj); \
|
||||
}
|
||||
#define sendString(n) \
|
||||
if (length > 0) \
|
||||
{ \
|
||||
Dart_CObject typeObj; \
|
||||
typeObj.type = Dart_CObject_kInt32; \
|
||||
typeObj.value.as_int32 = (n); \
|
||||
std::string str(at, length); \
|
||||
Dart_CObject strObj; \
|
||||
strObj.type = Dart_CObject_kString; \
|
||||
strObj.value.as_string = (char *)str.c_str(); \
|
||||
Dart_CObject *values[2] = {&typeObj, &strObj}; \
|
||||
Dart_CObject out; \
|
||||
out.type = Dart_CObject_kArray; \
|
||||
out.value.as_array.length = 2; \
|
||||
out.value.as_array.values = values; \
|
||||
Dart_PostCObject(thePort, &out); \
|
||||
}
|
||||
#define sendInt(n) \
|
||||
{ \
|
||||
Dart_CObject obj; \
|
||||
obj.type = Dart_CObject_kInt64; \
|
||||
obj.value.as_int64 = (n); \
|
||||
Dart_PostCObject(thePort, &obj); \
|
||||
}
|
||||
#define sendString(n) \
|
||||
if (length > 0) { \
|
||||
Dart_CObject typeObj; \
|
||||
typeObj.type = Dart_CObject_kInt32; \
|
||||
typeObj.value.as_int32 = (n); \
|
||||
std::string str(at, length); \
|
||||
Dart_CObject strObj; \
|
||||
strObj.type = Dart_CObject_kString; \
|
||||
strObj.value.as_string = (char *)str.c_str(); \
|
||||
Dart_CObject *values[2] = {&typeObj, &strObj}; \
|
||||
Dart_CObject out; \
|
||||
out.type = Dart_CObject_kArray; \
|
||||
out.value.as_array.length = 2; \
|
||||
out.value.as_array.values = values; \
|
||||
Dart_PostCObject(thePort, &out); \
|
||||
}
|
||||
|
||||
if (fdArg->type == Dart_CObject_kInt32)
|
||||
{
|
||||
fd = (int64_t)fdArg->value.as_int32;
|
||||
}
|
||||
else
|
||||
{
|
||||
fd = fdArg->value.as_int64;
|
||||
}
|
||||
if (fdArg->type == Dart_CObject_kInt32) {
|
||||
fd = (int64_t)fdArg->value.as_int32;
|
||||
} else {
|
||||
fd = fdArg->value.as_int64;
|
||||
}
|
||||
|
||||
if (fd != -1)
|
||||
{
|
||||
http_parser_settings settings;
|
||||
if (fd != -1) {
|
||||
http_parser_settings settings;
|
||||
|
||||
settings.on_message_begin = [](http_parser *parser) {
|
||||
return 0;
|
||||
};
|
||||
settings.on_message_begin = [](http_parser *parser) { return 0; };
|
||||
|
||||
settings.on_headers_complete = [](http_parser *parser) {
|
||||
Dart_CObject type;
|
||||
type.type = Dart_CObject_kInt32;
|
||||
type.value.as_int32 = 2;
|
||||
Dart_CObject value;
|
||||
value.type = Dart_CObject_kInt32;
|
||||
value.value.as_int32 = parser->method;
|
||||
Dart_CObject *values[2] = {&type, &value};
|
||||
Dart_CObject out;
|
||||
out.type = Dart_CObject_kArray;
|
||||
out.value.as_array.length = 2;
|
||||
out.value.as_array.values = values;
|
||||
Dart_PostCObject(thePort, &out);
|
||||
sendInt(100);
|
||||
return 0;
|
||||
};
|
||||
settings.on_headers_complete = [](http_parser *parser) {
|
||||
Dart_CObject type;
|
||||
type.type = Dart_CObject_kInt32;
|
||||
type.value.as_int32 = 2;
|
||||
Dart_CObject value;
|
||||
value.type = Dart_CObject_kInt32;
|
||||
value.value.as_int32 = parser->method;
|
||||
Dart_CObject *values[2] = {&type, &value};
|
||||
Dart_CObject out;
|
||||
out.type = Dart_CObject_kArray;
|
||||
out.value.as_array.length = 2;
|
||||
out.value.as_array.values = values;
|
||||
Dart_PostCObject(thePort, &out);
|
||||
sendInt(100);
|
||||
return 0;
|
||||
};
|
||||
|
||||
settings.on_message_complete = [](http_parser *parser) {
|
||||
sendInt(200);
|
||||
return 0;
|
||||
};
|
||||
settings.on_message_complete = [](http_parser *parser) {
|
||||
sendInt(200);
|
||||
return 0;
|
||||
};
|
||||
|
||||
settings.on_chunk_complete = [](http_parser *parser) {
|
||||
return 0;
|
||||
};
|
||||
settings.on_chunk_complete = [](http_parser *parser) { return 0; };
|
||||
|
||||
settings.on_chunk_header = [](http_parser *parser) {
|
||||
return 0;
|
||||
};
|
||||
settings.on_chunk_header = [](http_parser *parser) { return 0; };
|
||||
|
||||
settings.on_url = [](http_parser *parser, const char *at, size_t length) {
|
||||
sendString(0);
|
||||
return 0;
|
||||
};
|
||||
settings.on_url = [](http_parser *parser, const char *at, size_t length) {
|
||||
sendString(0);
|
||||
return 0;
|
||||
};
|
||||
|
||||
settings.on_header_field = [](http_parser *parser, const char *at, size_t length) {
|
||||
theStruct.lastHeader = std::string(at, length);
|
||||
return 0;
|
||||
};
|
||||
settings.on_header_field = [](http_parser *parser, const char *at,
|
||||
size_t length) {
|
||||
theStruct.lastHeader = std::string(at, length);
|
||||
return 0;
|
||||
};
|
||||
|
||||
settings.on_header_value = [](http_parser *parser, const char *at, size_t length) {
|
||||
if (!theStruct.lastHeader.empty())
|
||||
{
|
||||
std::string vStr(at, length);
|
||||
Dart_CObject type;
|
||||
type.type = Dart_CObject_kInt32;
|
||||
type.value.as_int32 = 1;
|
||||
Dart_CObject name;
|
||||
name.type = Dart_CObject_kString;
|
||||
name.value.as_string = (char *)theStruct.lastHeader.c_str();
|
||||
Dart_CObject value;
|
||||
value.type = Dart_CObject_kString;
|
||||
value.value.as_string = (char *)vStr.c_str();
|
||||
Dart_CObject *values[3] = {&type, &name, &value};
|
||||
Dart_CObject out;
|
||||
out.type = Dart_CObject_kArray;
|
||||
out.value.as_array.length = 3;
|
||||
out.value.as_array.values = values;
|
||||
Dart_PostCObject(thePort, &out);
|
||||
theStruct.lastHeader.clear();
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
settings.on_header_value = [](http_parser *parser, const char *at,
|
||||
size_t length) {
|
||||
if (!theStruct.lastHeader.empty()) {
|
||||
std::string vStr(at, length);
|
||||
Dart_CObject type;
|
||||
type.type = Dart_CObject_kInt32;
|
||||
type.value.as_int32 = 1;
|
||||
Dart_CObject name;
|
||||
name.type = Dart_CObject_kString;
|
||||
name.value.as_string = (char *)theStruct.lastHeader.c_str();
|
||||
Dart_CObject value;
|
||||
value.type = Dart_CObject_kString;
|
||||
value.value.as_string = (char *)vStr.c_str();
|
||||
Dart_CObject *values[3] = {&type, &name, &value};
|
||||
Dart_CObject out;
|
||||
out.type = Dart_CObject_kArray;
|
||||
out.value.as_array.length = 3;
|
||||
out.value.as_array.values = values;
|
||||
Dart_PostCObject(thePort, &out);
|
||||
theStruct.lastHeader.clear();
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
settings.on_body = [](http_parser *parser, const char *at, size_t length) {
|
||||
Dart_CObject obj;
|
||||
obj.type = Dart_CObject_kTypedData;
|
||||
obj.value.as_typed_data.type = Dart_TypedData_kUint8;
|
||||
obj.value.as_typed_data.length = length;
|
||||
obj.value.as_typed_data.values = (uint8_t *)at;
|
||||
Dart_PostCObject(thePort, &obj);
|
||||
return 0;
|
||||
};
|
||||
settings.on_body = [](http_parser *parser, const char *at, size_t length) {
|
||||
Dart_CObject obj;
|
||||
obj.type = Dart_CObject_kTypedData;
|
||||
obj.value.as_typed_data.type = Dart_TypedData_kUint8;
|
||||
obj.value.as_typed_data.length = length;
|
||||
obj.value.as_typed_data.values = (uint8_t *)at;
|
||||
Dart_PostCObject(thePort, &obj);
|
||||
return 0;
|
||||
};
|
||||
|
||||
size_t len = 80 * 1024, nparsed = 0;
|
||||
char buf[len];
|
||||
ssize_t recved = 0;
|
||||
memset(buf, 0, sizeof(buf));
|
||||
// http_parser parser;
|
||||
auto *parser = (http_parser *)malloc(sizeof(http_parser));
|
||||
http_parser_init(parser, HTTP_BOTH);
|
||||
parser->data = &httpData;
|
||||
size_t len = 80 * 1024, nparsed = 0;
|
||||
char buf[len];
|
||||
ssize_t recved = 0;
|
||||
memset(buf, 0, sizeof(buf));
|
||||
// http_parser parser;
|
||||
auto *parser = (http_parser *)malloc(sizeof(http_parser));
|
||||
http_parser_init(parser, HTTP_BOTH);
|
||||
parser->data = &httpData;
|
||||
|
||||
while ((recved = recv(fd, buf, len, 0)) >= 0)
|
||||
{
|
||||
if (false) // (isUpgrade)
|
||||
{
|
||||
// send_string(&parser, buf, (size_t)recved, 7, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Start up / continue the parser.
|
||||
* Note we pass recved==0 to signal that EOF has been received.
|
||||
*/
|
||||
nparsed = http_parser_execute(parser, &settings, buf, recved);
|
||||
while ((recved = recv(fd, buf, len, 0)) >= 0) {
|
||||
if (false) // (isUpgrade)
|
||||
{
|
||||
// send_string(&parser, buf, (size_t)recved, 7, true);
|
||||
} else {
|
||||
/* Start up / continue the parser.
|
||||
* Note we pass recved==0 to signal that EOF has been received.
|
||||
*/
|
||||
nparsed = http_parser_execute(parser, &settings, buf, recved);
|
||||
|
||||
if (nparsed != recved)
|
||||
{
|
||||
// TODO: End it...!
|
||||
}
|
||||
else if (recved == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// if ((isUpgrade = parser.upgrade) == 1)
|
||||
// {
|
||||
// send_notification(&parser, 6);
|
||||
// }
|
||||
// else if (nparsed != recved)
|
||||
// {
|
||||
// close(rq->sock);
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
|
||||
// memset(buf, 0, len);
|
||||
if (nparsed != recved) {
|
||||
// TODO: End it...!
|
||||
} else if (recved == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
// if ((isUpgrade = parser.upgrade) == 1)
|
||||
// {
|
||||
// send_notification(&parser, 6);
|
||||
// }
|
||||
// else if (nparsed != recved)
|
||||
// {
|
||||
// close(rq->sock);
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
|
||||
// memset(buf, 0, len);
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
BIN
lib/src/libangel_wings.so
Normal file
BIN
lib/src/libangel_wings.so
Normal file
Binary file not shown.
241
lib/src/util.cc
241
lib/src/util.cc
|
@ -1,171 +1,146 @@
|
|||
#include <dart_native_api.h>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
#include "angel_wings.h"
|
||||
#include "wings_socket.h"
|
||||
#include <dart_native_api.h>
|
||||
#include <iostream>
|
||||
using namespace wings;
|
||||
|
||||
void Dart_WingsSocket_listen(Dart_NativeArguments arguments)
|
||||
{
|
||||
uint64_t ptr;
|
||||
Dart_Handle pointerHandle = Dart_GetNativeArgument(arguments, 0);
|
||||
HandleError(Dart_IntegerToUint64(pointerHandle, &ptr));
|
||||
void Dart_WingsSocket_listen(Dart_NativeArguments arguments) {
|
||||
uint64_t ptr;
|
||||
Dart_Handle pointerHandle = Dart_GetNativeArgument(arguments, 0);
|
||||
HandleError(Dart_IntegerToUint64(pointerHandle, &ptr));
|
||||
|
||||
auto *socket = (WingsSocket *)ptr;
|
||||
socket->start(arguments);
|
||||
auto *socket = (WingsSocket *)ptr;
|
||||
socket->start(arguments);
|
||||
}
|
||||
|
||||
struct wingsSockName
|
||||
{
|
||||
sa_family_t family;
|
||||
sockaddr_in v4;
|
||||
sockaddr_in6 v6;
|
||||
struct wingsSockName {
|
||||
sa_family_t family;
|
||||
sockaddr_in v4;
|
||||
sockaddr_in6 v6;
|
||||
|
||||
struct sockaddr *ptr() const
|
||||
{
|
||||
if (family == AF_INET6)
|
||||
{
|
||||
return (sockaddr *)&v6;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (sockaddr *)&v4;
|
||||
}
|
||||
struct sockaddr *ptr() const {
|
||||
if (family == AF_INET6) {
|
||||
return (sockaddr *)&v6;
|
||||
} else {
|
||||
return (sockaddr *)&v4;
|
||||
}
|
||||
}
|
||||
|
||||
void *addrPtr() const
|
||||
{
|
||||
if (family == AF_INET6)
|
||||
{
|
||||
return (void *)&v6.sin6_addr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (void *)&v4.sin_addr;
|
||||
}
|
||||
void *addrPtr() const {
|
||||
if (family == AF_INET6) {
|
||||
return (void *)&v6.sin6_addr;
|
||||
} else {
|
||||
return (void *)&v4.sin_addr;
|
||||
}
|
||||
}
|
||||
|
||||
socklen_t length() const
|
||||
{
|
||||
if (family == AF_INET6)
|
||||
{
|
||||
return sizeof(v6);
|
||||
}
|
||||
else
|
||||
{
|
||||
return sizeof(v4);
|
||||
}
|
||||
socklen_t length() const {
|
||||
if (family == AF_INET6) {
|
||||
return sizeof(v6);
|
||||
} else {
|
||||
return sizeof(v4);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void wingsThrowOSError()
|
||||
{
|
||||
wingsThrowError(strerror(errno), "dart:io", "OSError", errno);
|
||||
void wingsThrowOSError() {
|
||||
wingsThrowError(strerror(errno), "dart:io", "OSError", errno);
|
||||
}
|
||||
|
||||
bool wingsReadSocket(Dart_NativeArguments arguments, wingsSockName *out)
|
||||
{
|
||||
uint64_t ptr;
|
||||
Dart_Handle pointerHandle = Dart_GetNativeArgument(arguments, 0);
|
||||
HandleError(Dart_IntegerToUint64(pointerHandle, &ptr));
|
||||
bool wingsReadSocket(Dart_NativeArguments arguments, wingsSockName *out) {
|
||||
uint64_t ptr;
|
||||
Dart_Handle pointerHandle = Dart_GetNativeArgument(arguments, 0);
|
||||
HandleError(Dart_IntegerToUint64(pointerHandle, &ptr));
|
||||
|
||||
auto *socket = (WingsSocket *)ptr;
|
||||
int fd = socket->getFD();
|
||||
auto *socket = (WingsSocket *)ptr;
|
||||
int fd = socket->getFD();
|
||||
|
||||
socklen_t len;
|
||||
out->family = socket->getFamily();
|
||||
len = out->length();
|
||||
socklen_t len;
|
||||
out->family = socket->getFamily();
|
||||
len = out->length();
|
||||
|
||||
int result;
|
||||
int result;
|
||||
|
||||
// result = connect(fd, out->ptr(), len);
|
||||
// result = connect(fd, out->ptr(), len);
|
||||
|
||||
// if (result < 0)
|
||||
// {
|
||||
// wingsThrowOSError();
|
||||
// return false;
|
||||
// }
|
||||
// if (result < 0)
|
||||
// {
|
||||
// wingsThrowOSError();
|
||||
// return false;
|
||||
// }
|
||||
|
||||
result = getsockname(fd, out->ptr(), &len);
|
||||
result = getsockname(fd, out->ptr(), &len);
|
||||
|
||||
if (result == -1)
|
||||
{
|
||||
wingsThrowOSError();
|
||||
return false;
|
||||
if (result == -1) {
|
||||
wingsThrowOSError();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Dart_WingsSocket_getAddress(Dart_NativeArguments arguments) {
|
||||
wingsSockName sock;
|
||||
if (wingsReadSocket(arguments, &sock)) {
|
||||
char addrBuf[INET6_ADDRSTRLEN + 1] = {0};
|
||||
|
||||
auto *result =
|
||||
inet_ntop(sock.family, sock.addrPtr(), addrBuf, sock.length());
|
||||
|
||||
if (result == NULL) {
|
||||
wingsThrowOSError();
|
||||
}
|
||||
|
||||
return true;
|
||||
Dart_Handle outHandle = Dart_NewStringFromCString(addrBuf);
|
||||
Dart_SetReturnValue(arguments, outHandle);
|
||||
}
|
||||
}
|
||||
|
||||
void Dart_WingsSocket_getAddress(Dart_NativeArguments arguments)
|
||||
{
|
||||
wingsSockName sock;
|
||||
if (wingsReadSocket(arguments, &sock))
|
||||
{
|
||||
char addrBuf[INET6_ADDRSTRLEN + 1] = {0};
|
||||
void Dart_WingsSocket_getPort(Dart_NativeArguments arguments) {
|
||||
wingsSockName sock;
|
||||
if (wingsReadSocket(arguments, &sock)) {
|
||||
Dart_Handle outHandle;
|
||||
|
||||
auto *result = inet_ntop(sock.family, sock.addrPtr(), addrBuf, sock.length());
|
||||
|
||||
if (result == NULL)
|
||||
{
|
||||
wingsThrowOSError();
|
||||
}
|
||||
|
||||
Dart_Handle outHandle = Dart_NewStringFromCString(addrBuf);
|
||||
Dart_SetReturnValue(arguments, outHandle);
|
||||
if (sock.family == AF_INET6) {
|
||||
outHandle = Dart_NewIntegerFromUint64(ntohs(sock.v6.sin6_port));
|
||||
} else {
|
||||
outHandle = Dart_NewIntegerFromUint64(ntohs(sock.v4.sin_port));
|
||||
}
|
||||
|
||||
Dart_SetReturnValue(arguments, outHandle);
|
||||
}
|
||||
}
|
||||
|
||||
void Dart_WingsSocket_getPort(Dart_NativeArguments arguments)
|
||||
{
|
||||
wingsSockName sock;
|
||||
if (wingsReadSocket(arguments, &sock))
|
||||
{
|
||||
Dart_Handle outHandle;
|
||||
|
||||
if (sock.family == AF_INET6)
|
||||
{
|
||||
outHandle = Dart_NewIntegerFromUint64(ntohs(sock.v6.sin6_port));
|
||||
}
|
||||
else
|
||||
{
|
||||
outHandle = Dart_NewIntegerFromUint64(ntohs(sock.v4.sin_port));
|
||||
}
|
||||
|
||||
Dart_SetReturnValue(arguments, outHandle);
|
||||
}
|
||||
void Dart_WingsSocket_write(Dart_NativeArguments arguments) {
|
||||
int64_t fd;
|
||||
void *data;
|
||||
Dart_TypedData_Type type;
|
||||
intptr_t len;
|
||||
Dart_Handle fdHandle = Dart_GetNativeArgument(arguments, 0);
|
||||
Dart_Handle dataHandle = Dart_GetNativeArgument(arguments, 1);
|
||||
HandleError(Dart_IntegerToInt64(fdHandle, &fd));
|
||||
HandleError(Dart_TypedDataAcquireData(dataHandle, &type, &data, &len));
|
||||
write(fd, data, len);
|
||||
HandleError(Dart_TypedDataReleaseData(dataHandle));
|
||||
}
|
||||
|
||||
void Dart_WingsSocket_write(Dart_NativeArguments arguments)
|
||||
{
|
||||
int64_t fd;
|
||||
void *data;
|
||||
Dart_TypedData_Type type;
|
||||
intptr_t len;
|
||||
Dart_Handle fdHandle = Dart_GetNativeArgument(arguments, 0);
|
||||
Dart_Handle dataHandle = Dart_GetNativeArgument(arguments, 1);
|
||||
HandleError(Dart_IntegerToInt64(fdHandle, &fd));
|
||||
HandleError(Dart_TypedDataAcquireData(dataHandle, &type, &data, &len));
|
||||
write(fd, data, len);
|
||||
HandleError(Dart_TypedDataReleaseData(dataHandle));
|
||||
void Dart_WingsSocket_closeDescriptor(Dart_NativeArguments arguments) {
|
||||
int64_t fd;
|
||||
Dart_Handle fdHandle = Dart_GetNativeArgument(arguments, 0);
|
||||
HandleError(Dart_IntegerToInt64(fdHandle, &fd));
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void Dart_WingsSocket_closeDescriptor(Dart_NativeArguments arguments)
|
||||
{
|
||||
int64_t fd;
|
||||
Dart_Handle fdHandle = Dart_GetNativeArgument(arguments, 0);
|
||||
HandleError(Dart_IntegerToInt64(fdHandle, &fd));
|
||||
close(fd);
|
||||
}
|
||||
void Dart_WingsSocket_close(Dart_NativeArguments arguments) {
|
||||
Dart_Port port;
|
||||
uint64_t ptr;
|
||||
Dart_Handle pointerHandle = Dart_GetNativeArgument(arguments, 0);
|
||||
Dart_Handle sendPortHandle = Dart_GetNativeArgument(arguments, 1);
|
||||
HandleError(Dart_IntegerToUint64(pointerHandle, &ptr));
|
||||
HandleError(Dart_SendPortGetId(sendPortHandle, &port));
|
||||
|
||||
void Dart_WingsSocket_close(Dart_NativeArguments arguments)
|
||||
{
|
||||
Dart_Port port;
|
||||
uint64_t ptr;
|
||||
Dart_Handle pointerHandle = Dart_GetNativeArgument(arguments, 0);
|
||||
Dart_Handle sendPortHandle = Dart_GetNativeArgument(arguments, 1);
|
||||
HandleError(Dart_IntegerToUint64(pointerHandle, &ptr));
|
||||
HandleError(Dart_SendPortGetId(sendPortHandle, &port));
|
||||
|
||||
auto *socket = (WingsSocket *)ptr;
|
||||
socket->decrRef(port);
|
||||
auto *socket = (WingsSocket *)ptr;
|
||||
socket->decrRef(port);
|
||||
}
|
|
@ -1,152 +1,129 @@
|
|||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include "wings_socket.h"
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
using namespace wings;
|
||||
|
||||
std::vector<WingsSocket *> wings::globalSocketList;
|
||||
|
||||
bool WingsSocketInfo::equals(const WingsSocketInfo &right) const
|
||||
{
|
||||
// std::cout << address << " vs " << right.address << std::endl;
|
||||
// std::cout << port << " vs " << right.port << std::endl;
|
||||
return (strcmp(address, right.address) == 0) &&
|
||||
port == right.port;
|
||||
bool WingsSocketInfo::equals(const WingsSocketInfo &right) const {
|
||||
// std::cout << address << " vs " << right.address << std::endl;
|
||||
// std::cout << port << " vs " << right.port << std::endl;
|
||||
return (strcmp(address, right.address) == 0) && port == right.port;
|
||||
}
|
||||
|
||||
WingsSocket::WingsSocket(sa_family_t family, int sockfd, const WingsSocketInfo &info)
|
||||
: sockfd(sockfd), info(info), family(family)
|
||||
{
|
||||
index = 0;
|
||||
open = true;
|
||||
refCount = 0;
|
||||
workerThread = nullptr;
|
||||
this->info.address = strdup(info.address);
|
||||
WingsSocket::WingsSocket(sa_family_t family, int sockfd,
|
||||
const WingsSocketInfo &info)
|
||||
: sockfd(sockfd), info(info), family(family) {
|
||||
portIterator = sendPorts.begin();
|
||||
open = true;
|
||||
refCount = 0;
|
||||
workerThread = nullptr;
|
||||
this->info.address = strdup(info.address);
|
||||
}
|
||||
|
||||
void WingsSocket::incrRef(Dart_Port port)
|
||||
{
|
||||
refCount++;
|
||||
sendPorts.push_back(port);
|
||||
void WingsSocket::incrRef(Dart_Port port) {
|
||||
refCount++;
|
||||
sendPorts.push_back(port);
|
||||
}
|
||||
|
||||
void WingsSocket::decrRef(Dart_Port port)
|
||||
{
|
||||
auto it = std::find(sendPorts.begin(), sendPorts.end(), port);
|
||||
void WingsSocket::decrRef(Dart_Port port) {
|
||||
auto it = std::find(sendPorts.begin(), sendPorts.end(), port);
|
||||
|
||||
if (it != sendPorts.end())
|
||||
{
|
||||
sendPorts.erase(it);
|
||||
}
|
||||
if (it != sendPorts.end()) {
|
||||
sendPorts.erase(it);
|
||||
}
|
||||
|
||||
refCount--;
|
||||
refCount--;
|
||||
|
||||
if (refCount <= 0 && open)
|
||||
{
|
||||
close(sockfd);
|
||||
}
|
||||
if (refCount <= 0 && open) {
|
||||
close(sockfd);
|
||||
open = false;
|
||||
}
|
||||
}
|
||||
|
||||
Dart_Port WingsSocket::nextPort()
|
||||
{
|
||||
if (index >= sendPorts.size())
|
||||
index = 0;
|
||||
Dart_Port port = sendPorts.at(index++);
|
||||
return port;
|
||||
Dart_Port WingsSocket::nextPort() {
|
||||
portIterator++;
|
||||
if (portIterator == sendPorts.end())
|
||||
portIterator = sendPorts.begin();
|
||||
return *portIterator;
|
||||
}
|
||||
|
||||
const WingsSocketInfo &WingsSocket::getInfo() const
|
||||
{
|
||||
return info;
|
||||
}
|
||||
const WingsSocketInfo &WingsSocket::getInfo() const { return info; }
|
||||
|
||||
int WingsSocket::getFD() const
|
||||
{
|
||||
return sockfd;
|
||||
}
|
||||
int WingsSocket::getFD() const { return sockfd; }
|
||||
|
||||
sa_family_t WingsSocket::getFamily() const
|
||||
{
|
||||
return family;
|
||||
}
|
||||
sa_family_t WingsSocket::getFamily() const { return family; }
|
||||
|
||||
void WingsSocket::start(Dart_NativeArguments arguments)
|
||||
{
|
||||
// if (workerThread == nullptr)
|
||||
// {
|
||||
// workerThread = std::make_unique<std::thread>(threadCallback, this);
|
||||
// }
|
||||
Dart_Port service_port =
|
||||
Dart_NewNativePort("WingsThreadCallback", &threadCallback, true);
|
||||
Dart_Handle send_port = Dart_NewSendPort(service_port);
|
||||
Dart_SetReturnValue(arguments, send_port);
|
||||
bool WingsSocket::isClosed() const { return !open; }
|
||||
|
||||
void WingsSocket::start(Dart_NativeArguments arguments) {
|
||||
// if (workerThread == nullptr)
|
||||
// {
|
||||
// workerThread = std::make_unique<std::thread>(threadCallback, this);
|
||||
// }
|
||||
Dart_Port service_port =
|
||||
Dart_NewNativePort("WingsThreadCallback", &threadCallback, true);
|
||||
Dart_Handle send_port = Dart_NewSendPort(service_port);
|
||||
Dart_SetReturnValue(arguments, send_port);
|
||||
}
|
||||
|
||||
void WingsSocket::threadCallback(Dart_Port dest_port_id,
|
||||
Dart_CObject *message)
|
||||
{
|
||||
Dart_CObject *message) {
|
||||
|
||||
WingsSocket *socket = nullptr;
|
||||
Dart_Port outPort = message->value.as_array.values[0]->value.as_send_port.id;
|
||||
Dart_CObject *ptrArg = message->value.as_array.values[1];
|
||||
WingsSocket *socket = nullptr;
|
||||
Dart_Port outPort = message->value.as_array.values[0]->value.as_send_port.id;
|
||||
Dart_CObject *ptrArg = message->value.as_array.values[1];
|
||||
|
||||
// If there are no listeners, quit.
|
||||
if (ptrArg->type == Dart_CObject_kInt32)
|
||||
{
|
||||
auto as64 = (int64_t)ptrArg->value.as_int32;
|
||||
socket = (WingsSocket *)as64;
|
||||
}
|
||||
else
|
||||
{
|
||||
socket = (WingsSocket *)ptrArg->value.as_int64;
|
||||
// If there are no listeners, quit.
|
||||
if (ptrArg->type == Dart_CObject_kInt32) {
|
||||
auto as64 = (int64_t)ptrArg->value.as_int32;
|
||||
socket = (WingsSocket *)as64;
|
||||
} else {
|
||||
socket = (WingsSocket *)ptrArg->value.as_int64;
|
||||
}
|
||||
|
||||
if (socket != nullptr) {
|
||||
if (socket->sendPorts.empty() || socket->isClosed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (socket != nullptr)
|
||||
{
|
||||
if (socket->sendPorts.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
int sock;
|
||||
unsigned long index = 0;
|
||||
sockaddr addr;
|
||||
socklen_t len;
|
||||
|
||||
int sock;
|
||||
unsigned long index = 0;
|
||||
sockaddr addr;
|
||||
socklen_t len;
|
||||
if ((sock = accept(socket->sockfd, &addr, &len)) != -1) {
|
||||
char addrBuf[INET6_ADDRSTRLEN] = {0};
|
||||
|
||||
if ((sock = accept(socket->sockfd, &addr, &len)) != -1)
|
||||
{
|
||||
char addrBuf[INET6_ADDRSTRLEN] = {0};
|
||||
if (addr.sa_family == AF_INET6) {
|
||||
auto as6 = (sockaddr_in6 *)&addr;
|
||||
inet_ntop(addr.sa_family, &(as6->sin6_addr), addrBuf, len);
|
||||
} else {
|
||||
auto as4 = (sockaddr_in *)&addr;
|
||||
inet_ntop(AF_INET, &(as4->sin_addr), addrBuf, len);
|
||||
}
|
||||
|
||||
if (addr.sa_family == AF_INET6)
|
||||
{
|
||||
auto as6 = (sockaddr_in6 *)&addr;
|
||||
inet_ntop(addr.sa_family, &(as6->sin6_addr), addrBuf, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto as4 = (sockaddr_in *)&addr;
|
||||
inet_ntop(AF_INET, &(as4->sin_addr), addrBuf, len);
|
||||
}
|
||||
Dart_CObject fdObj;
|
||||
fdObj.type = Dart_CObject_kInt64;
|
||||
fdObj.value.as_int64 = sock;
|
||||
|
||||
Dart_CObject fdObj;
|
||||
fdObj.type = Dart_CObject_kInt64;
|
||||
fdObj.value.as_int64 = sock;
|
||||
Dart_CObject addrObj;
|
||||
addrObj.type = Dart_CObject_kString;
|
||||
addrObj.value.as_string = addrBuf;
|
||||
|
||||
Dart_CObject addrObj;
|
||||
addrObj.type = Dart_CObject_kString;
|
||||
addrObj.value.as_string = addrBuf;
|
||||
Dart_CObject *values[2] = {&fdObj, &addrObj};
|
||||
|
||||
Dart_CObject *values[2] = {&fdObj, &addrObj};
|
||||
Dart_CObject obj;
|
||||
obj.type = Dart_CObject_kArray;
|
||||
obj.value.as_array.length = 2;
|
||||
obj.value.as_array.values = values;
|
||||
|
||||
Dart_CObject obj;
|
||||
obj.type = Dart_CObject_kArray;
|
||||
obj.value.as_array.length = 2;
|
||||
obj.value.as_array.values = values;
|
||||
|
||||
// Dart_PostCObject(outPort, &obj);
|
||||
// Dispatch the fd to the next listener.
|
||||
auto port = socket->nextPort();
|
||||
Dart_PostCObject(port, &obj);
|
||||
// Dart_PostCObject(outPort, &obj);
|
||||
}
|
||||
// Dart_PostCObject(outPort, &obj);
|
||||
// Dispatch the fd to the next listener.
|
||||
auto port = socket->nextPort();
|
||||
Dart_PostCObject(port, &obj);
|
||||
// Dart_PostCObject(outPort, &obj);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -118,12 +118,13 @@ class WingsSocket extends Stream<WingsClientSocket> {
|
|||
.listen(onData, onError: onError, cancelOnError: cancelOnError);
|
||||
}
|
||||
|
||||
Future<void> close() async {
|
||||
Future<void> close(){
|
||||
if (_open) {
|
||||
_open = false;
|
||||
closeWingsSocket(_pointer, _recv.sendPort);
|
||||
_recv.close();
|
||||
await _ctrl.close();
|
||||
_ctrl.close();
|
||||
}
|
||||
return Future.value();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
#ifndef WINGS_SOCKET_H
|
||||
#define WINGS_SOCKET_H
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <stdlib.h>
|
||||
#include <netinet/in.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <dart_api.h>
|
||||
#include <dart_native_api.h>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
namespace wings
|
||||
{
|
||||
struct WingsSocketInfo
|
||||
{
|
||||
namespace wings {
|
||||
struct WingsSocketInfo {
|
||||
const char *address;
|
||||
uint64_t port;
|
||||
bool shared;
|
||||
|
@ -25,8 +24,7 @@ struct WingsSocketInfo
|
|||
bool equals(const WingsSocketInfo &right) const;
|
||||
};
|
||||
|
||||
class WingsSocket
|
||||
{
|
||||
class WingsSocket {
|
||||
public:
|
||||
WingsSocket(sa_family_t family, int sockfd, const WingsSocketInfo &info);
|
||||
void incrRef(Dart_Port port);
|
||||
|
@ -34,19 +32,20 @@ public:
|
|||
const WingsSocketInfo &getInfo() const;
|
||||
void start(Dart_NativeArguments arguments);
|
||||
int getFD() const;
|
||||
bool isClosed() const;
|
||||
sa_family_t getFamily() const;
|
||||
Dart_Port nextPort();
|
||||
|
||||
private:
|
||||
static void threadCallback(Dart_Port dest_port_id, Dart_CObject *message);
|
||||
WingsSocketInfo info;
|
||||
unsigned long index;
|
||||
std::list<Dart_Port>::iterator portIterator;
|
||||
int sockfd;
|
||||
int refCount;
|
||||
bool open;
|
||||
sa_family_t family;
|
||||
std::unique_ptr<std::thread> workerThread;
|
||||
std::vector<Dart_Port> sendPorts;
|
||||
std::list<Dart_Port> sendPorts;
|
||||
};
|
||||
|
||||
extern std::vector<WingsSocket *> globalSocketList;
|
||||
|
|
Binary file not shown.
BIN
libangel_wings.so
Normal file
BIN
libangel_wings.so
Normal file
Binary file not shown.
24
provision.sh
Executable file
24
provision.sh
Executable file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Install Dart, globally.
|
||||
sudo apt-get update
|
||||
sudo apt-get install apt-transport-https
|
||||
sudo sh -c 'curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
|
||||
sudo sh -c 'curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y dart
|
||||
export PATH="$PATH:/usr/lib/dart/bin"
|
||||
echo 'export PATH="$PATH:/usr/lib/dart/bin"' >> ~vagrant/.profile
|
||||
|
||||
# Install build tooling, CMake, etc.
|
||||
sudo apt-get install -y build-essential
|
||||
sudo apt-get install -y cmake
|
||||
|
||||
# Build the library.
|
||||
pushd /vagrant
|
||||
mkdir -p cmake-build-vagrant
|
||||
pushd cmake-build-vagrant
|
||||
cmake ..
|
||||
cmake --build . --target install
|
||||
popd
|
||||
popd
|
672
ubuntu-bionic-18.04-cloudimg-console.log
Normal file
672
ubuntu-bionic-18.04-cloudimg-console.log
Normal file
|
@ -0,0 +1,672 @@
|
|||
[ 0.000000] Linux version 4.15.0-60-generic (buildd@lgw01-amd64-030) (gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)) #67-Ubuntu SMP Thu Aug 22 16:55:30 UTC 2019 (Ubuntu 4.15.0-60.67-generic 4.15.18)
|
||||
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-4.15.0-60-generic root=LABEL=cloudimg-rootfs ro console=tty1 console=ttyS0
|
||||
[ 0.000000] KERNEL supported cpus:
|
||||
[ 0.000000] Intel GenuineIntel
|
||||
[ 0.000000] AMD AuthenticAMD
|
||||
[ 0.000000] Centaur CentaurHauls
|
||||
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
|
||||
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
|
||||
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
|
||||
[ 0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
|
||||
[ 0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'standard' format.
|
||||
[ 0.000000] e820: BIOS-provided physical RAM map:
|
||||
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
|
||||
[ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
|
||||
[ 0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
|
||||
[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000003ffeffff] usable
|
||||
[ 0.000000] BIOS-e820: [mem 0x000000003fff0000-0x000000003fffffff] ACPI data
|
||||
[ 0.000000] BIOS-e820: [mem 0x00000000fec00000-0x00000000fec00fff] reserved
|
||||
[ 0.000000] BIOS-e820: [mem 0x00000000fee00000-0x00000000fee00fff] reserved
|
||||
[ 0.000000] BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
|
||||
[ 0.000000] NX (Execute Disable) protection: active
|
||||
[ 0.000000] SMBIOS 2.5 present.
|
||||
[ 0.000000] DMI: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
|
||||
[ 0.000000] Hypervisor detected: KVM
|
||||
[ 0.000000] e820: last_pfn = 0x3fff0 max_arch_pfn = 0x400000000
|
||||
[ 0.000000] MTRR: Disabled
|
||||
[ 0.000000] x86/PAT: MTRRs disabled, skipping PAT initialization too.
|
||||
[ 0.000000] CPU MTRRs all blank - virtualized system.
|
||||
[ 0.000000] x86/PAT: Configuration [0-7]: WB WT UC- UC WB WT UC- UC
|
||||
[ 0.000000] found SMP MP-table at [mem 0x0009fff0-0x0009ffff]
|
||||
[ 0.000000] Scanning 1 areas for low memory corruption
|
||||
[ 0.000000] RAMDISK: [mem 0x35a8b000-0x36d3cfff]
|
||||
[ 0.000000] ACPI: Early table checksum verification disabled
|
||||
[ 0.000000] ACPI: RSDP 0x00000000000E0000 000024 (v02 VBOX )
|
||||
[ 0.000000] ACPI: XSDT 0x000000003FFF0030 00003C (v01 VBOX VBOXXSDT 00000001 ASL 00000061)
|
||||
[ 0.000000] ACPI: FACP 0x000000003FFF00F0 0000F4 (v04 VBOX VBOXFACP 00000001 ASL 00000061)
|
||||
[ 0.000000] ACPI: DSDT 0x000000003FFF0470 0022EA (v02 VBOX VBOXBIOS 00000002 INTL 20100528)
|
||||
[ 0.000000] ACPI: FACS 0x000000003FFF0200 000040
|
||||
[ 0.000000] ACPI: FACS 0x000000003FFF0200 000040
|
||||
[ 0.000000] ACPI: APIC 0x000000003FFF0240 00005C (v02 VBOX VBOXAPIC 00000001 ASL 00000061)
|
||||
[ 0.000000] ACPI: SSDT 0x000000003FFF02A0 0001CC (v01 VBOX VBOXCPUT 00000002 INTL 20100528)
|
||||
[ 0.000000] No NUMA configuration found
|
||||
[ 0.000000] Faking a node at [mem 0x0000000000000000-0x000000003ffeffff]
|
||||
[ 0.000000] NODE_DATA(0) allocated [mem 0x3ffc5000-0x3ffeffff]
|
||||
[ 0.000000] kvm-clock: cpu 0, msr 0:3ff44001, primary cpu clock
|
||||
[ 0.000000] kvm-clock: Using msrs 4b564d01 and 4b564d00
|
||||
[ 0.000000] kvm-clock: using sched offset of 6313796290 cycles
|
||||
[ 0.000000] clocksource: kvm-clock: mask: 0xffffffffffffffff max_cycles: 0x1cd42e4dffb, max_idle_ns: 881590591483 ns
|
||||
[ 0.000000] Zone ranges:
|
||||
[ 0.000000] DMA [mem 0x0000000000001000-0x0000000000ffffff]
|
||||
[ 0.000000] DMA32 [mem 0x0000000001000000-0x000000003ffeffff]
|
||||
[ 0.000000] Normal empty
|
||||
[ 0.000000] Device empty
|
||||
[ 0.000000] Movable zone start for each node
|
||||
[ 0.000000] Early memory node ranges
|
||||
[ 0.000000] node 0: [mem 0x0000000000001000-0x000000000009efff]
|
||||
[ 0.000000] node 0: [mem 0x0000000000100000-0x000000003ffeffff]
|
||||
[ 0.000000] Reserved but unavailable: 98 pages
|
||||
[ 0.000000] Initmem setup node 0 [mem 0x0000000000001000-0x000000003ffeffff]
|
||||
[ 0.000000] ACPI: PM-Timer IO Port: 0x4008
|
||||
[ 0.000000] IOAPIC[0]: apic_id 2, version 32, address 0xfec00000, GSI 0-23
|
||||
[ 0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 0 global_irq 2 dfl dfl)
|
||||
[ 0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 low level)
|
||||
[ 0.000000] Using ACPI (MADT) for SMP configuration information
|
||||
[ 0.000000] smpboot: Allowing 2 CPUs, 0 hotplug CPUs
|
||||
[ 0.000000] PM: Registered nosave memory: [mem 0x00000000-0x00000fff]
|
||||
[ 0.000000] PM: Registered nosave memory: [mem 0x0009f000-0x0009ffff]
|
||||
[ 0.000000] PM: Registered nosave memory: [mem 0x000a0000-0x000effff]
|
||||
[ 0.000000] PM: Registered nosave memory: [mem 0x000f0000-0x000fffff]
|
||||
[ 0.000000] e820: [mem 0x40000000-0xfebfffff] available for PCI devices
|
||||
[ 0.000000] Booting paravirtualized kernel on KVM
|
||||
[ 0.000000] clocksource: refined-jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645519600211568 ns
|
||||
[ 0.000000] random: get_random_bytes called from start_kernel+0x99/0x4fd with crng_init=0
|
||||
[ 0.000000] setup_percpu: NR_CPUS:8192 nr_cpumask_bits:2 nr_cpu_ids:2 nr_node_ids:1
|
||||
[ 0.000000] percpu: Embedded 46 pages/cpu s151552 r8192 d28672 u1048576
|
||||
[ 0.000000] PV qspinlock hash table entries: 256 (order: 0, 4096 bytes)
|
||||
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 257913
|
||||
[ 0.000000] Policy zone: DMA32
|
||||
[ 0.000000] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-4.15.0-60-generic root=LABEL=cloudimg-rootfs ro console=tty1 console=ttyS0
|
||||
[ 0.000000] Memory: 983440K/1048120K available (12300K kernel code, 2481K rwdata, 4172K rodata, 2436K init, 2384K bss, 64680K reserved, 0K cma-reserved)
|
||||
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=2, Nodes=1
|
||||
[ 0.000000] Kernel/User page tables isolation: enabled
|
||||
[ 0.000000] ftrace: allocating 39306 entries in 154 pages
|
||||
[ 0.004000] Hierarchical RCU implementation.
|
||||
[ 0.004000] RCU restricting CPUs from NR_CPUS=8192 to nr_cpu_ids=2.
|
||||
[ 0.004000] Tasks RCU enabled.
|
||||
[ 0.004000] RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=2
|
||||
[ 0.004000] NR_IRQS: 524544, nr_irqs: 440, preallocated irqs: 16
|
||||
[ 0.004000] Console: colour VGA+ 80x25
|
||||
[ 0.004000] console [tty1] enabled
|
||||
[ 0.004000] console [ttyS0] enabled
|
||||
[ 0.004000] ACPI: Core revision 20170831
|
||||
[ 0.004000] ACPI: 2 ACPI AML tables successfully acquired and loaded
|
||||
[ 0.004000] APIC: Switch to symmetric I/O mode setup
|
||||
[ 0.004000] x2apic enabled
|
||||
[ 0.004000] Switched APIC routing to physical x2apic.
|
||||
[ 0.005261] ..TIMER: vector=0x30 apic1=0 pin1=2 apic2=-1 pin2=-1
|
||||
[ 0.008004] tsc: Detected 1799.999 MHz processor
|
||||
[ 0.012012] Calibrating delay loop (skipped) preset value.. 3599.99 BogoMIPS (lpj=7199996)
|
||||
[ 0.014430] pid_max: default: 32768 minimum: 301
|
||||
[ 0.016036] Security Framework initialized
|
||||
[ 0.017257] Yama: becoming mindful.
|
||||
[ 0.018593] AppArmor: AppArmor initialized
|
||||
[ 0.021844] Dentry cache hash table entries: 131072 (order: 8, 1048576 bytes)
|
||||
[ 0.024088] Inode-cache hash table entries: 65536 (order: 7, 524288 bytes)
|
||||
[ 0.028022] Mount-cache hash table entries: 2048 (order: 2, 16384 bytes)
|
||||
[ 0.030085] Mountpoint-cache hash table entries: 2048 (order: 2, 16384 bytes)
|
||||
[ 0.032346] Last level iTLB entries: 4KB 64, 2MB 8, 4MB 8
|
||||
[ 0.036002] Last level dTLB entries: 4KB 64, 2MB 0, 4MB 0, 1GB 4
|
||||
[ 0.038331] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user pointer sanitization
|
||||
[ 0.040053] Spectre V2 : Mitigation: Full generic retpoline
|
||||
[ 0.044003] Spectre V2 : Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch
|
||||
[ 0.047370] Speculative Store Bypass: Vulnerable
|
||||
[ 0.048050] MDS: Vulnerable: Clear CPU buffers attempted, no microcode
|
||||
[ 0.050738] Freeing SMP alternatives memory: 36K
|
||||
[ 0.060000] smpboot: CPU0: Intel(R) Core(TM) i5-5350U CPU @ 1.80GHz (family: 0x6, model: 0x3d, stepping: 0x4)
|
||||
[ 0.060095] Performance Events: unsupported p6 CPU model 61 no PMU driver, software events only.
|
||||
[ 0.063096] Hierarchical SRCU implementation.
|
||||
[ 0.064650] NMI watchdog: Perf event create on CPU 0 failed with -2
|
||||
[ 0.066472] NMI watchdog: Perf NMI watchdog permanently disabled
|
||||
[ 0.068053] smp: Bringing up secondary CPUs ...
|
||||
[ 0.069490] x86: Booting SMP configuration:
|
||||
[ 0.070770] .... node #0, CPUs: #1
|
||||
[ 0.004000] kvm-clock: cpu 1, msr 0:3ff44041, secondary cpu clock
|
||||
[ 0.078095] smp: Brought up 1 node, 2 CPUs
|
||||
[ 0.078095] smpboot: Max logical packages: 1
|
||||
[ 0.080007] smpboot: Total of 2 processors activated (7199.99 BogoMIPS)
|
||||
[ 0.085029] devtmpfs: initialized
|
||||
[ 0.085718] x86/mm: Memory block size: 128MB
|
||||
[ 0.088152] evm: security.selinux
|
||||
[ 0.089578] evm: security.SMACK64
|
||||
[ 0.090723] evm: security.SMACK64EXEC
|
||||
[ 0.092005] evm: security.SMACK64TRANSMUTE
|
||||
[ 0.093324] evm: security.SMACK64MMAP
|
||||
[ 0.094789] evm: security.apparmor
|
||||
[ 0.096003] evm: security.ima
|
||||
[ 0.097270] evm: security.capability
|
||||
[ 0.100127] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
|
||||
[ 0.104010] futex hash table entries: 512 (order: 3, 32768 bytes)
|
||||
[ 0.108000] pinctrl core: initialized pinctrl subsystem
|
||||
[ 0.108153] RTC time: 4:37:25, date: 09/29/19
|
||||
[ 0.112223] NET: Registered protocol family 16
|
||||
[ 0.114097] audit: initializing netlink subsys (disabled)
|
||||
[ 0.116040] audit: type=2000 audit(1569731852.938:1): state=initialized audit_enabled=0 res=1
|
||||
[ 0.120020] cpuidle: using governor ladder
|
||||
[ 0.121972] cpuidle: using governor menu
|
||||
[ 0.124054] ACPI: bus type PCI registered
|
||||
[ 0.125660] acpiphp: ACPI Hot Plug PCI Controller Driver version: 0.5
|
||||
[ 0.128144] PCI: Using configuration type 1 for base access
|
||||
[ 0.132420] HugeTLB registered 2.00 MiB page size, pre-allocated 0 pages
|
||||
[ 0.136070] ACPI: Added _OSI(Module Device)
|
||||
[ 0.137755] ACPI: Added _OSI(Processor Device)
|
||||
[ 0.139558] ACPI: Added _OSI(3.0 _SCP Extensions)
|
||||
[ 0.140012] ACPI: Added _OSI(Processor Aggregator Device)
|
||||
[ 0.142205] ACPI: Added _OSI(Linux-Dell-Video)
|
||||
[ 0.144009] ACPI: Added _OSI(Linux-Lenovo-NV-HDMI-Audio)
|
||||
[ 0.146265] ACPI: Added _OSI(Linux-HPI-Hybrid-Graphics)
|
||||
[ 0.148559] ACPI: Executed 1 blocks of module-level executable AML code
|
||||
[ 0.157460] ACPI: Interpreter enabled
|
||||
[ 0.159031] ACPI: (supports S0 S5)
|
||||
[ 0.160004] ACPI: Using IOAPIC for interrupt routing
|
||||
[ 0.162232] PCI: Using host bridge windows from ACPI; if necessary, use "pci=nocrs" and report a bug
|
||||
[ 0.164282] ACPI: Enabled 2 GPEs in block 00 to 07
|
||||
[ 0.177420] ACPI: PCI Root Bridge [PCI0] (domain 0000 [bus 00-ff])
|
||||
[ 0.179619] acpi PNP0A03:00: _OSC: OS supports [ASPM ClockPM Segments MSI]
|
||||
[ 0.180559] acpi PNP0A03:00: _OSC: not requesting OS control; OS requires [ExtendedConfig ASPM ClockPM MSI]
|
||||
[ 0.184016] acpi PNP0A03:00: fail to add MMCONFIG information, can't access extended PCI configuration space under this bridge.
|
||||
[ 0.188599] PCI host bridge to bus 0000:00
|
||||
[ 0.190032] pci_bus 0000:00: root bus resource [io 0x0000-0x0cf7 window]
|
||||
[ 0.192012] pci_bus 0000:00: root bus resource [io 0x0d00-0xffff window]
|
||||
[ 0.196010] pci_bus 0000:00: root bus resource [mem 0x000a0000-0x000bffff window]
|
||||
[ 0.198997] pci_bus 0000:00: root bus resource [mem 0x40000000-0xfdffffff window]
|
||||
[ 0.200005] pci_bus 0000:00: root bus resource [bus 00-ff]
|
||||
[ 0.209096] pci 0000:00:01.1: legacy IDE quirk: reg 0x10: [io 0x01f0-0x01f7]
|
||||
[ 0.212011] pci 0000:00:01.1: legacy IDE quirk: reg 0x14: [io 0x03f6]
|
||||
[ 0.214198] pci 0000:00:01.1: legacy IDE quirk: reg 0x18: [io 0x0170-0x0177]
|
||||
[ 0.216011] pci 0000:00:01.1: legacy IDE quirk: reg 0x1c: [io 0x0376]
|
||||
[ 0.250063] pci 0000:00:07.0: quirk: [io 0x4000-0x403f] claimed by PIIX4 ACPI
|
||||
[ 0.252032] pci 0000:00:07.0: quirk: [io 0x4100-0x410f] claimed by PIIX4 SMB
|
||||
[ 0.268428] ACPI: PCI Interrupt Link [LNKA] (IRQs 5 9 10 *11)
|
||||
[ 0.271342] ACPI: PCI Interrupt Link [LNKB] (IRQs 5 9 *10 11)
|
||||
[ 0.272177] ACPI: PCI Interrupt Link [LNKC] (IRQs 5 *9 10 11)
|
||||
[ 0.274371] ACPI: PCI Interrupt Link [LNKD] (IRQs 5 9 10 *11)
|
||||
[ 0.276529] SCSI subsystem initialized
|
||||
[ 0.280075] pci 0000:00:02.0: vgaarb: setting as boot VGA device
|
||||
[ 0.282678] pci 0000:00:02.0: vgaarb: VGA device added: decodes=io+mem,owns=io+mem,locks=none
|
||||
[ 0.284008] pci 0000:00:02.0: vgaarb: bridge control possible
|
||||
[ 0.288007] vgaarb: loaded
|
||||
[ 0.289501] ACPI: bus type USB registered
|
||||
[ 0.292045] usbcore: registered new interface driver usbfs
|
||||
[ 0.294316] usbcore: registered new interface driver hub
|
||||
[ 0.296044] usbcore: registered new device driver usb
|
||||
[ 0.300127] EDAC MC: Ver: 3.0.0
|
||||
[ 0.302311] PCI: Using ACPI for IRQ routing
|
||||
[ 0.304830] NetLabel: Initializing
|
||||
[ 0.308006] NetLabel: domain hash size = 128
|
||||
[ 0.310637] NetLabel: protocols = UNLABELED CIPSOv4 CALIPSO
|
||||
[ 0.312043] NetLabel: unlabeled traffic allowed by default
|
||||
[ 0.316129] clocksource: Switched to clocksource kvm-clock
|
||||
[ 0.338523] VFS: Disk quotas dquot_6.6.0
|
||||
[ 0.340526] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
|
||||
[ 0.344063] AppArmor: AppArmor Filesystem Enabled
|
||||
[ 0.347415] pnp: PnP ACPI init
|
||||
[ 0.354536] pnp: PnP ACPI: found 3 devices
|
||||
[ 0.377986] clocksource: acpi_pm: mask: 0xffffff max_cycles: 0xffffff, max_idle_ns: 2085701024 ns
|
||||
[ 0.384610] NET: Registered protocol family 2
|
||||
[ 0.391662] TCP established hash table entries: 8192 (order: 4, 65536 bytes)
|
||||
[ 0.396743] TCP bind hash table entries: 8192 (order: 5, 131072 bytes)
|
||||
[ 0.401916] TCP: Hash tables configured (established 8192 bind 8192)
|
||||
[ 0.406238] UDP hash table entries: 512 (order: 2, 16384 bytes)
|
||||
[ 0.409854] UDP-Lite hash table entries: 512 (order: 2, 16384 bytes)
|
||||
[ 0.414792] NET: Registered protocol family 1
|
||||
[ 0.418002] pci 0000:00:00.0: Limiting direct PCI/PCI transfers
|
||||
[ 0.423100] pci 0000:00:01.0: Activating ISA DMA hang workarounds
|
||||
[ 0.427601] pci 0000:00:02.0: Video device with shadowed ROM at [mem 0x000c0000-0x000dffff]
|
||||
[ 0.434649] Unpacking initramfs...
|
||||
[ 0.787407] Freeing initrd memory: 19144K
|
||||
[ 0.789209] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x19f228ab7a2, max_idle_ns: 440795289252 ns
|
||||
[ 0.793332] platform rtc_cmos: registered platform RTC device (no PNP device found)
|
||||
[ 0.796800] Scanning for low memory corruption every 60 seconds
|
||||
[ 0.799238] Initialise system trusted keyrings
|
||||
[ 0.801081] Key type blacklist registered
|
||||
[ 0.802821] workingset: timestamp_bits=36 max_order=18 bucket_order=0
|
||||
[ 0.805819] zbud: loaded
|
||||
[ 0.807186] squashfs: version 4.0 (2009/01/31) Phillip Lougher
|
||||
[ 0.810037] fuse init (API version 7.26)
|
||||
[ 0.815469] Key type asymmetric registered
|
||||
[ 0.816858] Asymmetric key parser 'x509' registered
|
||||
[ 0.818479] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 246)
|
||||
[ 0.821254] io scheduler noop registered
|
||||
[ 0.822470] io scheduler deadline registered
|
||||
[ 0.823827] io scheduler cfq registered (default)
|
||||
[ 0.826132] ACPI: AC Adapter [AC] (on-line)
|
||||
[ 0.827462] input: Power Button as /devices/LNXSYSTM:00/LNXPWRBN:00/input/input0
|
||||
[ 0.830032] ACPI: Power Button [PWRF]
|
||||
[ 0.831785] input: Sleep Button as /devices/LNXSYSTM:00/LNXSLPBN:00/input/input1
|
||||
[ 0.834809] ACPI: Sleep Button [SLPF]
|
||||
[ 0.838210] ACPI: Battery Slot [BAT0] (battery present)
|
||||
[ 0.840233] Serial: 8250/16550 driver, 32 ports, IRQ sharing enabled
|
||||
|