-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinit.cc
More file actions
executable file
·84 lines (72 loc) · 1.76 KB
/
Copy pathinit.cc
File metadata and controls
executable file
·84 lines (72 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* @package node-ssh
* @copyright Copyright(c) 2011 Ajax.org B.V. <info AT ajax.org>
* @author Gabor Krizsanits <gabor AT ajax DOT org>
* @license http://github.com/ajaxorg/node-ssh/blob/master/LICENSE MIT License
*/
#include "sftp.h"
#include "tunnel.h"
#include <libssh/callbacks.h>
#include <errno.h>
#include <stdlib.h>
#include <pthread.h>
// Thread callbacks are based on the libssh pthreads.c file
extern "C" {
static int ssh_pthread_mutex_init (void **priv)
{
int err = 0;
*priv = malloc (sizeof (pthread_mutex_t));
if (*priv==NULL)
return ENOMEM;
err = pthread_mutex_init ((pthread_mutex_t*)*priv, NULL);
if (err != 0){
free (*priv);
*priv=NULL;
}
return err;
}
static int ssh_pthread_mutex_destroy (void **lock)
{
int err = pthread_mutex_destroy ((pthread_mutex_t*)*lock);
free (*lock);
*lock=NULL;
return err;
}
static int ssh_pthread_mutex_lock (void **lock)
{
return pthread_mutex_lock ((pthread_mutex_t*)*lock);
}
static int ssh_pthread_mutex_unlock (void **lock)
{
return pthread_mutex_unlock ((pthread_mutex_t*)*lock);
}
static unsigned long ssh_pthread_thread_id (void)
{
#if _WIN32
return (unsigned long) pthread_self().p;
#else
return (unsigned long) pthread_self();
#endif
}
static struct ssh_threads_callbacks_struct ssh_threads_pthread =
{
"threads_pthread",
ssh_pthread_mutex_init,
ssh_pthread_mutex_destroy,
ssh_pthread_mutex_lock,
ssh_pthread_mutex_unlock,
ssh_pthread_thread_id
};
struct ssh_threads_callbacks_struct *ssh_threads_get_pthread()
{
return &ssh_threads_pthread;
}
void init(Handle<Object> target)
{
ssh_threads_set_callbacks(&ssh_threads_pthread);
ssh_init();
HandleScope scope;
SFTP::Initialize(target);
Tunnel::Initialize(target);
}
} //extern "C"