X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/c1d3e52e58e86c49f9d04e06ae8e0ece4b98250c..8b898c07529e9b3338430715caf64c915a03a550:/Handler.cpp diff --git a/Handler.cpp b/Handler.cpp index 4f11b7b..da458d6 100644 --- a/Handler.cpp +++ b/Handler.cpp @@ -1,5 +1,5 @@ -/* Cycript - Optimizing JavaScript Compiler/Runtime - * Copyright (C) 2009-2015 Jay Freeman (saurik) +/* Cycript - The Truly Universal Scripting Language + * Copyright (C) 2009-2016 Jay Freeman (saurik) */ /* GNU Affero General Public License, Version 3 {{{ */ @@ -19,6 +19,8 @@ **/ /* }}} */ +#include "cycript.hpp" + #include #include #include @@ -34,15 +36,11 @@ #include #endif -#include "cycript.hpp" - +#include "Driver.hpp" #include "JavaScript.hpp" -#include "Parser.hpp" +#include "Syntax.hpp" #include "Pooling.hpp" -#include "Cycript.tab.hh" -#include "Driver.hpp" - struct CYExecute_ { CYPool &pool_; const char * volatile data_; @@ -153,7 +151,7 @@ static void *OnClient(void *data) { return NULL; } -extern "C" void CYHandleClient(int socket) { +void CYHandleClient(int socket) { // XXX: this leaks memory... really? CYPool *pool(new CYPool()); CYClient *client(new(*pool) CYClient(socket)); @@ -168,13 +166,13 @@ static void CYHandleSocket(const char *path) { address.sun_family = AF_UNIX; strcpy(address.sun_path, path); - _syscall(connect(socket, reinterpret_cast(&address), SUN_LEN(&address))); + _syscall(connect(socket, reinterpret_cast(&address), sizeof(address))); CYInitializeDynamic(); CYHandleClient(socket); } -extern "C" void CYHandleServer(pid_t pid) { try { +_extern void CYHandleServer(pid_t pid) { try { char path[1024]; sprintf(path, "/tmp/.s.cy.%u", pid); CYHandleSocket(path); @@ -183,7 +181,7 @@ extern "C" void CYHandleServer(pid_t pid) { try { fprintf(stderr, "%s\n", error.PoolCString(pool)); } } -extern "C" char *MSmain0(int argc, char *argv[]) { try { +_extern char *MSmain0(int argc, char *argv[]) { try { _assert(argc == 2); CYHandleSocket(argv[1]); @@ -191,7 +189,11 @@ extern "C" char *MSmain0(int argc, char *argv[]) { try { if (handle == NULL) { Dl_info info; _assert(dladdr(reinterpret_cast(&MSmain0), &info) != 0); +#ifdef __ANDROID__ + handle = dlopen(info.dli_fname, 0); +#else handle = dlopen(info.dli_fname, RTLD_NOLOAD); +#endif } return NULL; @@ -218,6 +220,9 @@ struct CYServer { void Listen() { socket_ = _syscall(::socket(PF_INET, SOCK_STREAM, 0)); try { + int value; + _syscall(::setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, &(value = 1), sizeof(value))); + sockaddr_in address; address.sin_family = AF_INET; address.sin_addr.s_addr = INADDR_ANY; @@ -245,7 +250,7 @@ static void *OnServer(void *data) { return NULL; } -extern "C" void CYListenServer(short port) { +_extern void CYListenServer(short port) { CYInitializeDynamic(); CYServer *server(new CYServer(port));