This commit is contained in:
Ryan 2009-02-20 17:06:07 +01:00
Родитель 4a5bab8ef6
Коммит 7b7ceea4ec
3 изменённых файлов: 51 добавлений и 113 удалений

Просмотреть файл

@ -3,18 +3,21 @@ V8INC = $(HOME)/src/v8/include
V8LIB = $(HOME)/src/v8/libv8.a
CFLAGS = -g -I$(V8INC) -Ideps/oi -DHAVE_GNUTLS=0 -Ideps/ebb
LDFLAGS = -lev #-lefence
LDFLAGS = -lev -pthread #-lefence
ifdef EVDIR
CFLAGS += -I$(EVDIR)/include
LDFLAGS += -L$(EVDIR)/lib
endif
server: server.o oi_socket.o ebb_request_parser.o
g++ $(LDFLAGS) $(V8LIB) $^ -o server
server: js_http_request_processor.o server.o oi_socket.o ebb_request_parser.o
g++ -o server $^ $(LDFLAGS) $(V8LIB)
server.o: server.cc
g++ $(CFLAGS) -c $<
js_http_request_processor.o: js_http_request_processor.cc
g++ $(CFLAGS) -c $<
ebb_request_parser.o: ebb_request_parser.c deps/ebb/ebb_request_parser.h
gcc $(CFLAGS) -c $<

44
count-hosts.js Normal file
Просмотреть файл

@ -0,0 +1,44 @@
// Copyright 2008 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
function Initialize() { }
function Process(request) {
print("hello ");
if (options.verbose) {
log("Processing " + request.host + request.path +
" from " + request.referrer + "@" + request.userAgent);
}
if (!output[request.host]) {
output[request.host] = 1;
} else {
output[request.host]++
}
}
Initialize();

Просмотреть файл

@ -32,7 +32,7 @@
#include <string>
#include <map>
#include <js_http_request_processor.h>
#include "js_http_request_processor.h"
using namespace std;
using namespace v8;
@ -459,115 +459,6 @@ void HttpRequestProcessor::Log
printf("Logged: %s\n", event);
}
/**
* A simplified http request.
*/
class StringHttpRequest : public HttpRequest
{
public:
StringHttpRequest
( const string& path
, const string& referrer
, const string& host
, const string& user_agent
);
virtual const string& Path () { return path_; }
virtual const string& Referrer () { return referrer_; }
virtual const string& Host () { return host_; }
virtual const string& UserAgent () { return user_agent_; }
private:
string path_;
string referrer_;
string host_;
string user_agent_;
};
StringHttpRequest::StringHttpRequest
( const string& path
, const string& referrer
, const string& host
, const string& user_agent
)
: path_ (path)
, referrer_ (referrer)
, host_ (host)
, user_agent_ (user_agent)
{
}
void ParseOptions
( int argc
, char* argv[]
, map<string, string>& options
, string* file
)
{
for (int i = 1; i < argc; i++) {
string arg = argv[i];
int index = arg.find('=', 0);
if (index == string::npos) {
*file = arg;
} else {
string key = arg.substr(0, index);
string value = arg.substr(index+1);
options[key] = value;
}
}
}
// Reads a file into a v8 string.
Handle<String> ReadFile
( const string& name
)
{
FILE* file = fopen(name.c_str(), "rb");
if (file == NULL) return Handle<String>();
fseek(file, 0, SEEK_END);
int size = ftell(file);
rewind(file);
char* chars = new char[size + 1];
chars[size] = '\0';
for (int i = 0; i < size;) {
int read = fread(&chars[i], 1, size - i, file);
i += read;
}
fclose(file);
Handle<String> result = String::New(chars, size);
delete[] chars;
return result;
}
const int kSampleSize = 6;
StringHttpRequest kSampleRequests[kSampleSize] =
{ StringHttpRequest("/process.cc", "localhost", "google.com", "firefox")
, StringHttpRequest("/", "localhost", "google.net", "firefox")
, StringHttpRequest("/", "localhost", "google.org", "safari")
, StringHttpRequest("/", "localhost", "yahoo.com", "ie")
, StringHttpRequest("/", "localhost", "yahoo.com", "safari")
, StringHttpRequest("/", "localhost", "yahoo.com", "firefox")
};
bool ProcessEntries
( HttpRequestProcessor* processor
, int count
, StringHttpRequest* reqs
)
{
for (int i = 0; i < count; i++) {
if (!processor->Process(&reqs[i]))
return false;
}
return true;
}
void PrintMap
( map<string, string>* m
)