Browse files

no more need for messy clientObj, just use client->handle_

  • Loading branch information...
1 parent 91f9039 commit 075cc8915709849bee1293d2caad1bea4afc9157 @substack committed Mar 24, 2011
Showing with 25 additions and 18 deletions.
  1. +1 −0 index.js
  2. +6 −4 src/client.cc
  3. +18 −14 src/sshd.cc
View
1 index.js
@@ -24,6 +24,7 @@ var exports = module.exports = function (keys) {
createServer : function (cb) {
var server = new sshd.Server(keys);
server.on('session', function (s) {
+console.log('got session!!!!');
cb(wrapSession(s));
});
return server;
View
10 src/client.cc
@@ -16,21 +16,23 @@ void Client::Initialize() {
Handle<Value> Client::New(const Arguments &args) {
HandleScope scope;
-
- Client *client = new Client();
- client->Wrap(args.This());
-
return args.This();
}
Client::Client() {
session = ssh_new();
+ Wrap(Persistent<Object>::New(
+ constructor_template->GetFunction()->NewInstance()
+ ));
+ Ref();
}
int Client::GetMessage(eio_req *req) {
Client *client = (Client *) req->data;
+printf("get message\n"); fflush(stdout);
ssh_message msg = ssh_message_get(client->session);
+printf("got message\n"); fflush(stdout);
client->messageQueue.push_back(msg);
return 0;
View
32 src/sshd.cc
@@ -8,7 +8,6 @@ Persistent<String> SSHD::sessionSymbol;
struct ClientServerPair {
SSHD *server;
Client *client;
- Persistent<Object> clientObj;
};
void SSHD::setPort(Local<Value> port) {
@@ -148,12 +147,7 @@ Handle<Value> SSHD::Listen(const Arguments &args) {
ClientServerPair *pair = new ClientServerPair;
pair->server = sshd;
-
- pair->clientObj = Persistent<Object>::New(
- Client::constructor_template->GetFunction()->NewInstance()
- );
- pair->client = ObjectWrap::Unwrap<Client>(pair->clientObj);
- pair->client->Ref();
+ pair->client = new Client;
eio_custom(Accept, EIO_PRI_DEFAULT, AcceptAfter, pair);
ev_ref(EV_DEFAULT_UC);
@@ -166,6 +160,7 @@ int SSHD::Accept (eio_req *req) {
SSHD *server = pair->server;
Client *client = pair->client;
+printf("0\n"); fflush(stdout);
int r = ssh_bind_accept(server->sshbind, client->session);
if (r == SSH_ERROR) {
fprintf(stderr,
@@ -174,6 +169,7 @@ int SSHD::Accept (eio_req *req) {
);
return 1;
}
+printf("1\n"); fflush(stdout);
if (ssh_handle_key_exchange(client->session)) {
fprintf(stderr,
"Error handling key exchange: %s\n",
@@ -182,36 +178,44 @@ int SSHD::Accept (eio_req *req) {
return 1;
}
+printf("2\n"); fflush(stdout);
return 0;
}
int SSHD::AcceptAfter (eio_req *req) {
+printf("3\n"); fflush(stdout);
ClientServerPair *pair = (ClientServerPair *) req->data;
SSHD *server = pair->server;
Client *client = pair->client;
+printf("4\n"); fflush(stdout);
Handle<Value> argv[1];
- argv[0] = pair->clientObj;
- server->Emit(sessionSymbol, 1, argv);
+ argv[0] = client->handle_;
+printf("5\n"); fflush(stdout);
+printf("6\n"); fflush(stdout);
+ server->Emit(String::NewSymbol("session"), 1, argv);
+printf("7\n"); fflush(stdout);
eio_custom(
Client::GetMessage,
EIO_PRI_DEFAULT,
Client::GetMessageAfter,
client
);
+printf("8\n"); fflush(stdout);
ev_ref(EV_DEFAULT_UC);
if (!server->closed) {
- pair->clientObj = Persistent<Object>::New(
- Client::constructor_template->GetFunction()->NewInstance()
- );
- pair->client = ObjectWrap::Unwrap<Client>(pair->clientObj);
- pair->client->Ref();
+printf("9\n"); fflush(stdout);
+ pair->client = new Client;
+printf("10\n"); fflush(stdout);
eio_custom(Accept, EIO_PRI_DEFAULT, AcceptAfter, pair);
ev_ref(EV_DEFAULT_UC);
+printf("11\n"); fflush(stdout);
}
+
+ return 0;
}
Handle<Value> SSHD::Close(const Arguments &args) {

0 comments on commit 075cc89

Please sign in to comment.