Revision 822d7fa2
deps/libeio/xthread.h | ||
---|---|---|
127 | 127 |
|
128 | 128 |
pthread_attr_init (&attr); |
129 | 129 |
pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); |
130 |
/* |
|
131 |
pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN < sizeof (long) * 4096 |
|
132 |
? sizeof (long) * 4096 : PTHREAD_STACK_MIN); |
|
133 |
*/ |
|
130 |
pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN < sizeof (long) * 4096 * 4 |
|
131 |
? sizeof (long) * 4096 * 4 : PTHREAD_STACK_MIN); |
|
134 | 132 |
#ifdef PTHREAD_SCOPE_PROCESS |
135 | 133 |
pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); |
136 | 134 |
#endif |
src/http.cc | ||
---|---|---|
44 | 44 |
|
45 | 45 |
#define INVALID_STATE_ERR 1 |
46 | 46 |
|
47 |
class Server { |
|
47 |
class HttpServer {
|
|
48 | 48 |
public: |
49 |
Server (Handle<Object> _js_server); |
|
50 |
~Server (); |
|
49 |
HttpServer (Handle<Object> _js_server);
|
|
50 |
~HttpServer ();
|
|
51 | 51 |
|
52 | 52 |
int Start(struct addrinfo *servinfo); |
53 | 53 |
void Stop(); |
... | ... | |
83 | 83 |
ebb_request_parser parser; |
84 | 84 |
list<HttpRequest*> requests; |
85 | 85 |
list<HttpRequest*> finished_requests; |
86 |
friend class Server; |
|
86 |
friend class HttpServer;
|
|
87 | 87 |
}; |
88 | 88 |
|
89 | 89 |
class HttpRequest { |
... | ... | |
461 | 461 |
{ |
462 | 462 |
HandleScope scope; |
463 | 463 |
|
464 |
Server *server = static_cast<Server*> (_server->data);
|
|
464 |
HttpServer *server = static_cast<HttpServer*> (_server->data);
|
|
465 | 465 |
|
466 | 466 |
Handle<Value> callback_v = server->Callback(); |
467 | 467 |
|
... | ... | |
560 | 560 |
static void |
561 | 561 |
server_destroy (Persistent<Value> _, void *data) |
562 | 562 |
{ |
563 |
Server *server = static_cast<Server *> (data);
|
|
563 |
HttpServer *server = static_cast<HttpServer *> (data);
|
|
564 | 564 |
delete server; |
565 | 565 |
} |
566 | 566 |
|
567 |
Server::Server (Handle<Object> _js_server)
|
|
567 |
HttpServer::HttpServer (Handle<Object> _js_server)
|
|
568 | 568 |
{ |
569 | 569 |
oi_server_init(&server, 1024); |
570 | 570 |
server.on_connection = on_connection; |
... | ... | |
576 | 576 |
js_server.MakeWeak (this, server_destroy); |
577 | 577 |
} |
578 | 578 |
|
579 |
Server::~Server ()
|
|
579 |
HttpServer::~HttpServer ()
|
|
580 | 580 |
{ |
581 | 581 |
Stop(); |
582 | 582 |
js_server.Dispose(); |
... | ... | |
584 | 584 |
} |
585 | 585 |
|
586 | 586 |
int |
587 |
Server::Start(struct addrinfo *servinfo) |
|
587 |
HttpServer::Start(struct addrinfo *servinfo)
|
|
588 | 588 |
{ |
589 | 589 |
int r = oi_server_listen(&server, servinfo); |
590 | 590 |
if(r == 0) |
... | ... | |
593 | 593 |
} |
594 | 594 |
|
595 | 595 |
void |
596 |
Server::Stop() |
|
596 |
HttpServer::Stop()
|
|
597 | 597 |
{ |
598 | 598 |
oi_server_close (&server); |
599 | 599 |
oi_server_detach (&server); |
... | ... | |
601 | 601 |
|
602 | 602 |
/* This constructor takes 2 arguments: host, port. */ |
603 | 603 |
static Handle<Value> |
604 |
newHTTPServer (const Arguments& args) |
|
604 |
newHTTPHttpServer (const Arguments& args)
|
|
605 | 605 |
{ |
606 | 606 |
if (args.Length() < 3) |
607 | 607 |
return Undefined(); |
... | ... | |
639 | 639 |
// |
640 | 640 |
// |
641 | 641 |
|
642 |
Server *server = new Server(args.This());
|
|
642 |
HttpServer *server = new HttpServer(args.This());
|
|
643 | 643 |
if(server == NULL) |
644 | 644 |
return Undefined(); // XXX raise error? |
645 | 645 |
|
... | ... | |
655 | 655 |
{ |
656 | 656 |
HandleScope scope; |
657 | 657 |
|
658 |
Local<FunctionTemplate> server_t = FunctionTemplate::New(newHTTPServer); |
|
658 |
Local<FunctionTemplate> server_t = FunctionTemplate::New(newHTTPHttpServer);
|
|
659 | 659 |
server_t->InstanceTemplate()->SetInternalFieldCount(1); |
660 | 660 |
|
661 | 661 |
server_t->Set("INVALID_STATE_ERR", Integer::New(INVALID_STATE_ERR)); |
src/net.cc | ||
---|---|---|
29 | 29 |
/* ai_next */ , NULL |
30 | 30 |
}; |
31 | 31 |
|
32 |
class Server { |
|
33 |
public: |
|
34 |
Server (Handle<Object> handle, int backlog); |
|
35 |
~Server (); |
|
36 |
|
|
37 |
static Handle<Value> New (const Arguments& args); |
|
38 |
static Handle<Value> ListenTCP (const Arguments& args); |
|
39 |
static Handle<Value> Close (const Arguments& args); |
|
40 |
|
|
41 |
private: |
|
42 |
static oi_socket* OnConnection (oi_server *, struct sockaddr *, socklen_t); |
|
43 |
static Server* Unwrap (Handle<Object> handle); |
|
44 |
static void MakeWeak (Persistent<Value> _, void *data); |
|
45 |
oi_server server_; |
|
46 |
Persistent<Object> handle_; |
|
47 |
}; |
|
32 | 48 |
|
33 | 49 |
class Socket { |
34 | 50 |
public: |
35 |
Socket (Handle<Object> obj, double timeout);
|
|
51 |
Socket (Handle<Object> handle, double timeout);
|
|
36 | 52 |
~Socket (); |
37 | 53 |
|
38 |
void SetEncoding (enum encoding);
|
|
54 |
void SetEncoding (Handle<Value>);
|
|
39 | 55 |
void SetTimeout (double); |
40 | 56 |
|
41 | 57 |
static Handle<Value> New (const Arguments& args); |
42 | 58 |
static Handle<Value> Write (const Arguments& args); |
43 | 59 |
static Handle<Value> Close (const Arguments& args); |
44 | 60 |
static Handle<Value> ConnectTCP (const Arguments& args); |
61 |
static Handle<Value> SetEncoding (const Arguments& args); |
|
45 | 62 |
|
63 |
private: |
|
46 | 64 |
static void OnConnect (oi_socket *socket); |
47 | 65 |
static void OnRead (oi_socket *s, const void *buf, size_t count); |
48 | 66 |
static void OnDrain (oi_socket *s); |
... | ... | |
50 | 68 |
static void OnClose (oi_socket *s); |
51 | 69 |
static void OnTimeout (oi_socket *s); |
52 | 70 |
|
53 |
char *host_; |
|
54 |
char *port_; |
|
55 |
|
|
56 |
private: |
|
57 | 71 |
static int Resolve (eio_req *req); |
58 | 72 |
static int AfterResolve (eio_req *req); |
59 | 73 |
|
... | ... | |
63 | 77 |
enum {UTF8, RAW} encoding_; |
64 | 78 |
oi_socket socket_; |
65 | 79 |
Persistent<Object> handle_; |
80 |
|
|
81 |
char *host_; |
|
82 |
char *port_; |
|
66 | 83 |
}; |
67 | 84 |
|
85 |
Server::Server (Handle<Object> handle, int backlog) |
|
86 |
{ |
|
87 |
oi_server_init(&server_, backlog); |
|
88 |
server_.on_connection = Server::OnConnection; |
|
89 |
// server_.on_error = Server::OnError; |
|
90 |
server_.data = this; |
|
91 |
|
|
92 |
HandleScope scope; |
|
93 |
handle_ = Persistent<Object>::New(handle); |
|
94 |
handle_->SetInternalField(0, External::New(this)); |
|
95 |
handle_.MakeWeak(this, Server::MakeWeak); |
|
96 |
} |
|
97 |
|
|
98 |
Server::~Server () |
|
99 |
{ |
|
100 |
oi_server_close(&server_); |
|
101 |
oi_server_detach(&server_); |
|
102 |
handle_.Dispose(); |
|
103 |
handle_.Clear(); // necessary? |
|
104 |
} |
|
105 |
|
|
106 |
Handle<Value> |
|
107 |
Server::New (const Arguments& args) |
|
108 |
{ |
|
109 |
; |
|
110 |
} |
|
111 |
|
|
112 |
Handle<Value> |
|
113 |
Server::ListenTCP (const Arguments& args) |
|
114 |
{ |
|
115 |
; |
|
116 |
} |
|
117 |
|
|
118 |
Handle<Value> |
|
119 |
Server::Close (const Arguments& args) |
|
120 |
{ |
|
121 |
; |
|
122 |
} |
|
123 |
|
|
124 |
oi_socket* |
|
125 |
Server::OnConnection (oi_server *, struct sockaddr *remote_addr, socklen_t remote_addr_len) |
|
126 |
{ |
|
127 |
; |
|
128 |
} |
|
129 |
|
|
130 |
Server* |
|
131 |
Server::Unwrap (Handle<Object> handle) |
|
132 |
{ |
|
133 |
HandleScope scope; |
|
134 |
Handle<External> field = Handle<External>::Cast(handle->GetInternalField(0)); |
|
135 |
Server* server = static_cast<Server*>(field->Value()); |
|
136 |
return server; |
|
137 |
} |
|
138 |
|
|
139 |
void |
|
140 |
Server::MakeWeak (Persistent<Value> _, void *data) |
|
141 |
{ |
|
142 |
Server *s = static_cast<Server*> (data); |
|
143 |
delete s; |
|
144 |
} |
|
145 |
|
|
68 | 146 |
Handle<Value> |
69 | 147 |
Socket::New(const Arguments& args) |
70 | 148 |
{ |
... | ... | |
105 | 183 |
return args.This(); |
106 | 184 |
} |
107 | 185 |
|
186 |
void |
|
187 |
Socket::SetEncoding (Handle<Value> encoding_value) |
|
188 |
{ |
|
189 |
if (encoding_value->IsString()) { |
|
190 |
HandleScope scope; |
|
191 |
Local<String> encoding_string = encoding_value->ToString(); |
|
192 |
char buf[5]; // need enough room for "utf8" or "raw" |
|
193 |
encoding_string->WriteAscii(buf, 0, 4); |
|
194 |
buf[4] = '\0'; |
|
195 |
if(strcasecmp(buf, "utf8") == 0) |
|
196 |
encoding_ = UTF8; |
|
197 |
else |
|
198 |
encoding_ = RAW; |
|
199 |
} |
|
200 |
} |
|
201 |
|
|
108 | 202 |
Socket* |
109 | 203 |
Socket::Unwrap (Handle<Object> handle) |
110 | 204 |
{ |
... | ... | |
232 | 326 |
|
233 | 327 |
HandleScope scope; |
234 | 328 |
handle_ = Persistent<Object>::New(handle); |
235 |
handle_->SetInternalField (0, External::New(this));
|
|
236 |
handle_.MakeWeak (this, Socket::MakeWeak);
|
|
329 |
handle_->SetInternalField(0, External::New(this)); |
|
330 |
handle_.MakeWeak(this, Socket::MakeWeak); |
|
237 | 331 |
|
238 |
encoding_ = UTF8; |
|
332 |
encoding_ = UTF8; // default encoding.
|
|
239 | 333 |
host_ = NULL; |
240 | 334 |
port_ = NULL; |
241 | 335 |
} |
... | ... | |
251 | 345 |
} |
252 | 346 |
|
253 | 347 |
Handle<Value> |
348 |
Socket::SetEncoding (const Arguments& args) |
|
349 |
{ |
|
350 |
Socket *socket = Socket::Unwrap(args.Holder()); |
|
351 |
socket->SetEncoding(args[0]); |
|
352 |
return Undefined(); |
|
353 |
} |
|
354 |
|
|
355 |
Handle<Value> |
|
254 | 356 |
Socket::Write (const Arguments& args) |
255 | 357 |
{ |
256 | 358 |
HandleScope scope; |
... | ... | |
410 | 512 |
Socket *socket = static_cast<Socket*> (s->data); |
411 | 513 |
HandleScope scope; |
412 | 514 |
|
413 |
printf("timeout\n"); |
|
414 |
|
|
415 | 515 |
Handle<Value> ontimeout_value = socket->handle_->Get( String::NewSymbol("onTimeout") ); |
416 | 516 |
if (!ontimeout_value->IsFunction()) return; |
417 | 517 |
Handle<Function> ontimeout = Handle<Function>::Cast(ontimeout_value); |
... | ... | |
438 | 538 |
//NODE_SET_METHOD(socket_template->InstanceTemplate(), "connectUNIX", Socket::ConnectUNIX); |
439 | 539 |
NODE_SET_METHOD(socket_template->InstanceTemplate(), "write", Socket::Write); |
440 | 540 |
NODE_SET_METHOD(socket_template->InstanceTemplate(), "close", Socket::Close); |
541 |
NODE_SET_METHOD(socket_template->InstanceTemplate(), "setEncoding", Socket::SetEncoding); |
|
542 |
|
|
543 |
Local<FunctionTemplate> server_template = FunctionTemplate::New(Server::New); |
|
544 |
server_template->InstanceTemplate()->SetInternalFieldCount(1); |
|
545 |
target->Set(String::NewSymbol("Server"), server_template->GetFunction()); |
|
441 | 546 |
|
547 |
NODE_SET_METHOD(server_template->InstanceTemplate(), "listenTCP", Server::ListenTCP); |
|
442 | 548 |
} |
443 | 549 |
|
wscript | ||
---|---|---|
63 | 63 |
|
64 | 64 |
# Configure default variant |
65 | 65 |
conf.setenv('default') |
66 |
conf.env.append_value('CCFLAGS', ['-DNDEBUG', '-O2', '-g'])
|
|
67 |
conf.env.append_value('CXXFLAGS', ['-DNDEBUG', '-O2', '-g'])
|
|
66 |
conf.env.append_value('CCFLAGS', ['-DNDEBUG', '-O0', '-g'])
|
|
67 |
conf.env.append_value('CXXFLAGS', ['-DNDEBUG', '-O0', '-g'])
|
|
68 | 68 |
conf.write_config_header("config.h") |
69 | 69 |
|
70 | 70 |
def build(bld): |
Also available in: Unified diff