mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-21 06:23:52 +00:00
Library interface to start ss local with a callback
This commit is contained in:
+17
-1
@@ -1722,7 +1722,7 @@ main(int argc, char **argv)
|
||||
#else
|
||||
|
||||
int
|
||||
start_ss_local_server(profile_t profile)
|
||||
_start_ss_local_server(profile_t profile, ss_local_callback callback, void *udata)
|
||||
{
|
||||
srand(time(NULL));
|
||||
|
||||
@@ -1831,6 +1831,10 @@ start_ss_local_server(profile_t profile)
|
||||
// Init connections
|
||||
cork_dllist_init(&connections);
|
||||
|
||||
if (callback) {
|
||||
callback(listen_ctx.fd, udp_fd, udata);
|
||||
}
|
||||
|
||||
// Enter the loop
|
||||
ev_run(loop, 0);
|
||||
|
||||
@@ -1852,4 +1856,16 @@ start_ss_local_server(profile_t profile)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
start_ss_local_server(profile_t profile)
|
||||
{
|
||||
return _start_ss_local_server(profile, NULL, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
start_ss_local_server_with_callback(profile_t profile, ss_local_callback callback, void *udata)
|
||||
{
|
||||
return _start_ss_local_server(profile, callback, udata);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -64,6 +64,8 @@ typedef struct {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*ss_local_callback) (int socks_fd, int udp_fd, void *data);
|
||||
|
||||
/*
|
||||
* Create and start a shadowsocks local server.
|
||||
*
|
||||
@@ -77,6 +79,16 @@ extern "C" {
|
||||
*/
|
||||
int start_ss_local_server(profile_t profile);
|
||||
|
||||
/*
|
||||
* Create and start a shadowsocks local server, specifying a callback.
|
||||
*
|
||||
* The callback is invoked when the local server has started successfully. It passes the SOCKS
|
||||
* server and UDP relay file descriptors, along with any supplied user data.
|
||||
*
|
||||
* Returns -1 on failure.
|
||||
*/
|
||||
int start_ss_local_server_with_callback(profile_t profile, ss_local_callback callback, void *udata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user